diff options
author | Vitaly Takmazov | 2018-03-28 23:33:44 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-28 23:33:44 +0300 |
commit | 024533a558e4827564041bdf5040e51370eece80 (patch) | |
tree | 694a7f765ac31d6170b2422060badbe036cd61c2 /juick-server/src/main/java/com/juick/server/TelegramBotManager.java | |
parent | f6eb11a23ab645b187c5911ec762a3d6ca58140c (diff) |
server: refactor event listeners
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/TelegramBotManager.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/TelegramBotManager.java | 21 |
1 files changed, 6 insertions, 15 deletions
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)) |