aboutsummaryrefslogtreecommitdiff
path: root/juick-common/src/main/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-05-10 12:50:08 +0300
committerGravatar Vitaly Takmazov2018-05-10 12:50:08 +0300
commitfb540605626e1c7bb1544a518a254e6a820afcb3 (patch)
treeb370df3f031a1a72a34b64bc197cd600b6947f5d /juick-common/src/main/java/com/juick/server
parentd2a1f21717c8583c9804c69319123fb7ebaac261 (diff)
server: MessageReadEvent
Diffstat (limited to 'juick-common/src/main/java/com/juick/server')
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java9
-rw-r--r--juick-common/src/main/java/com/juick/server/component/MessageReadEvent.java28
2 files changed, 33 insertions, 4 deletions
diff --git a/juick-common/src/main/java/com/juick/server/CommandsManager.java b/juick-common/src/main/java/com/juick/server/CommandsManager.java
index ab55bba7..918e6028 100644
--- a/juick-common/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java
@@ -21,10 +21,7 @@ import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
import com.juick.formatters.PlainTextFormatter;
-import com.juick.server.component.LikeEvent;
-import com.juick.server.component.MessageEvent;
-import com.juick.server.component.PingEvent;
-import com.juick.server.component.SubscribeEvent;
+import com.juick.server.component.*;
import com.juick.server.helpers.CommandResult;
import com.juick.server.helpers.TagStats;
import com.juick.server.helpers.annotation.UserCommand;
@@ -116,6 +113,7 @@ public class CommandsManager {
imagesService.saveImageWithPreviews(attachmentFName, fname);
}
com.juick.Message msg = messagesService.getMessage(mid);
+ applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
applicationEventPublisher.publishEvent(new MessageEvent(this, msg, subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid())));
return CommandResult.build(msg, "New message posted.\n#" + msg.getMid() + " https://juick.com/" + msg.getMid(), String.format("[New message](%s) posted", PlainTextFormatter.formatUrl(msg)));
}
@@ -347,6 +345,7 @@ public class CommandsManager {
if (msg != null) {
if (subscribe) {
if (subscriptionService.subscribeMessage(msg, user)) {
+ applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
return CommandResult.fromString("Subscribed");
}
} else {
@@ -398,6 +397,7 @@ public class CommandsManager {
if (msg != null) {
if (showReplies) {
List<com.juick.Message> replies = messagesService.getReplies(user, mid);
+ applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
replies.add(0, msg);
return CommandResult.fromString(String.join("\n",
replies.stream().map(PlainTextFormatter::formatPostSummary).collect(Collectors.toList())));
@@ -491,6 +491,7 @@ public class CommandsManager {
String attachmentStr = attachment.toString();
String attachmentType = StringUtils.isNotEmpty(attachmentStr) ? attachmentStr.substring(attachmentStr.length() - 3) : null;
int newrid = messagesService.createReply(mid, rid, user, txt, attachmentType);
+ applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
if (StringUtils.isNotEmpty(attachmentType)) {
String attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost()
: HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost();
diff --git a/juick-common/src/main/java/com/juick/server/component/MessageReadEvent.java b/juick-common/src/main/java/com/juick/server/component/MessageReadEvent.java
new file mode 100644
index 00000000..e75d3636
--- /dev/null
+++ b/juick-common/src/main/java/com/juick/server/component/MessageReadEvent.java
@@ -0,0 +1,28 @@
+package com.juick.server.component;
+
+import com.juick.Message;
+import com.juick.User;
+import org.springframework.context.ApplicationEvent;
+
+public class MessageReadEvent extends ApplicationEvent {
+ private User user;
+ private Message message;
+ /**
+ * Create a new ApplicationEvent.
+ *
+ * @param source the object on which the event initially occurred (never {@code null})
+ */
+ public MessageReadEvent(Object source, User user, Message message) {
+ super(source);
+ this.user = user;
+ this.message = message;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+}