import net.pterodactylus.util.cache.DefaultCacheItem;
import net.pterodactylus.util.cache.MemoryCache;
import net.pterodactylus.util.cache.ValueRetriever;
+import net.pterodactylus.util.collection.SetBuilder;
import net.pterodactylus.util.filter.Filters;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.notify.Notification;
/** The “new reply” notification. */
private final ListNotification<Reply> newReplyNotification;
+ /** The invisible “local post” notification. */
+ private final ListNotification<Post> localPostNotification;
+
+ /** The invisible “local reply” notification. */
+ private final ListNotification<Reply> localReplyNotification;
+
/** The “you have been mentioned” notification. */
private final ListNotification<Post> mentionNotification;
public WebInterface(SonePlugin sonePlugin) {
this.sonePlugin = sonePlugin;
formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
- soneTextParser = new SoneTextParser(getCore());
+ soneTextParser = new SoneTextParser(getCore(), getCore());
templateContextFactory = new TemplateContextFactory();
templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
Template newPostNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newPostNotification.html"));
newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate, false);
+ Template localPostNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newPostNotification.html"));
+ localPostNotification = new ListNotification<Post>("local-post-notification", "posts", localPostNotificationTemplate, false);
+
Template newReplyNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newReplyNotification.html"));
newReplyNotification = new ListNotification<Reply>("new-reply-notification", "replies", newReplyNotificationTemplate, false);
+ Template localReplyNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newReplyNotification.html"));
+ localReplyNotification = new ListNotification<Reply>("local-reply-notification", "replies", localReplyNotificationTemplate, false);
+
Template mentionNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/mentionNotification.html"));
mentionNotification = new ListNotification<Post>("mention-notification", "posts", mentionNotificationTemplate, false);
* @return The new posts
*/
public Set<Post> getNewPosts() {
- return new HashSet<Post>(newPostNotification.getElements());
+ return new SetBuilder<Post>().addAll(newPostNotification.getElements()).addAll(localPostNotification.getElements()).get();
}
/**
* @return The new replies
*/
public Set<Reply> getNewReplies() {
- return new HashSet<Reply>(newReplyNotification.getElements());
+ return new SetBuilder<Reply>().addAll(newReplyNotification.getElements()).addAll(localReplyNotification.getElements()).get();
}
/**
}
}
+ /**
+ * 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>();
*/
@Override
public void newPostFound(Post post) {
- newPostNotification.add(post);
+ boolean isLocal = getCore().isLocalSone(post.getSone());
+ if (isLocal) {
+ localPostNotification.add(post);
+ } else {
+ newPostNotification.add(post);
+ }
if (!hasFirstStartNotification()) {
- notificationManager.addNotification(newPostNotification);
- if (!getMentionedSones(post.getText()).isEmpty()) {
+ notificationManager.addNotification(isLocal ? localPostNotification : newPostNotification);
+ if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) {
mentionNotification.add(post);
notificationManager.addNotification(mentionNotification);
}
if (reply.getPost().getSone() == null) {
return;
}
- newReplyNotification.add(reply);
+ boolean isLocal = getCore().isLocalSone(reply.getSone());
+ if (isLocal) {
+ localReplyNotification.add(reply);
+ } else {
+ newReplyNotification.add(reply);
+ }
if (!hasFirstStartNotification()) {
- notificationManager.addNotification(newReplyNotification);
- if (!getMentionedSones(reply.getText()).isEmpty()) {
+ notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification);
+ if (!getMentionedSones(reply.getText()).isEmpty() && !isLocal) {
mentionNotification.add(reply.getPost());
notificationManager.addNotification(mentionNotification);
}
@Override
public void markPostKnown(Post post) {
newPostNotification.remove(post);
+ localPostNotification.remove(post);
mentionNotification.remove(post);
}
@Override
public void markReplyKnown(Reply reply) {
newReplyNotification.remove(reply);
+ localReplyNotification.remove(reply);
mentionNotification.remove(reply.getPost());
}
@Override
public void postRemoved(Post post) {
newPostNotification.remove(post);
+ localPostNotification.remove(post);
}
/**
@Override
public void replyRemoved(Reply reply) {
newReplyNotification.remove(reply);
+ localReplyNotification.remove(reply);
}
/**