aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/ServerManager.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-server/src/main/java/com/juick/server/ServerManager.java
parente24f7a7ce9eb765aa2f581defbe20433a647700d (diff)
server: MessageEvent now have list of subscribers
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.java21
1 files changed, 9 insertions, 12 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 40de9d3e..f209d934 100644
--- a/juick-server/src/main/java/com/juick/server/ServerManager.java
+++ b/juick-server/src/main/java/com/juick/server/ServerManager.java
@@ -22,18 +22,16 @@ import com.juick.User;
import com.juick.server.component.MessageEvent;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
-import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
-import rocks.xmpp.addr.Jid;
+import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.io.IOException;
-import java.net.URI;
import java.util.List;
import java.util.stream.Collectors;
@@ -49,8 +47,6 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
@Inject
private MessagesService messagesService;
@Inject
- private SubscriptionService subscriptionService;
- @Inject
private WebsocketManager wsHandler;
@Value("${service_user:juick}")
private String serviceUser;
@@ -77,10 +73,10 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
}
}
- private void onJuickMessagePost(final com.juick.Message jmsg) {
+ private void onJuickMessagePost(final com.juick.Message jmsg, List<User> subscribedUsers) {
try {
String json = jsonMapper.writeValueAsString(jmsg);
- List<Integer> uids = subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid())
+ List<Integer> uids = subscribedUsers
.stream().map(User::getUid).collect(Collectors.toList());
synchronized (wsHandler.getClients()) {
wsHandler.getClients().stream().filter(c ->
@@ -111,13 +107,13 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
}
}
- private void onJuickMessageReply(final com.juick.Message jmsg) {
+ private void onJuickMessageReply(final com.juick.Message jmsg, final List<User> subscribedUsers) {
try {
String json = jsonMapper.writeValueAsString(jmsg);
com.juick.Message op = messagesService.getMessage(jmsg.getMid());
List<Integer> threadUsers =
- subscriptionService.getUsersSubscribedToComments(op, jmsg)
+ subscribedUsers
.stream().map(User::getUid).collect(Collectors.toList());
synchronized (wsHandler.getClients()) {
wsHandler.getClients().stream().filter(c ->
@@ -149,19 +145,20 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
}
@Override
- public void onApplicationEvent(MessageEvent event) {
+ public void onApplicationEvent(@Nonnull 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) {
// to get full message with attachment, etc.
- onJuickMessagePost(messagesService.getMessage(jmsg.getMid()));
+ onJuickMessagePost(messagesService.getMessage(jmsg.getMid()), subscribedUsers);
} else {
// to get quote and attachment
com.juick.Message reply = messagesService.getReply(jmsg.getMid(), jmsg.getRid());
- onJuickMessageReply(reply);
+ onJuickMessageReply(reply, subscribedUsers);
}
}
}