From 9e5a6b3f2f6907f18f22718bcb6f0ac7f79c95cd Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 12 Apr 2018 14:17:46 +0300 Subject: server: MessageEvent now have list of subscribers --- .../main/java/com/juick/server/XMPPConnection.java | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'juick-server-xmpp/src/main') diff --git a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java index 884b1563..bf3f54e1 100644 --- a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java @@ -74,6 +74,7 @@ import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -261,13 +262,12 @@ public class XMPPConnection implements StanzaListener, NotificationListener { return stanzaWriter.toString(); } - private void sendJuickMessage(com.juick.Message jmsg) { + private void sendJuickMessage(com.juick.Message jmsg, List users) { List jids = new ArrayList<>(); if (jmsg.FriendsOnly) { jids = subscriptionService.getJIDSubscribedToUser(jmsg.getUser().getUid(), jmsg.FriendsOnly); } else { - List users = subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid()); for (User user : users) { jids.addAll(userService.getJIDsbyUID(user.getUid())); } @@ -304,13 +304,10 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } } - public void sendJuickComment(com.juick.Message jmsg) { - List users; + public void sendJuickComment(com.juick.Message jmsg, List users) { String replyQuote; String replyTo; - com.juick.Message op = messagesService.getMessage(jmsg.getMid()); - users = subscriptionService.getUsersSubscribedToComments(op, jmsg); com.juick.Message replyMessage = jmsg.getReplyto() > 0 ? messagesService.getReply(jmsg.getMid(), jmsg.getReplyto()) : messagesService.getMessage(jmsg.getMid()); replyTo = replyMessage.getUser().getName(); @@ -340,6 +337,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { @Override public void processMessageEvent(MessageEvent event) { com.juick.Message msg = event.getMessage(); + List subscribers = event.getUsers(); if (MessageUtils.isPM(msg)) { userService.getJIDsbyUID(msg.getTo().getUid()) .forEach(userJid -> { @@ -357,10 +355,10 @@ public class XMPPConnection implements StanzaListener, NotificationListener { router.send(ClientMessage.from(mm)); }); } else if (MessageUtils.isReply(msg)) { - sendJuickComment(msg); + sendJuickComment(msg, subscribers); } else { - sendJuickMessage(msg); + sendJuickMessage(msg, subscribers); } } @@ -380,11 +378,9 @@ public class XMPPConnection implements StanzaListener, NotificationListener { @Override public void processLikeEvent(LikeEvent likeEvent) { - List users; + List users = likeEvent.getSubscribers(); com.juick.Message jmsg = likeEvent.getMessage(); User liker = likeEvent.getUser(); - users = subscriptionService.getUsersSubscribedToUserRecommendations(liker.getUid(), - jmsg.getMid(), jmsg.getUser().getUid()); String txt = "Recommended by @" + liker.getName() + ":\n"; txt += "@" + jmsg.getUser().getName() + ":" + MessageUtils.getTagsString(jmsg) + "\n"; @@ -551,15 +547,17 @@ public class XMPPConnection implements StanzaListener, NotificationListener { com.juick.Message jmsg = msg.getExtension(com.juick.Message.class); if (jmsg != null) { if (to.getLocal().equals("pm")) { - applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg)); + applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg, Collections.singletonList(jmsg.getTo()))); } else { if (MessageUtils.isReply(jmsg)) { // to get quote and attachment + com.juick.Message original = messagesService.getMessage(jmsg.getMid()); com.juick.Message reply = messagesService.getReply(jmsg.getMid(), jmsg.getRid()); - applicationEventPublisher.publishEvent(new MessageEvent(this, reply)); + applicationEventPublisher.publishEvent(new MessageEvent(this, reply, + subscriptionService.getUsersSubscribedToComments(original, reply))); } else if (!MessageUtils.isPM(jmsg)) { applicationEventPublisher.publishEvent(new MessageEvent(this, - messagesService.getMessage(jmsg.getMid()))); + messagesService.getMessage(jmsg.getMid()), subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid()))); } } } else { -- cgit v1.2.3