From ad7b47d7b928d7f1100abfbee1ff82f526eafce2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 25 Dec 2017 14:16:18 +0300 Subject: change subject for email replies --- juick-api/src/main/java/com/juick/api/EmailManager.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'juick-api/src/main/java/com/juick') 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 { 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 { 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); } -- cgit v1.2.3