aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/ServerManager.java
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-server/src/main/java/com/juick/server/ServerManager.java
parentd2a1f21717c8583c9804c69319123fb7ebaac261 (diff)
server: MessageReadEvent
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/ServerManager.java')
-rw-r--r--juick-server/src/main/java/com/juick/server/ServerManager.java48
1 files changed, 40 insertions, 8 deletions
diff --git a/juick-server/src/main/java/com/juick/server/ServerManager.java b/juick-server/src/main/java/com/juick/server/ServerManager.java
index 3db6ec90..fa266c77 100644
--- a/juick-server/src/main/java/com/juick/server/ServerManager.java
+++ b/juick-server/src/main/java/com/juick/server/ServerManager.java
@@ -20,10 +20,11 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.Message;
import com.juick.User;
-import com.juick.server.component.MessageEvent;
+import com.juick.server.component.*;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
import com.juick.service.UserService;
+import com.juick.util.MessageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -41,7 +42,7 @@ import java.util.stream.Collectors;
* @author Ugnich Anton
*/
@Component
-public class ServerManager implements ApplicationListener<MessageEvent> {
+public class ServerManager implements NotificationListener {
private static Logger logger = LoggerFactory.getLogger(ServerManager.class);
@Inject
@@ -151,14 +152,15 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
}
@Override
- public void onApplicationEvent(@Nonnull MessageEvent event) {
+ public void processMessageEvent(MessageEvent event) {
com.juick.Message jmsg = event.getMessage();
List<User> subscribedUsers = event.getUsers();
- if (jmsg.getMid() == 0) {
- if (jmsg.getTo().getUid() > 0) {
- onJuickPM(jmsg.getTo().getUid(), jmsg);
- }
- } else if (jmsg.getRid() == 0) {
+ if (jmsg.isService()) {
+ return;
+ }
+ if (MessageUtils.isPM(jmsg)) {
+ onJuickPM(jmsg.getTo().getUid(), jmsg);
+ } else if (!MessageUtils.isReply(jmsg)) {
// to get full message with attachment, etc.
onJuickMessagePost(messagesService.getMessage(jmsg.getMid()), subscribedUsers);
} else {
@@ -171,4 +173,34 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
onJuickMessageReply(reply, subscribedUsers);
}
}
+
+ @Override
+ public void processSubscribeEvent(SubscribeEvent subscribeEvent) {
+
+ }
+
+ @Override
+ public void processLikeEvent(LikeEvent likeEvent) {
+
+ }
+
+ @Override
+ public void processPingEvent(PingEvent pingEvent) {
+
+ }
+
+ @Override
+ public void processMessageReadEvent(MessageReadEvent messageReadEvent) {
+ User userTo = messageReadEvent.getUser();
+ Message source = messageReadEvent.getMessage();
+ wsHandler.getClients().stream().filter(c ->
+ (!c.legacy && c.visitor.getUid() == userTo.getUid()) || c.visitor.getName().equals(serviceUser)
+ ).forEach(u -> {
+ Message serviceMessage = new Message();
+ serviceMessage.setService(true);
+ serviceMessage.setUser(userTo);
+ serviceMessage.setMid(source.getMid());
+ serviceMessage.setUnread(false);
+ });
+ }
}