diff options
author | Vitaly Takmazov | 2018-03-28 21:34:16 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-28 21:34:16 +0300 |
commit | 0a3936561d17ee70c9fecac871ea8a4e097cb518 (patch) | |
tree | 2095c0700c3027465a1733f310a4bf1d81f82ccd /juick-server/src/main | |
parent | 4b3ddcd138af69f504a9a08281edc1c2e7eb0c7a (diff) |
server: telegram PMs
Diffstat (limited to 'juick-server/src/main')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/TelegramBotManager.java | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java index a44892a4..1aa7273d 100644 --- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java +++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java @@ -309,7 +309,18 @@ public class TelegramBotManager { public void processMessageEvent(MessageEvent messageEvent) { com.juick.Message jmsg = messageEvent.getMessage(); String msgUrl = formatUrl(jmsg); - if (jmsg.getMid() > 0 && jmsg.getRid() == 0) { + boolean isPM = jmsg.getMid() == 0; + boolean isReply = jmsg.getRid() > 0; + if (isPM) { + telegramService.getTelegramIdentifiers(Collections.singletonList(jmsg.getTo())) + .forEach(c -> telegramNotify(c, formatPost(jmsg, true), null)); + } else if (isReply) { + com.juick.Message op = messagesService.getMessage(jmsg.getMid()); + String fmsg = String.format("[%s](%s) %s", MSG_LINK, msgUrl, formatPost(jmsg, true)); + telegramService.getTelegramIdentifiers( + subscriptionService.getUsersSubscribedToComments(op, jmsg) + ).forEach(c -> telegramNotify(c, fmsg, MessageUtils.attachmentUrl(jmsg))); + } else { String msg = String.format("[%s](%s) %s", MSG_LINK, msgUrl, formatPost(jmsg, true)); List<Long> users = telegramService.getTelegramIdentifiers(subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid())); @@ -319,12 +330,6 @@ public class TelegramBotManager { users.forEach(c -> telegramNotify(c, msg, MessageUtils.attachmentUrl(jmsg))); // anonymous chats.stream().filter(u -> telegramService.getUser(u) == 0).forEach(c -> telegramNotify(c, msg, MessageUtils.attachmentUrl(jmsg))); - } else if (jmsg.getRid() > 0) { - com.juick.Message op = messagesService.getMessage(jmsg.getMid()); - String fmsg = String.format("[%s](%s) %s", MSG_LINK, msgUrl, formatPost(jmsg, true)); - telegramService.getTelegramIdentifiers( - subscriptionService.getUsersSubscribedToComments(op, jmsg) - ).forEach(c -> telegramNotify(c, fmsg, MessageUtils.attachmentUrl(jmsg))); } } @EventListener @@ -333,8 +338,8 @@ public class TelegramBotManager { User liker = likeEvent.getUser(); com.juick.Message message = likeEvent.getMessage(); telegramService.getTelegramIdentifiers(Collections.singletonList(message.getUser())) - .forEach(c -> telegramNotify(c, String.format("%s recommends your post", - MessageUtils.getMarkdownUser(liker)),null)); + .forEach(c -> telegramNotify(c, String.format("%s recommends your [post](%s)", + MessageUtils.getMarkdownUser(liker), formatUrl(message)),null)); } @EventListener @Async |