diff options
author | Vitaly Takmazov | 2017-12-25 14:16:18 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-12-25 14:16:18 +0300 |
commit | ad7b47d7b928d7f1100abfbee1ff82f526eafce2 (patch) | |
tree | 09c7069aa023b711da91af78d14be07aee5b4d99 /juick-api/src/main/java | |
parent | 53a86871b8e7a352ccecab21f9edc3df025b68ce (diff) |
change subject for email replies
Diffstat (limited to 'juick-api/src/main/java')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/EmailManager.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/juick-api/src/main/java/com/juick/api/EmailManager.java b/juick-api/src/main/java/com/juick/api/EmailManager.java index a2ddbc3b..1573e7be 100644 --- a/juick-api/src/main/java/com/juick/api/EmailManager.java +++ b/juick-api/src/main/java/com/juick/api/EmailManager.java @@ -4,6 +4,7 @@ import com.juick.Message; import com.juick.server.component.MessageEvent; import com.juick.server.util.HttpBadRequestException; import com.juick.service.EmailService; +import com.juick.service.MessagesService; import com.juick.service.SubscriptionService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,21 +31,26 @@ public class EmailManager implements ApplicationListener<MessageEvent> { EmailService emailService; @Inject SubscriptionService subscriptionService; + @Inject + MessagesService messagesService; @Override public void onApplicationEvent(MessageEvent event) { Message msg = event.getMessage(); if (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, msg))); + .forEach(email -> emailNotify(email, subject, msg))); } else { + Message originalMessage = messagesService.getMessage(msg.getMid()); + String subject = String.format("New reply to %s", originalMessage.getUser().getName()); subscriptionService.getUsersSubscribedToComments(msg.getMid(), msg.getUser().getUid()) .forEach(user -> emailService.getEmails(user.getUid(), true) - .forEach(email -> emailNotify(email, msg))); + .forEach(email -> emailNotify(email, subject, msg))); } } - void emailNotify(String email, Message msg) { + void emailNotify(String email, String subject, Message msg) { Properties prop = System.getProperties(); prop.put("mail.smtp.starttls.enable", "true"); Session session = Session.getDefaultInstance(prop); @@ -53,11 +59,11 @@ public class EmailManager implements ApplicationListener<MessageEvent> { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress("juick@juick.com")); message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(email)); - message.setSubject(String.format("New message from %s", msg.getUser().getName())); + message.setSubject(subject); message.setText(String.format("%s\n%s\n---\nYou are receiving this because you are subscribed to this user " + "or discussion. Configure notifications at https://juick.com/settings", formatPost(msg), formatUrl(msg))); - transport.send(message); + transport.sendMessage(message, message.getAllRecipients()); } catch (MessagingException ex) { logger.error("mail exception", ex); } |