From 7ca0d89a7207994a8d03c8e38c1aef96fcda23ff Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 18 Sep 2019 16:47:32 +0300 Subject: Send events to service email --- src/main/java/com/juick/server/ServerManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/juick/server/ServerManager.java b/src/main/java/com/juick/server/ServerManager.java index d3d17c80..a226bf29 100644 --- a/src/main/java/com/juick/server/ServerManager.java +++ b/src/main/java/com/juick/server/ServerManager.java @@ -16,6 +16,8 @@ */ package com.juick.server; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.Message; import com.juick.User; import com.juick.model.AnonymousUser; @@ -58,9 +60,16 @@ public class ServerManager implements NotificationListener { @Value("${service_user:juick}") private String serviceUsername; + @Value("${service_email:root@localhost}") + private String serviceEmail; private User serviceUser; + @Inject + private EmailManager emailManager; + @Inject + private ObjectMapper jsonMapper; + @PostConstruct public void init() { serviceUser = userService.getUserByName(serviceUsername); @@ -102,6 +111,11 @@ public class ServerManager implements NotificationListener { onJuickMessageReply(jmsg, subscribedUsers); } messageEvent(jmsg, Collections.singletonList(serviceUser)); + try { + emailManager.sendEmail("noreply@juick.com", serviceEmail, "New event", jsonMapper.writeValueAsString(event), null, Collections.emptyMap()); + } catch (JsonProcessingException e) { + logger.warn("JSON exception", e); + } } @Override @@ -147,7 +161,7 @@ public class ServerManager implements NotificationListener { sendSseEvent(msg, "read", subscribers); } - public void messageEvent(Message msg, List subscribers){ + public void messageEvent(Message msg, List subscribers) { sendSseEvent(msg, "msg", subscribers); } -- cgit v1.2.3