projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Convert “Sone marked as known” into EventBus-based event.
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
web
/
WebInterface.java
diff --git
a/src/main/java/net/pterodactylus/sone/web/WebInterface.java
b/src/main/java/net/pterodactylus/sone/web/WebInterface.java
index
20b1f82
..
224dc69
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/WebInterface.java
+++ b/
src/main/java/net/pterodactylus/sone/web/WebInterface.java
@@
-37,6
+37,10
@@
import java.util.logging.Logger;
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.core.CoreListener;
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.core.CoreListener;
+import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
+import net.pterodactylus.sone.core.event.NewPostFoundEvent;
+import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
+import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Post;
@@
-103,8
+107,6
@@
import net.pterodactylus.sone.web.ajax.UntrustAjaxPage;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.sone.web.page.PageToadlet;
import net.pterodactylus.sone.web.page.PageToadletFactory;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.sone.web.page.PageToadlet;
import net.pterodactylus.sone.web.page.PageToadletFactory;
-import net.pterodactylus.util.collection.SetBuilder;
-import net.pterodactylus.util.collection.filter.Filters;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.notify.Notification;
import net.pterodactylus.util.notify.NotificationManager;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.notify.Notification;
import net.pterodactylus.util.notify.NotificationManager;
@@
-132,6
+134,9
@@
import net.pterodactylus.util.web.RedirectPage;
import net.pterodactylus.util.web.StaticPage;
import net.pterodactylus.util.web.TemplatePage;
import net.pterodactylus.util.web.StaticPage;
import net.pterodactylus.util.web.TemplatePage;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
import freenet.clients.http.SessionManager;
import com.google.inject.Inject;
import freenet.clients.http.SessionManager;
@@
-462,7
+467,7
@@
public class WebInterface implements CoreListener {
* @return The new posts
*/
public Set<Post> getNewPosts() {
* @return The new posts
*/
public Set<Post> getNewPosts() {
- return
new SetBuilder<Post>().addAll(newPostNotification.getElements()).addAll(localPostNotification.getElements()).get
();
+ return
ImmutableSet.<Post> builder().addAll(newPostNotification.getElements()).addAll(localPostNotification.getElements()).build
();
}
/**
}
/**
@@
-472,7
+477,7
@@
public class WebInterface implements CoreListener {
* @return The new replies
*/
public Set<PostReply> getNewReplies() {
* @return The new replies
*/
public Set<PostReply> getNewReplies() {
- return
new SetBuilder<PostReply>().addAll(newReplyNotification.getElements()).addAll(localReplyNotification.getElements()).get
();
+ return
ImmutableSet.<PostReply> builder().addAll(newReplyNotification.getElements()).addAll(localReplyNotification.getElements()).build
();
}
/**
}
/**
@@
-737,7
+742,7
@@
public class WebInterface implements CoreListener {
* The text to parse
* @return All mentioned local Sones
*/
* The text to parse
* @return All mentioned local Sones
*/
- private
Set
<Sone> getMentionedSones(String text) {
+ private
Collection
<Sone> getMentionedSones(String text) {
/* we need no context to find mentioned Sones. */
Set<Sone> mentionedSones = new HashSet<Sone>();
try {
/* we need no context to find mentioned Sones. */
Set<Sone> mentionedSones = new HashSet<Sone>();
try {
@@
-749,7
+754,7
@@
public class WebInterface implements CoreListener {
} catch (IOException ioe1) {
logger.log(Level.WARNING, String.format("Could not parse post text: %s", text), ioe1);
}
} catch (IOException ioe1) {
logger.log(Level.WARNING, String.format("Could not parse post text: %s", text), ioe1);
}
- return
Filters.filteredSet
(mentionedSones, Sone.LOCAL_SONE_FILTER);
+ return
Collections2.filter
(mentionedSones, Sone.LOCAL_SONE_FILTER);
}
/**
}
/**
@@
-774,15
+779,15
@@
public class WebInterface implements CoreListener {
}
//
}
//
- //
CORELISTENER METHOD
S
+ //
EVENT HANDLER
S
//
/**
* {@inheritDoc}
*/
//
/**
* {@inheritDoc}
*/
- @
Overrid
e
- public void newSoneFound(
Sone sone
) {
- newSoneNotification.add(
sone
);
+ @
Subscrib
e
+ public void newSoneFound(
NewSoneFoundEvent newSoneFoundEvent
) {
+ newSoneNotification.add(
newSoneFoundEvent.sone()
);
if (!hasFirstStartNotification()) {
notificationManager.addNotification(newSoneNotification);
}
if (!hasFirstStartNotification()) {
notificationManager.addNotification(newSoneNotification);
}
@@
-791,8
+796,9
@@
public class WebInterface implements CoreListener {
/**
* {@inheritDoc}
*/
/**
* {@inheritDoc}
*/
- @Override
- public void newPostFound(Post post) {
+ @Subscribe
+ public void newPostFound(NewPostFoundEvent newPostFoundEvent) {
+ Post post = newPostFoundEvent.post();
boolean isLocal = post.getSone().isLocal();
if (isLocal) {
localPostNotification.add(post);
boolean isLocal = post.getSone().isLocal();
if (isLocal) {
localPostNotification.add(post);
@@
-813,8
+819,9
@@
public class WebInterface implements CoreListener {
/**
* {@inheritDoc}
*/
/**
* {@inheritDoc}
*/
- @Override
- public void newReplyFound(PostReply reply) {
+ @Subscribe
+ public void newReplyFound(NewPostReplyFoundEvent newPostReplyFoundEvent) {
+ PostReply reply = newPostReplyFoundEvent.postReply();
boolean isLocal = reply.getSone().isLocal();
if (isLocal) {
localReplyNotification.add(reply);
boolean isLocal = reply.getSone().isLocal();
if (isLocal) {
localReplyNotification.add(reply);
@@
-835,11
+842,15
@@
public class WebInterface implements CoreListener {
/**
* {@inheritDoc}
*/
/**
* {@inheritDoc}
*/
- @
Overrid
e
- public void markSoneKnown(
Sone sone
) {
- newSoneNotification.remove(
sone
);
+ @
Subscrib
e
+ public void markSoneKnown(
MarkSoneKnownEvent markSoneKnownEvent
) {
+ newSoneNotification.remove(
markSoneKnownEvent.sone()
);
}
}
+ //
+ // CORELISTENER METHODS
+ //
+
/**
* {@inheritDoc}
*/
/**
* {@inheritDoc}
*/