diff options
Diffstat (limited to 'juick-notifications/src/main/java/com/juick/components')
-rw-r--r-- | juick-notifications/src/main/java/com/juick/components/Notifications.java | 11 | ||||
-rw-r--r-- | juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java | 5 |
2 files changed, 8 insertions, 8 deletions
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 5f6630fb..ce89de32 100644 --- a/juick-notifications/src/main/java/com/juick/components/Notifications.java +++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java @@ -22,7 +22,6 @@ import com.google.android.gcm.server.*; import com.juick.ExternalToken; import com.juick.User; import com.juick.formatters.PlainTextFormatter; -import com.juick.server.component.MessageEvent; import com.juick.util.MessageUtils; import com.turo.pushy.apns.ApnsClient; import com.turo.pushy.apns.PushNotificationResponse; @@ -33,7 +32,6 @@ import org.apache.commons.text.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationListener; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Component; @@ -41,6 +39,7 @@ import org.springframework.web.client.RestTemplate; import javax.annotation.Nonnull; import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.inject.Inject; import java.io.IOException; import java.util.*; @@ -52,7 +51,7 @@ import java.util.stream.Collectors; * @author Ugnich Anton */ @Component -public class Notifications implements NotificationClientListener, AutoCloseable, ApplicationListener<MessageEvent> { +public class Notifications implements NotificationClientListener { private static Logger logger = LoggerFactory.getLogger(Notifications.class); @Inject @@ -78,9 +77,7 @@ public class Notifications implements NotificationClientListener, AutoCloseable, public void init() throws IOException { mpnsClient.setListener(this); } - @Override - public void onApplicationEvent(@Nonnull MessageEvent event) { - com.juick.Message jmsg = event.getMessage(); + public void messageReceived(@Nonnull com.juick.Message jmsg) { User pmTo = jmsg.getTo(); final List<User> users = new ArrayList<>(); @@ -205,7 +202,7 @@ public class Notifications implements NotificationClientListener, AutoCloseable, } } - @Override + @PreDestroy public void close() throws Exception { apns.close(); diff --git a/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java b/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java index eecddc70..0f62e702 100644 --- a/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java +++ b/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java @@ -1,6 +1,7 @@ package com.juick.components.service; import com.fasterxml.jackson.databind.ObjectMapper; +import com.juick.components.Notifications; import com.juick.server.component.DisconnectedEvent; import com.juick.server.component.MessageEvent; import org.slf4j.Logger; @@ -26,6 +27,8 @@ public class JuickServerComponent extends TextWebSocketHandler { @Inject private ApplicationEventPublisher applicationEventPublisher; @Inject + private Notifications notifications; + @Inject private ObjectMapper jsonMapper; private WebSocketSession session; @@ -54,7 +57,7 @@ public class JuickServerComponent extends TextWebSocketHandler { if (logger.isInfoEnabled()) // prevent writeValueAsString execution if logger disabled logger.info("got jmsg: {}", jsonMapper.writeValueAsString(jmsg)); if (!closeFlag.get()) { - applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg)); + notifications.messageReceived(jmsg); } } |