diff options
Diffstat (limited to 'juick-server/src/main/java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/EmailManager.java | 25 | ||||
-rw-r--r-- | juick-server/src/main/java/com/juick/server/TelegramBotManager.java | 6 |
2 files changed, 18 insertions, 13 deletions
diff --git a/juick-server/src/main/java/com/juick/server/EmailManager.java b/juick-server/src/main/java/com/juick/server/EmailManager.java index 83db3ac3..b185de5c 100644 --- a/juick-server/src/main/java/com/juick/server/EmailManager.java +++ b/juick-server/src/main/java/com/juick/server/EmailManager.java @@ -44,18 +44,23 @@ public class EmailManager implements ApplicationListener<MessageEvent> { @Override public void onApplicationEvent(@Nonnull MessageEvent event) { Message msg = event.getMessage(); - if (msg.getMid() > 0 && msg.getRid() == 0) { - String subject = String.format("New message from %s", msg.getUser().getName()); - subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid()) - .forEach(user -> emailService.getEmails(user.getUid(), true) - .forEach(email -> emailNotify(email, subject, msg))); - } else if (msg.getRid() > 0) { + if (MessageUtils.isPM(msg)) { + String subject = String.format("Private message from %s", msg.getUser().getName()); + emailService.getEmails(msg.getTo().getUid(), true).forEach(email -> { + emailNotify(email, subject, msg); + }); + } else if (MessageUtils.isReply(msg)) { Message originalMessage = messagesService.getMessage(msg.getMid()); String subject = String.format("New reply to %s", originalMessage.getUser().getName()); subscriptionService.getUsersSubscribedToComments(originalMessage, msg) .stream().filter(user -> !userService.isInBLAny(user.getUid(), msg.getUser().getUid())) .flatMap(user -> emailService.getEmails(user.getUid(), true).stream()) - .forEach(email -> emailNotify(email, subject, msg)); + .forEach(email -> emailNotify(email, subject, msg)); + } else { + String subject = String.format("New message from %s", msg.getUser().getName()); + subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid()) + .forEach(user -> emailService.getEmails(user.getUid(), true) + .forEach(email -> emailNotify(email, subject, msg))); } } @@ -67,8 +72,10 @@ public class EmailManager implements ApplicationListener<MessageEvent> { Transport transport = session.getTransport("smtp"); MimeMessage message = new MimeMessage(session) { protected void updateMessageID() throws MessagingException { - setHeader("Message-ID", String.format("<%d.%d@juick.com>", msg.getMid(), msg.getRid())); - if (msg.getRid() > 0) { + if (!MessageUtils.isPM(msg)) { + setHeader("Message-ID", String.format("<%d.%d@juick.com>", msg.getMid(), msg.getRid())); + } + if (MessageUtils.isReply(msg)) { if (msg.getReplyto() > 0) { Message replyto = messagesService.getReply(msg.getMid(), msg.getReplyto()); setHeader("In-Reply-To", String.format("<%d.%d@juick.com>", replyto.getMid(), replyto.getRid())); 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 320ab9ae..9fcf08da 100644 --- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java +++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java @@ -303,12 +303,10 @@ public class TelegramBotManager implements NotificationListener { public void processMessageEvent(MessageEvent messageEvent) { com.juick.Message jmsg = messageEvent.getMessage(); String msgUrl = formatUrl(jmsg); - boolean isPM = jmsg.getMid() == 0; - boolean isReply = jmsg.getRid() > 0; - if (isPM) { + if (MessageUtils.isPM(jmsg)) { telegramService.getTelegramIdentifiers(Collections.singletonList(jmsg.getTo())) .forEach(c -> telegramNotify(c, formatPost(jmsg, true), null)); - } else if (isReply) { + } else if (MessageUtils.isReply(jmsg)) { com.juick.Message op = messagesService.getMessage(jmsg.getMid()); String fmsg = String.format("[%s](%s) %s", MSG_LINK, msgUrl, formatPost(jmsg, true)); telegramService.getTelegramIdentifiers( |