aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/configuration
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-22 12:09:35 +0300
committerGravatar Vitaly Takmazov2018-03-22 12:09:35 +0300
commit17e72bb8c612e34ec3aac56dd906bd9fefc2bc7c (patch)
treef84400450dea9a77ef741062ddf71bbb0535d6b4 /juick-server/src/main/java/com/juick/server/configuration
parent679731ebbea77a7d361a53bb8280d1869c2a95d3 (diff)
server: event listeners are beans
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/configuration')
-rw-r--r--juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java3
-rw-r--r--juick-server/src/main/java/com/juick/server/configuration/EventsConfiguration.java39
2 files changed, 41 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java b/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java
index 1ca0130f..8d533f05 100644
--- a/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java
+++ b/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java
@@ -53,7 +53,8 @@ import java.util.Collections;
@EnableSwagger2
@EnableScheduling
@EnableWebSocket
-@Import({ApiSecurityConfig.class, BaseWebConfiguration.class, DataConfiguration.class, StorageConfiguration.class})
+@Import({ApiSecurityConfig.class, BaseWebConfiguration.class, DataConfiguration.class, StorageConfiguration.class,
+EventsConfiguration.class})
@ComponentScan(basePackages = "com.juick.server")
public class ApiAppConfiguration implements WebMvcConfigurer, WebSocketConfigurer {
@Inject
diff --git a/juick-server/src/main/java/com/juick/server/configuration/EventsConfiguration.java b/juick-server/src/main/java/com/juick/server/configuration/EventsConfiguration.java
new file mode 100644
index 00000000..4edc9dde
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/server/configuration/EventsConfiguration.java
@@ -0,0 +1,39 @@
+package com.juick.server.configuration;
+
+import com.juick.server.TelegramBotManager;
+import com.juick.server.XMPPBot;
+import com.juick.server.component.LikeEvent;
+import com.juick.server.component.MessageEvent;
+import com.juick.server.component.SubscribeEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.inject.Inject;
+
+@Configuration
+public class EventsConfiguration {
+ @Inject
+ private TelegramBotManager telegramBotManager;
+ @Inject
+ private XMPPBot bot;
+ @Bean
+ ApplicationListener<MessageEvent> messageListener() {
+ return event -> {
+ telegramBotManager.processMessage(event.getMessage());
+ bot.processMessage(event.getMessage());
+ };
+ }
+ @Bean
+ ApplicationListener<LikeEvent> likeListener() {
+ return event -> {
+ telegramBotManager.processLike(event.getUser(), event.getMessage());
+ };
+ }
+ @Bean
+ ApplicationListener<SubscribeEvent> subscribeListener() {
+ return event -> {
+ telegramBotManager.processSubscribe(event.getUser(), event.getToUser());
+ };
+ }
+}