import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import net.pterodactylus.util.template.TemplateProvider;
import net.pterodactylus.util.template.XmlFilter;
import net.pterodactylus.util.thread.Ticker;
+import net.pterodactylus.util.version.Version;
import freenet.clients.http.SessionManager;
import freenet.clients.http.SessionManager.Session;
import freenet.clients.http.ToadletContainer;
/** The “Sone rescued” notification. */
private final ListNotification<Sone> sonesRescuedNotification;
+ /** Sone locked notification ticker objects. */
+ private final Map<Sone, Object> lockedSonesTickerObjects = Collections.synchronizedMap(new HashMap<Sone, Object>());
+
+ /** The “Sone locked” notification. */
+ private final ListNotification<Sone> lockedSonesNotification;
+
+ /** The “new version” notification. */
+ private final TemplateNotification newVersionNotification;
+
/**
* Creates a new web interface.
*
Template sonesRescuedTemplate = templateFactory.createTemplate(createReader("/templates/notify/sonesRescuedNotification.html"));
sonesRescuedNotification = new ListNotification<Sone>("sones-rescued-notification", "sones", sonesRescuedTemplate);
+
+ Template lockedSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/lockedSonesNotification.html"));
+ lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
+
+ Template newVersionTemplate = templateFactory.createTemplate(createReader("/templates/notify/newVersionNotification.html"));
+ newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate);
}
//
* currently logged in
*/
public Sone getCurrentSone(ToadletContext toadletContext) {
- return getCurrentSone(getCurrentSession(toadletContext));
+ return getCurrentSone(toadletContext, true);
+ }
+
+ /**
+ * Returns the currently logged in Sone.
+ *
+ * @param toadletContext
+ * The toadlet context
+ * @param create
+ * {@code true} to create a new session if no session exists,
+ * {@code false} to not create a new session
+ * @return The currently logged in Sone, or {@code null} if no Sone is
+ * currently logged in
+ */
+ public Sone getCurrentSone(ToadletContext toadletContext, boolean create) {
+ return getCurrentSone(getCurrentSession(toadletContext, create));
}
/**
newPostNotification.add(post);
if (!hasFirstStartNotification()) {
notificationManager.addNotification(newPostNotification);
+ } else {
+ getCore().markPostKnown(post);
}
}
newReplyNotification.add(reply);
if (!hasFirstStartNotification()) {
notificationManager.addNotification(newReplyNotification);
+ } else {
+ getCore().markReplyKnown(reply);
}
}
*/
@Override
public void postRemoved(Post post) {
- /* TODO */
+ newPostNotification.remove(post);
}
/**
*/
@Override
public void replyRemoved(Reply reply) {
- /* TODO */
+ newReplyNotification.remove(reply);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void soneLocked(final Sone sone) {
+ Object tickerObject = Ticker.getInstance().registerEvent(System.currentTimeMillis() + (5 * 60) * 1000, new Runnable() {
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ lockedSonesNotification.add(sone);
+ lockedSonesTickerObjects.remove(sone);
+ notificationManager.addNotification(lockedSonesNotification);
+ }
+ }, "Sone Locked Notification");
+ lockedSonesTickerObjects.put(sone, tickerObject);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void soneUnlocked(Sone sone) {
+ lockedSonesNotification.remove(sone);
+ Ticker.getInstance().deregisterEvent(lockedSonesTickerObjects.remove(sone));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void updateFound(Version version, long releaseTime) {
+ newVersionNotification.set("version", version);
+ newVersionNotification.set("releaseTime", releaseTime);
+ notificationManager.addNotification(newVersionNotification);
}
/**