aboutsummaryrefslogtreecommitdiff
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
parentf86e3e089ff4e4e27133156e277c94d4cd8c7111 (diff)
server: PMs in email
* also introduces MessageUtils.isReply and MessageUtils.isPM
-rw-r--r--juick-common/src/main/java/com/juick/formatters/PlainTextFormatter.java10
-rw-r--r--juick-common/src/main/java/com/juick/util/MessageUtils.java6
-rw-r--r--juick-notifications/src/main/java/com/juick/components/Notifications.java6
-rw-r--r--juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java6
-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
6 files changed, 33 insertions, 26 deletions
diff --git a/juick-common/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-common/src/main/java/com/juick/formatters/PlainTextFormatter.java
index a47a6113..0e7569ab 100644
--- a/juick-common/src/main/java/com/juick/formatters/PlainTextFormatter.java
+++ b/juick-common/src/main/java/com/juick/formatters/PlainTextFormatter.java
@@ -37,10 +37,8 @@ public class PlainTextFormatter {
public static String formatPost(Message jmsg, boolean markdown) {
StringBuilder sb = new StringBuilder();
- boolean isPM = jmsg.getMid() == 0;
- boolean isReply = jmsg.getRid() > 0;
- String title = isReply ? "Reply by @" : isPM ? "Private message from @" : "@";
- String subtitle = isReply ? markdown ? MessageUtils.escapeMarkdown(StringUtils.defaultString(jmsg.getReplyQuote()))
+ String title = MessageUtils.isReply(jmsg) ? "Reply by @" : MessageUtils.isPM(jmsg) ? "Private message from @" : "@";
+ String subtitle = MessageUtils.isReply(jmsg) ? markdown ? MessageUtils.escapeMarkdown(StringUtils.defaultString(jmsg.getReplyQuote()))
: jmsg.getReplyQuote()
: markdown ? MessageUtils.getMarkdownTags(jmsg) : MessageUtils.getTagsString(jmsg);
sb.append(title).append(markdown ? MessageUtils.getMarkdownUser(jmsg.getUser()) : jmsg.getUser().getName()).append(":\n")
@@ -78,8 +76,10 @@ public class PlainTextFormatter {
}
public static String formatUrl(com.juick.Message jmsg) {
- if (jmsg.getRid() > 0) {
+ if (MessageUtils.isReply(jmsg)) {
return String.format("https://juick.com/%d#%d", jmsg.getMid(), jmsg.getRid());
+ } else if (MessageUtils.isPM(jmsg)) {
+ return "https://juick.com/pm/inbox";
}
return "https://juick.com/" + jmsg.getMid();
}
diff --git a/juick-common/src/main/java/com/juick/util/MessageUtils.java b/juick-common/src/main/java/com/juick/util/MessageUtils.java
index 10314bb0..bb7edfc3 100644
--- a/juick-common/src/main/java/com/juick/util/MessageUtils.java
+++ b/juick-common/src/main/java/com/juick/util/MessageUtils.java
@@ -262,4 +262,10 @@ public class MessageUtils {
}
return builder.toString();
}
+ public static boolean isPM(Message message) {
+ return message.getMid() == 0;
+ }
+ public static boolean isReply(Message message) {
+ return message.getRid() > 0;
+ }
}
diff --git a/juick-notifications/src/main/java/com/juick/components/Notifications.java b/juick-notifications/src/main/java/com/juick/components/Notifications.java
index a43d985c..410debd4 100644
--- a/juick-notifications/src/main/java/com/juick/components/Notifications.java
+++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java
@@ -81,18 +81,16 @@ public class Notifications implements NotificationClientListener, AutoCloseable,
@Override
public void onApplicationEvent(@Nonnull MessageEvent event) {
com.juick.Message jmsg = event.getMessage();
- boolean isPM = jmsg.getMid() == 0;
- boolean isReply = jmsg.getRid() > 0;
User pmTo = jmsg.getTo();
final List<User> users = new ArrayList<>();
- if (isPM) {
+ if (MessageUtils.isPM(jmsg)) {
users.addAll(rest.exchange(String.format("http://api.juick.com/notifications?uid=%d",
pmTo.getUid()),
HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
}).getBody());
} else {
- if (isReply) {
+ if (MessageUtils.isReply(jmsg)) {
users.addAll(rest.exchange(String.format("http://api.juick.com/notifications?uid=%d&mid=%d&rid=%d",
jmsg.getUser().getUid(), jmsg.getMid(), jmsg.getRid()),
HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
diff --git a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java
index f0c205d9..19fddd78 100644
--- a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java
+++ b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java
@@ -391,9 +391,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
@Override
public void processMessageEvent(MessageEvent event) {
com.juick.Message msg = event.getMessage();
- boolean isPM = msg.getMid() == 0;
- boolean isReply = msg.getRid() > 0;
- if (isPM) {
+ if (MessageUtils.isPM(msg)) {
userService.getJIDsbyUID(msg.getTo().getUid())
.forEach(userJid -> {
Message mm = new Message();
@@ -409,7 +407,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
}
router.send(ClientMessage.from(mm));
});
- } else if (isReply) {
+ } else if (MessageUtils.isReply(msg)) {
sendJuickComment(msg);
}
else {
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(