diff options
author | Vitaly Takmazov | 2017-10-30 13:52:55 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-10-30 23:55:25 +0300 |
commit | 240a375ecdeb7592d8765f0edb7d2fd67c50ac10 (patch) | |
tree | 7d518988a1fc3c79ccb00cd07fdb4201569c674e /juick-ws/src | |
parent | 3ca4188155e5f04a5cc96c4be20ef206e9f3ffde (diff) |
xmpp: bot refactoring
Diffstat (limited to 'juick-ws/src')
-rw-r--r-- | juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java | 51 |
1 files changed, 1 insertions, 50 deletions
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 bdf6dba6..599d1394 100644 --- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java @@ -51,7 +51,7 @@ import java.util.List; /** * Created by vitalyster on 28.06.2016. */ -public class WebsocketComponent extends TextWebSocketHandler implements ProtocolListener { +public class WebsocketComponent extends TextWebSocketHandler { private static final Logger logger = LoggerFactory.getLogger(WebsocketComponent.class); private final List<SocketSubscribed> clients = Collections.synchronizedList(new LinkedList<>()); @@ -62,13 +62,7 @@ public class WebsocketComponent extends TextWebSocketHandler implements Protocol private MessagesService messagesService; @Inject private SubscriptionService subscriptionService; - @Inject - private JuickProtocol protocol; - @PostConstruct - public void init() { - protocol.setListener(this); - } @Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { @@ -148,53 +142,10 @@ public class WebsocketComponent extends TextWebSocketHandler implements Protocol } }); } - - @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - getClients().stream().filter(s -> !s.legacy && s.session.equals(session)).forEach(s -> { - User user = s.visitor; - String input = message.getPayload(); - if (StringUtils.isNotBlank(input)) { - try { - s.session.sendMessage(new TextMessage(protocol.getReply(user, input))); - } catch (IOException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { - logger.error("protocol exception", e); - } - } - }); - } - public List<SocketSubscribed> getClients() { return clients; } - @Override - public void privateMessage(User from, User to, String body) { - notifyUser(from, to, "Private message from @" + from.getName() + ":\n" + body); - } - - @Override - public void userSubscribed(User from, User to) { - 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 { - s.session.sendMessage(new TextMessage(body)); - } catch (IOException e) { - logger.error("protocol exception", e); - } - }); - } - class SocketSubscribed { WebSocketSession session; String clientName; |