aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-01-17 13:43:53 +0300
committerGravatar Vitaly Takmazov2018-01-17 13:43:53 +0300
commitf641853214daace2a73503f3a78e1f9ba29fd386 (patch)
tree0eeeab99a0512d98198289714fa06edf9e5cef9a /juick-api/src/main/java/com/juick
parent62df283157ff32dded77e833fbd0f4e3007acbbe (diff)
api: delete telegram id when got 403
Diffstat (limited to 'juick-api/src/main/java/com/juick')
-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());
+ }
}
}