aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-06-07 18:56:02 +0300
committerGravatar Vitaly Takmazov2016-06-07 18:56:02 +0300
commitf2d66113d764f81d58905256a0f74e4f2ebd19f0 (patch)
treed32702515c129b919270140c1a58310dd7a0746d /src/main/java/com/juick
parent740fa16a06f9aeae839ffda6344c663a258d8e85 (diff)
telegram: use first name when username is not set
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/api/TelegramBotHook.java12
1 files changed, 8 insertions, 4 deletions
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<Long> 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());