From 17e72bb8c612e34ec3aac56dd906bd9fefc2bc7c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 22 Mar 2018 12:09:35 +0300 Subject: server: event listeners are beans --- .../server/configuration/ApiAppConfiguration.java | 3 +- .../server/configuration/EventsConfiguration.java | 39 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 juick-server/src/main/java/com/juick/server/configuration/EventsConfiguration.java (limited to 'juick-server/src/main/java/com/juick/server/configuration') 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 1ca0130f1..8d533f05f 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 000000000..4edc9dde4 --- /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 messageListener() { + return event -> { + telegramBotManager.processMessage(event.getMessage()); + bot.processMessage(event.getMessage()); + }; + } + @Bean + ApplicationListener likeListener() { + return event -> { + telegramBotManager.processLike(event.getUser(), event.getMessage()); + }; + } + @Bean + ApplicationListener subscribeListener() { + return event -> { + telegramBotManager.processSubscribe(event.getUser(), event.getToUser()); + }; + } +} -- cgit v1.2.3