From 753d79d6bbabfdac33c6c382717fe0acaec2a3bd Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 11 Oct 2017 12:47:02 +0300 Subject: telegram: do not duplicate subscription requests --- juick-api/src/main/java/com/juick/api/TelegramBotManager.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'juick-api/src/main') diff --git a/juick-api/src/main/java/com/juick/api/TelegramBotManager.java b/juick-api/src/main/java/com/juick/api/TelegramBotManager.java index 161680e9..4de5c840 100644 --- a/juick-api/src/main/java/com/juick/api/TelegramBotManager.java +++ b/juick-api/src/main/java/com/juick/api/TelegramBotManager.java @@ -19,6 +19,7 @@ package com.juick.api; import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.service.MessagesService; +import com.juick.service.SubscriptionService; import com.juick.service.TelegramService; import com.pengrad.telegrambot.Callback; import com.pengrad.telegrambot.TelegramBot; @@ -64,6 +65,8 @@ public class TelegramBotManager extends TextWebSocketHandler { @Inject private MessagesService messagesService; @Inject + private SubscriptionService subscriptionService; + @Inject private ObjectMapper jsonMapper; private WebSocketSession session; @@ -115,7 +118,7 @@ public class TelegramBotManager extends TextWebSocketHandler { if (jmsg.getRid() == 0) { String msg = formatPost(jmsg); - List users = telegramService.getSubscribers(jmsg.getUser().getUid()); + List users = telegramService.getTelegramIdentifiers(subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid())); List chats = telegramService.getChats(); // registered subscribed users @@ -126,7 +129,9 @@ public class TelegramBotManager extends TextWebSocketHandler { // get quote com.juick.Message msg = messagesService.getReply(jmsg.getMid(), jmsg.getRid()); String fmsg = formatPost(msg); - telegramService.getSubscribersToComments(jmsg.getMid(), jmsg.getUser().getUid()).forEach(c -> telegramNotify(c, fmsg, msgUrl)); + telegramService.getTelegramIdentifiers( + subscriptionService.getUsersSubscribedToComments(jmsg.getMid(), jmsg.getUser().getUid()) + ).forEach(c -> telegramNotify(c, fmsg, msgUrl)); } } -- cgit v1.2.3