aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/TelegramBotManager.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-11 06:57:36 +0300
committerGravatar Vitaly Takmazov2023-01-11 06:57:36 +0300
commit6c3663df82c7e29febc0aebd51717184df7da09c (patch)
tree6b987923e6b28081352f67687306a5c410a2c738 /src/main/java/com/juick/TelegramBotManager.java
parente96411433898f940b22257affba284787e2783cd (diff)
Social login refactoring: set cookie after login
Diffstat (limited to 'src/main/java/com/juick/TelegramBotManager.java')
-rw-r--r--src/main/java/com/juick/TelegramBotManager.java20
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));
}
}