aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/ws/WebsocketComponent.java6
-rw-r--r--src/main/java/com/juick/ws/XMPPConnection.java25
2 files changed, 19 insertions, 12 deletions
diff --git a/src/main/java/com/juick/ws/WebsocketComponent.java b/src/main/java/com/juick/ws/WebsocketComponent.java
index d38f7b697..daf177539 100644
--- a/src/main/java/com/juick/ws/WebsocketComponent.java
+++ b/src/main/java/com/juick/ws/WebsocketComponent.java
@@ -97,7 +97,10 @@ public class WebsocketComponent extends TextWebSocketHandler {
}
}
if (sockSubscr != null) {
- clients.add(sockSubscr);
+ synchronized (clients) {
+ clients.add(sockSubscr);
+ logger.info(clients.size() + " clients connected");
+ }
}
}
@Override
@@ -110,6 +113,7 @@ public class WebsocketComponent extends TextWebSocketHandler {
}
return false;
});
+ logger.info(clients.size() + " clients connected");
}
}
diff --git a/src/main/java/com/juick/ws/XMPPConnection.java b/src/main/java/com/juick/ws/XMPPConnection.java
index d0bdc42f1..4a80eec52 100644
--- a/src/main/java/com/juick/ws/XMPPConnection.java
+++ b/src/main/java/com/juick/ws/XMPPConnection.java
@@ -108,11 +108,11 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
String json = messageSerializer.serialize(jmsg).toString();
List<Integer> uids = SubscriptionsQueries.getSubscribedUsers(sql, jmsg.getUser().getUID(), jmsg.getMID())
.stream().map(User::getUID).collect(Collectors.toList());
- logger.info(String.format("%d users subscribed to %d", uids.size(), jmsg.getUser().getUID()));
synchronized (wsHandler.clients) {
- Long legacycount = wsHandler.clients.stream().filter(c -> c.legacy && c.allMessages).count();
- logger.info(String.format("%d legacy users watched %d", legacycount, jmsg.getMID()));
- wsHandler.clients.stream().filter(c -> !c.legacy && uids.contains(c.visitor.getUID())).forEach(c -> {
+ wsHandler.clients.stream().filter(c ->
+ (!c.legacy && c.visitor.getUID() == 0) // anonymous users
+ || (!c.legacy && uids.contains(c.visitor.getUID()))) // subscriptions
+ .forEach(c -> {
try {
logger.info("sending message to " + c.visitor.getUID());
c.session.sendMessage(new TextMessage(json));
@@ -120,7 +120,9 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
logger.log(Level.WARNING, "ws error", e);
}
});
- wsHandler.clients.stream().filter(c -> c.legacy && c.allMessages).forEach(c -> {
+ wsHandler.clients.stream().filter(c ->
+ c.legacy && c.allMessages) // legacy all posts
+ .forEach(c -> {
try {
logger.info("sending message to legacy client " + c.visitor.getUID());
c.session.sendMessage(new TextMessage(json));
@@ -133,15 +135,14 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
private void onJuickMessageReply(com.juick.Message jmsg) {
String json = messageSerializer.serialize(jmsg).toString();
- logger.info("got reply: " + json);
List<Integer> threadUsers =
SubscriptionsQueries.getUsersSubscribedToComments(sql, jmsg.getMID(), jmsg.getUser().getUID())
.stream().map(User::getUID).collect(Collectors.toList());
- logger.info(String.format("%d users subscribed to %d", threadUsers.size(), jmsg.getMID()));
synchronized (wsHandler.clients) {
- Long legacycount = wsHandler.clients.stream().filter(c -> c.legacy && c.allReplies).count();
- logger.info(String.format("%d legacy users watched %d", legacycount, jmsg.getMID()));
- wsHandler.clients.stream().filter(c -> !c.legacy && threadUsers.contains(c.visitor.getUID())).forEach(c -> {
+ wsHandler.clients.stream().filter(c ->
+ (!c.legacy && c.visitor.getUID() == 0) // anonymous users
+ || (!c.legacy && threadUsers.contains(c.visitor.getUID()))) // subscriptions
+ .forEach(c -> {
try {
logger.info("sending reply to " + c.visitor.getUID());
c.session.sendMessage(new TextMessage(json));
@@ -149,7 +150,9 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
logger.log(Level.WARNING, "ws error", e);
}
});
- wsHandler.clients.stream().filter(c -> (c.legacy && c.allReplies) || (c.legacy && c.MID == jmsg.getMID())).forEach(c -> {
+ wsHandler.clients.stream().filter(c ->
+ (c.legacy && c.allReplies) || (c.legacy && c.MID == jmsg.getMID())) // legacy replies
+ .forEach(c -> {
try {
logger.info("sending reply to legacy client " + c.visitor.getUID());
c.session.sendMessage(new TextMessage(json));