From 024533a558e4827564041bdf5040e51370eece80 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 28 Mar 2018 23:33:44 +0300 Subject: server: refactor event listeners --- .../java/com/juick/server/TelegramBotManager.java | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'juick-server/src/main/java/com/juick/server/TelegramBotManager.java') 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 1aa7273d..1ea71ebb 100644 --- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java +++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java @@ -45,16 +45,10 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationListener; -import org.springframework.context.annotation.Scope; -import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; -import javax.annotation.Nonnull; import javax.annotation.PostConstruct; import javax.inject.Inject; import java.io.IOException; @@ -68,8 +62,7 @@ import static com.juick.formatters.PlainTextFormatter.formatUrl; * Created by vt on 12/05/16. */ @Component -@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS) -public class TelegramBotManager { +public class TelegramBotManager implements NotificationListener { private static final Logger logger = LoggerFactory.getLogger(TelegramBotManager.class); private TelegramBot bot; @@ -304,8 +297,7 @@ public class TelegramBotManager { } }); } - @EventListener - @Async + @Override public void processMessageEvent(MessageEvent messageEvent) { com.juick.Message jmsg = messageEvent.getMessage(); String msgUrl = formatUrl(jmsg); @@ -332,18 +324,17 @@ public class TelegramBotManager { chats.stream().filter(u -> telegramService.getUser(u) == 0).forEach(c -> telegramNotify(c, msg, MessageUtils.attachmentUrl(jmsg))); } } - @EventListener - @Async + @Override public void processLikeEvent(LikeEvent likeEvent) { User liker = likeEvent.getUser(); com.juick.Message message = likeEvent.getMessage(); + logger.info("Like received in tg listener"); telegramService.getTelegramIdentifiers(Collections.singletonList(message.getUser())) .forEach(c -> telegramNotify(c, String.format("%s recommends your [post](%s)", MessageUtils.getMarkdownUser(liker), formatUrl(message)),null)); } - @EventListener - @Async - public void processSubscribe(SubscribeEvent subscribeEvent) { + @Override + public void processSubscribeEvent(SubscribeEvent subscribeEvent) { User subscriber = subscribeEvent.getUser(); User target = subscribeEvent.getToUser(); telegramService.getTelegramIdentifiers(Collections.singletonList(target)) -- cgit v1.2.3