aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server/src/main/java/com/juick/server/TelegramBotManager.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/configuration/TelegramConfig.java15
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java13
4 files changed, 18 insertions, 14 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 4cac0dff..3c3fbc9f 100644
--- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
@@ -45,7 +45,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@@ -63,7 +62,6 @@ import static com.juick.formatters.PlainTextFormatter.formatUrl;
/**
* Created by vt on 12/05/16.
*/
-@Component
public class TelegramBotManager implements NotificationListener {
private static final Logger logger = LoggerFactory.getLogger(TelegramBotManager.class);
diff --git a/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java b/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java
index 9c4f64ce..10fd1ab3 100644
--- a/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java
+++ b/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java
@@ -19,6 +19,7 @@ package com.juick.server.api.webhooks;
import com.juick.server.TelegramBotManager;
import org.apache.commons.io.IOUtils;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -35,6 +36,7 @@ import java.nio.charset.StandardCharsets;
*/
@ApiIgnore
@RestController
+@ConditionalOnProperty(name = "telegram_token")
public class TelegramWebhook {
@Inject
private TelegramBotManager telegramBotManager;
diff --git a/juick-server/src/main/java/com/juick/server/configuration/TelegramConfig.java b/juick-server/src/main/java/com/juick/server/configuration/TelegramConfig.java
new file mode 100644
index 00000000..ebd1fd15
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/server/configuration/TelegramConfig.java
@@ -0,0 +1,15 @@
+package com.juick.server.configuration;
+
+import com.juick.server.TelegramBotManager;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConditionalOnProperty(name = "telegram_token")
+public class TelegramConfig {
+ @Bean
+ public TelegramBotManager telegramBotManager() {
+ return new TelegramBotManager();
+ }
+}
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index d700b909..88ce5cf3 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -57,9 +57,6 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.socket.TextMessage;
-import org.springframework.web.socket.client.WebSocketConnectionManager;
-import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import org.w3c.dom.Document;
@@ -142,8 +139,6 @@ public class ServerTests {
@Inject
private TelegramService telegramService;
@Inject
- private TelegramBotManager telegramBotManager;
- @Inject
private CrosspostService crosspostService;
@Inject
private ImagesService imagesService;
@@ -896,14 +891,8 @@ public class ServerTests {
mockMvc.perform(post("/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=1"))
.andExpect(status().isOk());
assertThat(messagesService.getMessage(mid1).getLikes(), is(1));
- }
-
- @Test
- public void telegramTests() {
- jdbcTemplate.update("INSERT INTO telegram(user_id, tg_id) VALUES(?,1)", ugnich.getUid());
- jdbcTemplate.update("INSERT INTO telegram_chats(chat_id) VALUES(1)");
- telegramBotManager.processUpdate("{\"message\":{\"chat\":{\"id\":1},\"text\":\"yo\",\"from\":{\"id\":1,\"username\":\"teleugnich\"}}}");
}
+
@Test
public void lastReadTests() throws Exception {
int mid = messagesService.createMessage(ugnich.getUid(), "to be watched", null, null);