aboutsummaryrefslogtreecommitdiff
path: root/juick-common/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-12 14:17:46 +0300
committerGravatar Vitaly Takmazov2018-04-12 14:17:46 +0300
commit9e5a6b3f2f6907f18f22718bcb6f0ac7f79c95cd (patch)
tree06d4eab436f56607f324cd2c43808854c35a6dfc /juick-common/src/main/java
parente24f7a7ce9eb765aa2f581defbe20433a647700d (diff)
server: MessageEvent now have list of subscribers
Diffstat (limited to 'juick-common/src/main/java')
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java11
-rw-r--r--juick-common/src/main/java/com/juick/server/component/LikeEvent.java10
-rw-r--r--juick-common/src/main/java/com/juick/server/component/MessageEvent.java11
3 files changed, 26 insertions, 6 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 cde6a4bf..9b7cda32 100644
--- a/juick-common/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java
@@ -110,7 +110,7 @@ public class CommandsManager {
imagesService.saveImageWithPreviews(attachmentFName, fname);
}
com.juick.Message msg = messagesService.getMessage(mid);
- applicationEventPublisher.publishEvent(new MessageEvent(this, 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)));
}
@@ -148,7 +148,7 @@ public class CommandsManager {
jmsg.setUser(user_from);
jmsg.setTo(user_to);
jmsg.setText(body);
- applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
+ applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg, Collections.singletonList(user_to)));
return CommandResult.fromString("Private message sent");
}
}
@@ -283,7 +283,9 @@ public class CommandsManager {
MessagesService.RecommendStatus status = messagesService.recommendMessage(mid, user.getUid());
switch (status) {
case Added:
- applicationEventPublisher.publishEvent(new LikeEvent(this, user, msg));
+ applicationEventPublisher.publishEvent(new LikeEvent(this, user, msg,
+ subscriptionService.getUsersSubscribedToUserRecommendations(
+ user.getUid(), msg.getMid(), msg.getUser().getUid())));
return CommandResult.fromString("Message is added to your recommendations");
case Deleted:
return CommandResult.fromString("Message deleted from your recommendations.");
@@ -485,8 +487,9 @@ public class CommandsManager {
String fname = String.format("%d-%d.%s", mid, newrid, attachmentType);
imagesService.saveImageWithPreviews(attachmentFName, fname);
}
+ Message original = messagesService.getMessage(mid);
Message reply = messagesService.getReply(mid, newrid);
- applicationEventPublisher.publishEvent(new MessageEvent(this, reply));
+ applicationEventPublisher.publishEvent(new MessageEvent(this, reply, subscriptionService.getUsersSubscribedToComments(original, reply)));
return CommandResult.build(reply,"Reply posted.\n#" + mid + "/" + newrid + " "
+ "https://juick.com/" + mid + "#" + newrid,
String.format("[Reply](%s) posted", PlainTextFormatter.formatUrl(reply)));
diff --git a/juick-common/src/main/java/com/juick/server/component/LikeEvent.java b/juick-common/src/main/java/com/juick/server/component/LikeEvent.java
index 8ff0a184..678a84a9 100644
--- a/juick-common/src/main/java/com/juick/server/component/LikeEvent.java
+++ b/juick-common/src/main/java/com/juick/server/component/LikeEvent.java
@@ -4,18 +4,22 @@ import com.juick.Message;
import com.juick.User;
import org.springframework.context.ApplicationEvent;
+import java.util.List;
+
public class LikeEvent extends ApplicationEvent {
private User user;
private Message message;
+ private List<User> subscribers;
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
*/
- public LikeEvent(Object source, User user, Message message) {
+ public LikeEvent(Object source, User user, Message message, List<User> subscribers) {
super(source);
this.message = message;
this.user = user;
+ this.subscribers = subscribers;
}
public User getUser() {
@@ -25,4 +29,8 @@ public class LikeEvent extends ApplicationEvent {
public Message getMessage() {
return message;
}
+
+ public List<User> getSubscribers() {
+ return subscribers;
+ }
}
diff --git a/juick-common/src/main/java/com/juick/server/component/MessageEvent.java b/juick-common/src/main/java/com/juick/server/component/MessageEvent.java
index 048de6a6..c0c60228 100644
--- a/juick-common/src/main/java/com/juick/server/component/MessageEvent.java
+++ b/juick-common/src/main/java/com/juick/server/component/MessageEvent.java
@@ -1,22 +1,31 @@
package com.juick.server.component;
import com.juick.Message;
+import com.juick.User;
import org.springframework.context.ApplicationEvent;
+import java.util.List;
+
public class MessageEvent extends ApplicationEvent {
private Message message;
+ private List<User> users;
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
* @param message app message
+ * @param interestedUsers users interested in notification
*/
- public MessageEvent(Object source, Message message) {
+ public MessageEvent(Object source, Message message, List<User> interestedUsers) {
super(source);
this.message = message;
+ this.users = interestedUsers;
}
public Message getMessage() {
return message;
}
+ public List<User> getUsers() {
+ return users;
+ }
}