diff options
Diffstat (limited to 'juick-server/src')
-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 |