aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java7
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java13
2 files changed, 15 insertions, 5 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java
index 14cdfc8f..4e37bfac 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java
@@ -18,6 +18,7 @@
package com.juick.service;
import com.juick.User;
+import org.springframework.dao.DuplicateKeyException;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@@ -36,7 +37,11 @@ public class TelegramServiceImpl extends BaseJdbcService implements TelegramServ
@Transactional
@Override
public boolean addChat(final Long id) {
- return getJdbcTemplate().update("INSERT IGNORE INTO telegram_chats(chat_id) VALUES(?)", id) > 0;
+ try {
+ return getJdbcTemplate().update("INSERT INTO telegram_chats(chat_id) VALUES(?)", id) > 0;
+ } catch (DuplicateKeyException e) {
+ return true;
+ }
}
@Transactional
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 2644b49c..2c335cb2 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
@@ -23,10 +23,7 @@ import com.juick.ExternalToken;
import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
-import com.juick.server.CommandsManager;
-import com.juick.server.EmailManager;
-import com.juick.server.XMPPConnection;
-import com.juick.server.XMPPServer;
+import com.juick.server.*;
import com.juick.server.helpers.AnonymousUser;
import com.juick.server.helpers.CommandResult;
import com.juick.server.helpers.TagStats;
@@ -123,6 +120,8 @@ public class ServerTests {
@Inject
private TelegramService telegramService;
@Inject
+ private TelegramBotManager telegramBotManager;
+ @Inject
private CrosspostService crosspostService;
@Inject
private ImagesService imagesService;
@@ -744,4 +743,10 @@ public class ServerTests {
mockMvc.perform(post("/like?mid=" + freefdMid + "&hash=" + freefdHash))
.andExpect(status().isForbidden());
}
+ @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\"}}}");
+ }
}