aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick')
-rw-r--r--juick-server/src/main/java/com/juick/server/CommandsManager.java11
-rw-r--r--juick-server/src/main/java/com/juick/server/ServerManager.java32
-rw-r--r--juick-server/src/main/java/com/juick/server/TelegramBotManager.java3
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Messages.java6
4 files changed, 30 insertions, 22 deletions
diff --git a/juick-server/src/main/java/com/juick/server/CommandsManager.java b/juick-server/src/main/java/com/juick/server/CommandsManager.java
index 018cef15..53b93d4c 100644
--- a/juick-server/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-server/src/main/java/com/juick/server/CommandsManager.java
@@ -122,7 +122,7 @@ public class CommandsManager {
Message msg = messagesService.getMessage(mid);
subscriptionService.subscribeMessage(msg, user);
- applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
+ applicationEventPublisher.publishEvent(new MessageReadEvent(this, Collections.singletonList(user), 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/m/" + msg.getMid(), String.format("[New message](%s) posted", PlainTextFormatter.formatUrl(msg)));
}
@@ -356,7 +356,8 @@ public class CommandsManager {
if (msg != null) {
if (subscribe) {
if (subscriptionService.subscribeMessage(msg, user)) {
- applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
+ applicationEventPublisher.publishEvent(
+ new MessageReadEvent(this, Collections.singletonList(user), msg));
return CommandResult.fromString("Subscribed");
}
} else {
@@ -408,7 +409,8 @@ public class CommandsManager {
if (msg != null) {
if (showReplies) {
List<com.juick.Message> replies = messagesService.getReplies(user, mid);
- applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
+ applicationEventPublisher.publishEvent(
+ new MessageReadEvent(this, Collections.singletonList(user), msg));
replies.add(0, msg);
return CommandResult.fromString(String.join("\n",
replies.stream().map(PlainTextFormatter::formatPostSummary).collect(Collectors.toList())));
@@ -508,7 +510,8 @@ public class CommandsManager {
attachmentType = attachmentFName.substring(attachmentFName.length() - 3);
}
int newrid = messagesService.createReply(mid, rid, user, txt, attachmentType);
- applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
+ applicationEventPublisher.publishEvent(
+ new MessageReadEvent(this, Collections.singletonList(user), msg));
if (haveAttachment) {
String fname = String.format("%d-%d.%s", mid, newrid, attachmentType);
imagesService.saveImageWithPreviews(attachmentFName, fname);
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 a50571e6..8a9d224b 100644
--- a/juick-server/src/main/java/com/juick/server/ServerManager.java
+++ b/juick-server/src/main/java/com/juick/server/ServerManager.java
@@ -187,22 +187,24 @@ public class ServerManager implements NotificationListener {
@Override
public void processMessageReadEvent(MessageReadEvent messageReadEvent) {
- User userTo = messageReadEvent.getUser();
+ List<User> users = messageReadEvent.getUsers();
Message source = messageReadEvent.getMessage();
- logger.info("Message read event from {} for {}", userTo.getName(), source.getMid());
- 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);
- try {
- u.sendMessage(new TextMessage(jsonMapper.writeValueAsString(serviceMessage)));
- } catch (IOException e) {
- logger.error("JSON error", e);
- }
+ users.forEach(userTo -> {
+ logger.info("Message read event from {} for {}", userTo.getName(), source.getMid());
+ 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);
+ try {
+ u.sendMessage(new TextMessage(jsonMapper.writeValueAsString(serviceMessage)));
+ } catch (IOException e) {
+ logger.error("JSON error", e);
+ }
+ });
});
}
}
diff --git a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
index 3c9bb46a..ab1675f5 100644
--- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
@@ -312,7 +312,8 @@ public class TelegramBotManager implements NotificationListener {
messagesService.setLastReadComment(userService.getUserByUID(userId)
.orElseThrow(IllegalStateException::new), source.getMid(), source.getRid());
User user = userService.getUserByUID(userId).orElseThrow(IllegalStateException::new);
- applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, source));
+ applicationEventPublisher.publishEvent(
+ new MessageReadEvent(this, Collections.singletonList(user), source));
}
}
}
diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java
index 86f9a20d..6baa154b 100644
--- a/juick-server/src/main/java/com/juick/server/api/Messages.java
+++ b/juick-server/src/main/java/com/juick/server/api/Messages.java
@@ -174,7 +174,8 @@ public class Messages {
msg.setRecommendations(new HashSet<>(messagesService.getMessageRecommendations(msg.getMid())));
List<com.juick.Message> replies = messagesService.getReplies(visitor, mid);
if (!visitor.isAnonymous()) {
- applicationEventPublisher.publishEvent(new MessageReadEvent(this, visitor, msg));
+ applicationEventPublisher.publishEvent(
+ new MessageReadEvent(this, Collections.singletonList(visitor), msg));
}
replies.add(0, msg);
return ResponseEntity.ok(replies);
@@ -188,7 +189,8 @@ public class Messages {
if (!visitor.isAnonymous()) {
messagesService.setLastReadComment(visitor, mid, rid);
Message msg = messagesService.getMessage(mid);
- applicationEventPublisher.publishEvent(new MessageReadEvent(this, visitor, msg));
+ applicationEventPublisher.publishEvent(
+ new MessageReadEvent(this, Collections.singletonList(visitor), msg));
return IOUtils.toByteArray(
Objects.requireNonNull(getClass().getClassLoader().getResource("Transparent.gif")));
}