From ed993af2e0e95b9af8c949fc0a5c812e93731c14 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 17 Jan 2017 17:31:19 +0300 Subject: juick-server: messagePosted protocol event --- juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'juick-ws/src/main') 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 { -- cgit v1.2.3