aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main/java')
-rw-r--r--juick-api/src/main/java/com/juick/api/TelegramBotManager.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/juick-api/src/main/java/com/juick/api/TelegramBotManager.java b/juick-api/src/main/java/com/juick/api/TelegramBotManager.java
index 098d0876..757dd347 100644
--- a/juick-api/src/main/java/com/juick/api/TelegramBotManager.java
+++ b/juick-api/src/main/java/com/juick/api/TelegramBotManager.java
@@ -21,6 +21,7 @@ import com.juick.server.component.MessageEvent;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
import com.juick.service.TelegramService;
+import com.juick.service.UserService;
import com.pengrad.telegrambot.Callback;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.model.request.ParseMode;
@@ -60,6 +61,8 @@ public class TelegramBotManager implements ApplicationListener<MessageEvent> {
private MessagesService messagesService;
@Inject
private SubscriptionService subscriptionService;
+ @Inject
+ private UserService userService;
private static final String MSG_LINK = "🔗";
@@ -120,8 +123,23 @@ public class TelegramBotManager implements ApplicationListener<MessageEvent> {
@Override
public void onResponse(SendMessage request, SendResponse response) {
if (!response.isOk()) {
- logger.warn("null response, isOk: {}, errorCode: {}, description: {}",
- response.isOk(), response.errorCode(), response.description());
+ if (response.errorCode() == 403) {
+ // remove from anonymous chat
+ telegramService.getChats().stream().filter(c -> c.equals(chatId)).findFirst().ifPresent(
+ d -> {
+ telegramService.deleteChat(d);
+ logger.info("deleted {} chat", d);
+ }
+ );
+ int userId = telegramService.getUser(chatId);
+ if (userId > 0) {
+ telegramService.deleteTelegramUser(chatId.intValue());
+ logger.info("deleted telegram id of @{}", userService.getUserByUID(userId));
+ }
+ } else {
+ logger.warn("error response, isOk: {}, errorCode: {}, description: {}",
+ response.isOk(), response.errorCode(), response.description());
+ }
}
}