diff options
4 files changed, 20 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java index 19275b36..2597ddbc 100644 --- a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java +++ b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java @@ -88,6 +88,7 @@ public class JuickProtocol { String body = input.substring(TagUtils.toString(tags).length()); int mid = messagesService.createMessage(user.getUid(), body, null, tags); subscriptionService.subscribeMessage(mid, user.getUid()); + listener.messagePosted(messagesService.getMessage(mid)); return new ProtocolReply("New message posted.\n#" + mid + " " + baseUri + mid); } @@ -344,6 +345,7 @@ public class JuickProtocol { return new ProtocolReply("Tags are updated"); } else { int newrid = messagesService.createReply(mid, rid, user.getUid(), txt, null); + listener.messagePosted(messagesService.getReply(mid, newrid)); return new ProtocolReply("Reply posted.\n#" + mid + "/" + newrid + " " + baseUri + mid + "#" + newrid); } diff --git a/juick-server/src/main/java/com/juick/server/protocol/ProtocolListener.java b/juick-server/src/main/java/com/juick/server/protocol/ProtocolListener.java index 719520c7..11231e04 100644 --- a/juick-server/src/main/java/com/juick/server/protocol/ProtocolListener.java +++ b/juick-server/src/main/java/com/juick/server/protocol/ProtocolListener.java @@ -1,5 +1,6 @@ package com.juick.server.protocol; +import com.juick.Message; import com.juick.User; /** @@ -8,4 +9,5 @@ import com.juick.User; public interface ProtocolListener { void privateMessage(User from, User to, String body); void userSubscribed(User from, User to); + void messagePosted(Message msg); } diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java index 909933e4..23223c0e 100644 --- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java @@ -1,9 +1,11 @@ package com.juick.ws; +import com.juick.Message; import com.juick.User; import com.juick.server.protocol.JuickProtocol; import com.juick.server.protocol.ProtocolListener; import com.juick.service.MessagesService; +import com.juick.service.SubscriptionService; import com.juick.service.UserService; import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; @@ -42,6 +44,8 @@ public class WebsocketComponent extends TextWebSocketHandler implements Protocol @Inject MessagesService messagesService; @Inject + SubscriptionService subscriptionService; + @Inject JuickProtocol protocol; @PostConstruct @@ -172,6 +176,13 @@ public class WebsocketComponent extends TextWebSocketHandler implements Protocol notifyUser(from, to, String.format("@%s subscribed to your blog", from.getName())); } + @Override + public void messagePosted(Message msg) { + subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid()).forEach(u -> { + notifyUser(msg.getUser(), u, msg.getText()); + }); + } + private void notifyUser(User from, User to, String body) { getClients().stream().filter(s -> !s.legacy && s.visitor.equals(to)).forEach(s -> { try { diff --git a/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java b/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java index 234d04f8..d5c4c045 100644 --- a/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java +++ b/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java @@ -137,4 +137,9 @@ public class XMPPBot implements AutoCloseable, ProtocolListener { component.send(mm); }); } + + @Override + public void messagePosted(com.juick.Message msg) { + + } } |