From f2d66113d764f81d58905256a0f74e4f2ebd19f0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 7 Jun 2016 18:56:02 +0300 Subject: telegram: use first name when username is not set --- src/main/java/com/juick/api/TelegramBotHook.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/api/TelegramBotHook.java b/src/main/java/com/juick/api/TelegramBotHook.java index 8c23973e..ccfa2c11 100644 --- a/src/main/java/com/juick/api/TelegramBotHook.java +++ b/src/main/java/com/juick/api/TelegramBotHook.java @@ -149,14 +149,18 @@ public class TelegramBotHook { User user_from = UserQueries.getUserByUID(jdbc, getUser(message.chat().id())).orElse(new User()); logger.info(String.format("got telegram msg %s from juick user %d", message.toString(), user_from.getUID())); List chats = getChats(); + String username = message.from().username(); + if (username == null) { + username = message.from().firstName(); + } if (!chats.contains(message.chat().id())) { addChat(message.chat().id()); - logger.info("added chat with " + message.from().firstName()); - createTelegramUser(message.from().id(), message.from().username()); - telegramSignupNotify(message.from().id().longValue(), UserQueries.getSignUpHashByTelegramID(jdbc, message.from().id().longValue(), message.from().username())); + logger.info("added chat with " + username); + createTelegramUser(message.from().id(), username); + telegramSignupNotify(message.from().id().longValue(), UserQueries.getSignUpHashByTelegramID(jdbc, message.from().id().longValue(), username)); } else { if (user_from.getUID() == 0) { - telegramSignupNotify(message.from().id().longValue(), UserQueries.getSignUpHashByTelegramID(jdbc, message.from().id().longValue(), message.from().username())); + telegramSignupNotify(message.from().id().longValue(), UserQueries.getSignUpHashByTelegramID(jdbc, message.from().id().longValue(), username)); } else if (message.text().equalsIgnoreCase("/login")) { String msg = String.format("Hi, %s!\nTap to log in", user_from.getUName()); String msgUrl = "http://juick.com/login?" + UserQueries.getHashByUID(jdbc, user_from.getUID()); -- cgit v1.2.3