From 55f245ddcdd7ce18d55cd9a4b6cd0081ac31735b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 15 Aug 2018 15:17:15 +0300 Subject: Author should receive notifications about likes --- .../src/main/java/com/juick/server/TelegramBotManager.java | 8 +++++--- .../src/main/java/com/juick/server/XMPPConnection.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'juick-server/src/main/java/com/juick/server') 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 50fe40e1..b4865dfb 100644 --- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java +++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java @@ -366,9 +366,11 @@ public class TelegramBotManager implements NotificationListener { com.juick.Message message = likeEvent.getMessage(); List subscribers = likeEvent.getSubscribers(); logger.info("Like received in tg listener"); - telegramService.getTelegramIdentifiers(Collections.singletonList(message.getUser())) - .forEach(c -> telegramNotify(c, String.format("%s recommends your [post](%s)", - MessageUtils.getMarkdownUser(liker), formatUrl(message)), new com.juick.Message())); + if (!userService.isInBLAny(message.getUser().getUid(), liker.getUid())) { + telegramService.getTelegramIdentifiers(Collections.singletonList(message.getUser())) + .forEach(c -> telegramNotify(c, String.format("%s recommends your [post](%s)", + MessageUtils.getMarkdownUser(liker), formatUrl(message)), new com.juick.Message())); + } telegramService.getTelegramIdentifiers(subscribers) .forEach(c -> telegramNotify(c, String.format("%s recommends you someone's [post](%s)", MessageUtils.getMarkdownUser(liker), formatUrl(message)), new com.juick.Message())); diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java index 41102322..856b1367 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -18,6 +18,7 @@ package com.juick.server; import com.juick.User; +import com.juick.formatters.PlainTextFormatter; import com.juick.server.component.*; import com.juick.server.helpers.CommandResult; import com.juick.server.helpers.UserInfo; @@ -405,6 +406,19 @@ public class XMPPConnection implements StanzaListener, NotificationListener { com.juick.Message jmsg = likeEvent.getMessage(); User liker = likeEvent.getUser(); + if (!userService.isInBLAny(jmsg.getUser().getUid(), liker.getUid())) { + userService.getJIDsbyUID(jmsg.getUser().getUid()).forEach(authorJid -> { + Message xmppMessage = new Message(); + xmppMessage.setFrom(jid); + xmppMessage.setTo(Jid.of(authorJid)); + xmppMessage.setType(Message.Type.CHAT); + xmppMessage.addExtension(jmsg); + xmppMessage.setBody(String.format("%s recommended your post #%d. %s", + liker.getName(), jmsg.getMid(), PlainTextFormatter.formatUrl(jmsg))); + router.send(ClientMessage.from(xmppMessage)); + }); + } + String txt = "Recommended by @" + liker.getName() + ":\n"; txt += "@" + jmsg.getUser().getName() + ":" + MessageUtils.getTagsString(jmsg) + "\n"; String attachmentUrl = MessageUtils.attachmentUrl(jmsg); -- cgit v1.2.3