+ * Returns all {@link Core#isLocalSone(Sone) local Sone}s that are
+ * referenced by {@link SonePart}s in the given text (after parsing it using
+ * {@link SoneTextParser}).
+ *
+ * @param text
+ * The text to parse
+ * @return All mentioned local Sones
+ */
+ private Set<Sone> getMentionedSones(String text) {
+ /* we need no context to find mentioned Sones. */
+ Set<Sone> mentionedSones = new HashSet<Sone>();
+ try {
+ for (Part part : soneTextParser.parse(null, new StringReader(text))) {
+ if (part instanceof SonePart) {
+ mentionedSones.add(((SonePart) part).getSone());
+ }
+ }
+ } catch (IOException ioe1) {
+ logger.log(Level.WARNING, "Could not parse post text: " + text, ioe1);
+ }
+ return Filters.filteredSet(mentionedSones, Sone.LOCAL_SONE_FILTER);
+ }
+
+ //
+ // CORELISTENER METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void rescuingSone(Sone sone) {
+ rescuingSonesNotification.add(sone);
+ notificationManager.addNotification(rescuingSonesNotification);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void rescuedSone(Sone sone) {
+ rescuingSonesNotification.remove(sone);
+ sonesRescuedNotification.add(sone);
+ notificationManager.addNotification(sonesRescuedNotification);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void newSoneFound(Sone sone) {
+ newSoneNotification.add(sone);
+ if (!hasFirstStartNotification()) {
+ notificationManager.addNotification(newSoneNotification);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void newPostFound(Post post) {
+ boolean isLocal = getCore().isLocalSone(post.getSone());
+ if (isLocal) {
+ localPostNotification.add(post);
+ } else {
+ newPostNotification.add(post);
+ }
+ if (!hasFirstStartNotification()) {
+ notificationManager.addNotification(isLocal ? localPostNotification : newPostNotification);
+ if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) {
+ mentionNotification.add(post);
+ notificationManager.addNotification(mentionNotification);
+ }
+ } else {
+ getCore().markPostKnown(post);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void newReplyFound(Reply reply) {
+ if (reply.getPost().getSone() == null) {
+ return;
+ }
+ boolean isLocal = getCore().isLocalSone(reply.getSone());
+ if (isLocal) {
+ localReplyNotification.add(reply);
+ } else {
+ newReplyNotification.add(reply);
+ }
+ if (!hasFirstStartNotification()) {
+ notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification);
+ if (!getMentionedSones(reply.getText()).isEmpty() && !isLocal) {
+ mentionNotification.add(reply.getPost());
+ notificationManager.addNotification(mentionNotification);
+ }
+ } else {
+ getCore().markReplyKnown(reply);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void markSoneKnown(Sone sone) {
+ newSoneNotification.remove(sone);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void markPostKnown(Post post) {
+ newPostNotification.remove(post);
+ localPostNotification.remove(post);
+ mentionNotification.remove(post);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void markReplyKnown(Reply reply) {
+ newReplyNotification.remove(reply);
+ localReplyNotification.remove(reply);
+ mentionNotification.remove(reply.getPost());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void soneRemoved(Sone sone) {
+ newSoneNotification.remove(sone);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void postRemoved(Post post) {
+ newPostNotification.remove(post);
+ localPostNotification.remove(post);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void replyRemoved(Reply reply) {
+ newReplyNotification.remove(reply);
+ localReplyNotification.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, long latestEdition) {
+ newVersionNotification.getTemplateContext().set("latestVersion", version);
+ newVersionNotification.getTemplateContext().set("latestEdition", latestEdition);
+ newVersionNotification.getTemplateContext().set("releaseTime", releaseTime);
+ notificationManager.addNotification(newVersionNotification);
+ }
+
+ /**