aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
diff options
context:
space:
mode:
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.java28
1 files changed, 22 insertions, 6 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 6987fa27..a44892a4 100644
--- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
@@ -46,6 +46,10 @@ 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;
@@ -64,6 +68,7 @@ import static com.juick.formatters.PlainTextFormatter.formatUrl;
* Created by vt on 12/05/16.
*/
@Component
+@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public class TelegramBotManager {
private static final Logger logger = LoggerFactory.getLogger(TelegramBotManager.class);
@@ -299,7 +304,10 @@ public class TelegramBotManager {
}
});
}
- public void processMessage(com.juick.Message jmsg) {
+ @EventListener
+ @Async
+ public void processMessageEvent(MessageEvent messageEvent) {
+ com.juick.Message jmsg = messageEvent.getMessage();
String msgUrl = formatUrl(jmsg);
if (jmsg.getMid() > 0 && jmsg.getRid() == 0) {
String msg = String.format("[%s](%s) %s", MSG_LINK, msgUrl, formatPost(jmsg, true));
@@ -318,15 +326,23 @@ public class TelegramBotManager {
subscriptionService.getUsersSubscribedToComments(op, jmsg)
).forEach(c -> telegramNotify(c, fmsg, MessageUtils.attachmentUrl(jmsg)));
}
- };
- public void processLike(User liker, com.juick.Message message) {
+ }
+ @EventListener
+ @Async
+ public void processLikeEvent(LikeEvent likeEvent) {
+ User liker = likeEvent.getUser();
+ com.juick.Message message = likeEvent.getMessage();
telegramService.getTelegramIdentifiers(Collections.singletonList(message.getUser()))
.forEach(c -> telegramNotify(c, String.format("%s recommends your post",
MessageUtils.getMarkdownUser(liker)),null));
- };
- public void processSubscribe(User subscriber, User target) {
+ }
+ @EventListener
+ @Async
+ public void processSubscribe(SubscribeEvent subscribeEvent) {
+ User subscriber = subscribeEvent.getUser();
+ User target = subscribeEvent.getToUser();
telegramService.getTelegramIdentifiers(Collections.singletonList(target))
.forEach(c -> telegramNotify(c, String.format("%s subscribed to your blog",
MessageUtils.getMarkdownUser(subscriber)), null));
- };
+ }
}