aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-04 22:20:52 +0300
committerGravatar Vitaly Takmazov2018-04-04 22:20:52 +0300
commit71c29cc99d1b3f71247b81bc42d30f8b52dad240 (patch)
treed859abf882d2a40e5130fbb210ab3dea8d582d42 /juick-server/src
parentf86e3e089ff4e4e27133156e277c94d4cd8c7111 (diff)
server: PMs in email
* also introduces MessageUtils.isReply and MessageUtils.isPM
Diffstat (limited to 'juick-server/src')
-rw-r--r--juick-server/src/main/java/com/juick/server/EmailManager.java25
-rw-r--r--juick-server/src/main/java/com/juick/server/TelegramBotManager.java6
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(