From 0a3936561d17ee70c9fecac871ea8a4e097cb518 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 28 Mar 2018 21:34:16 +0300 Subject: server: telegram PMs --- .../java/com/juick/server/TelegramBotManager.java | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'juick-server/src') 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 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 -- cgit v1.2.3