From 240a375ecdeb7592d8765f0edb7d2fd67c50ac10 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 30 Oct 2017 13:52:55 +0300 Subject: xmpp: bot refactoring --- .../main/java/com/juick/ws/WebsocketComponent.java | 51 +--------------------- 1 file changed, 1 insertion(+), 50 deletions(-) (limited to 'juick-ws') 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 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 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; -- cgit v1.2.3