diff options
Diffstat (limited to 'src/main/java/com/juick/TelegramBotManager.java')
-rw-r--r-- | src/main/java/com/juick/TelegramBotManager.java | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/main/java/com/juick/TelegramBotManager.java b/src/main/java/com/juick/TelegramBotManager.java index b68658ae..b92704a0 100644 --- a/src/main/java/com/juick/TelegramBotManager.java +++ b/src/main/java/com/juick/TelegramBotManager.java @@ -136,7 +136,7 @@ public class TelegramBotManager implements NotificationListener { logger.error("error parsing telegram update: {}", update); return; } - User user_from = userService.getUserByUID(telegramService.getUser(message.chat().id())).orElse(AnonymousUser.INSTANCE); + User user_from = userService.getUserByTelegramId(message.chat().id()).orElse(AnonymousUser.INSTANCE); logger.info("Found juick user {}", user_from.getUid()); Optional<Pair<Integer, Integer>> originalMessageData = messagesService.findMessageByProperty("durovId", String.valueOf(message.messageId())); @@ -157,7 +157,7 @@ public class TelegramBotManager implements NotificationListener { telegramNotify(message.chat().id(), "Error updating message", new com.juick.model.Message()); } } else { - User user_from = userService.getUserByUID(telegramService.getUser(message.chat().id())).orElse(AnonymousUser.INSTANCE); + User user_from = userService.getUserByTelegramId(message.chat().id()).orElse(AnonymousUser.INSTANCE); logger.info("Found juick user {}", user_from.getUid()); String username = message.from().username(); @@ -355,7 +355,7 @@ public class TelegramBotManager implements NotificationListener { } private void processTelegramResponse(Long chatId, SendResponse response, com.juick.model.Message source) { - int userId = telegramService.getUser(chatId); + var user = userService.getUserByTelegramId(chatId).orElse(AnonymousUser.INSTANCE); if (!response.isOk()) { if (response.errorCode() == 403) { // remove from anonymous users @@ -365,11 +365,9 @@ public class TelegramBotManager implements NotificationListener { logger.info("deleted {} chat", d); } ); - if (userId > 0) { - User userToDelete = userService.getUserByUID(userId) - .orElseThrow(IllegalStateException::new); - boolean status = telegramService.deleteTelegramUser(userToDelete.getUid()); - logger.info("deleting telegram id of @{} : {}", userToDelete.getName(), status); + if (!user.isAnonymous()) { + boolean status = telegramService.deleteTelegramUser(user.getUid()); + logger.info("deleting telegram id of @{} : {}", user.getName(), status); } } else { logger.warn("error response, isOk: {}, errorCode: {}, description: {}", @@ -377,9 +375,7 @@ public class TelegramBotManager implements NotificationListener { } } else { if (MessageUtils.isReply(source)) { - messagesService.setLastReadComment(userService.getUserByUID(userId) - .orElseThrow(IllegalStateException::new), source.getMid(), source.getRid()); - User user = userService.getUserByUID(userId).orElseThrow(IllegalStateException::new); + messagesService.setLastReadComment(user, source.getMid(), source.getRid()); userService.updateLastSeen(user); applicationEventPublisher.publishEvent( new SystemEvent(this, SystemActivity.read(user, source))); @@ -453,7 +449,7 @@ public class TelegramBotManager implements NotificationListener { users.forEach(c -> telegramNotify(c, msg, jmsg)); // anonymous - chats.stream().filter(u -> telegramService.getUser(u) == 0).forEach(c -> telegramNotify(c, msg, jmsg)); + chats.stream().filter(u -> userService.getUserByTelegramId(u).isPresent()).forEach(c -> telegramNotify(c, msg, jmsg)); } } |