diff options
Diffstat (limited to 'src/main/java/com/juick/server/CommandsManager.java')
-rw-r--r-- | src/main/java/com/juick/server/CommandsManager.java | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/main/java/com/juick/server/CommandsManager.java b/src/main/java/com/juick/server/CommandsManager.java index b21ff81c..6fd88f07 100644 --- a/src/main/java/com/juick/server/CommandsManager.java +++ b/src/main/java/com/juick/server/CommandsManager.java @@ -23,6 +23,7 @@ import com.juick.User; import com.juick.formatters.PlainTextFormatter; import com.juick.model.CommandResult; import com.juick.model.TagStats; +import com.juick.server.api.SystemActivity; import com.juick.server.helpers.annotation.UserCommand; import com.juick.server.util.HttpUtils; import com.juick.server.www.WebApp; @@ -141,9 +142,12 @@ public class CommandsManager { msg.getUser().setAvatar(webApp.getAvatarUrl(msg.getUser())); subscriptionService.subscribeMessage(msg, user); - applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg)); - applicationEventPublisher.publishEvent(new MessageEvent(this, msg, subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg))); - 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))); + applicationEventPublisher.publishEvent(new SystemEvent(this, SystemActivity.read(user, msg))); + applicationEventPublisher.publishEvent(new SystemEvent(this, + SystemActivity.message(user, msg, subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg)))); + 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))); } @UserCommand(pattern = "^ping$", patternFlags = Pattern.CASE_INSENSITIVE, @@ -180,7 +184,8 @@ public class CommandsManager { jmsg.setUser(user_from); jmsg.setTo(user_to); jmsg.setText(body); - applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg, Collections.singletonList(user_to))); + applicationEventPublisher.publishEvent(new SystemEvent(this, + SystemActivity.message(user_from, jmsg, Collections.singletonList(user_to)))); return CommandResult.fromString("Private message sent"); } } @@ -314,9 +319,9 @@ public class CommandsManager { MessagesService.RecommendStatus status = messagesService.recommendMessage(mid, user.getUid(), user.getUri().toASCIIString()); switch (status) { case Added: - applicationEventPublisher.publishEvent(new LikeEvent(this, user, msg.get(), + applicationEventPublisher.publishEvent(new SystemEvent(this, SystemActivity.like(user, msg.get(), subscriptionService.getUsersSubscribedToUserRecommendations( - user.getUid(), msg.get()))); + user.getUid(), msg.get())))); return CommandResult.fromString("Message is added to your recommendations"); case Deleted: return CommandResult.fromString("Message deleted from your recommendations."); @@ -338,7 +343,8 @@ public class CommandsManager { if (subscribe) { if (subscriptionService.subscribeUser(user, toUser)) { // TODO: already subscribed case - applicationEventPublisher.publishEvent(new SubscribeEvent(this, user, toUser)); + applicationEventPublisher.publishEvent(new SystemEvent(this, + SystemActivity.follow(user, Collections.singletonList(toUser)))); return CommandResult.fromString("Subscribed to @" + toUser.getName()); } } else { @@ -376,7 +382,7 @@ public class CommandsManager { if (subscribe) { if (subscriptionService.subscribeMessage(msg.get(), user)) { applicationEventPublisher.publishEvent( - new MessageReadEvent(this, user, msg.get())); + new SystemEvent(this, SystemActivity.read(user, msg.get()))); return CommandResult.fromString("Subscribed"); } } else { @@ -429,10 +435,10 @@ public class CommandsManager { if (showReplies) { List<com.juick.Message> replies = messagesService.getReplies(user, mid); applicationEventPublisher.publishEvent( - new MessageReadEvent(this, user, msg.get())); + new SystemEvent(this, SystemActivity.read(user, msg.get()))); replies.add(0, msg.get()); - return CommandResult.fromString(String.join("\n", - replies.stream().map(PlainTextFormatter::formatPostSummary).collect(Collectors.toList()))); + return CommandResult.fromString(replies.stream() + .map(PlainTextFormatter::formatPostSummary).collect(Collectors.joining("\n"))); } return CommandResult.fromString(PlainTextFormatter.formatPost(msg.get())); } @@ -474,8 +480,8 @@ public class CommandsManager { } @UserCommand(pattern = "^D #(\\d+)(\\.|\\-|\\/)(\\d+)$", help = "D #1234/5 - Delete comment", patternFlags = Pattern.CASE_INSENSITIVE) public CommandResult commandDeleteReply(User user, URI attachment, String... args) { - int mid = Integer.valueOf(args[0]); - int rid = Integer.valueOf(args[2]); + int mid = Integer.parseInt(args[0]); + int rid = Integer.parseInt(args[2]); if (messagesService.deleteReply(user.getUid(), mid, rid)) { return CommandResult.fromString("Reply deleted"); } else { @@ -556,12 +562,15 @@ public class CommandsManager { imagesService.saveImageWithPreviews(attachmentFName, fname); } applicationEventPublisher.publishEvent( - new MessageReadEvent(this, user, msg.get())); + new SystemEvent(this, SystemActivity.read(user, msg.get()))); Message original = messagesService.getMessage(mid).orElseThrow(IllegalStateException::new); subscriptionService.subscribeMessage(original, user); Message reply = messagesService.getReply(mid, newrid); reply.getUser().setAvatar(webApp.getAvatarUrl(reply.getUser())); - applicationEventPublisher.publishEvent(new MessageEvent(this, reply, subscriptionService.getUsersSubscribedToComments(original, reply))); + applicationEventPublisher.publishEvent( + new SystemEvent(this, + SystemActivity.message(reply.getUser(), reply, + subscriptionService.getUsersSubscribedToComments(original, reply)))); return CommandResult.build(reply, "Reply posted.\n#" + mid + "/" + newrid + " " + "https://juick.com/m/" + mid + "#" + newrid, String.format("[Reply](%s) posted", PlainTextFormatter.formatUrl(reply))); |