aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/api/TelegramBotHook.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-05-19 23:24:22 +0300
committerGravatar Vitaly Takmazov2016-05-19 23:24:22 +0300
commit7fb8cdfb02c24c265a081499c858f3aca1efbb2b (patch)
tree87f8764cf0baf4d3dc6de7b2d19fda827a16b1cb /src/main/java/com/juick/api/TelegramBotHook.java
parentce8cef088e7fa1b31a5aa59bb3111600863bc432 (diff)
update server api and try to fix anonymous chats
Diffstat (limited to 'src/main/java/com/juick/api/TelegramBotHook.java')
-rw-r--r--src/main/java/com/juick/api/TelegramBotHook.java12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/main/java/com/juick/api/TelegramBotHook.java b/src/main/java/com/juick/api/TelegramBotHook.java
index 6b1f946c..8bbf0e33 100644
--- a/src/main/java/com/juick/api/TelegramBotHook.java
+++ b/src/main/java/com/juick/api/TelegramBotHook.java
@@ -76,7 +76,7 @@ public class TelegramBotHook {
String msgUrl = "https://juick.com/" + jmsg.getMID();
users.stream().forEach(c -> telegramNotify(c, msg, msgUrl));
// anonymous
- chats.stream().filter(u -> !getUser(u).isPresent()).forEach(c -> telegramNotify(c, msg, msgUrl));
+ chats.stream().filter(u -> getUser(u) == 0).forEach(c -> telegramNotify(c, msg, msgUrl));
}
});
ws.connect();
@@ -146,7 +146,7 @@ public class TelegramBotHook {
public void doPost(HttpServletRequest request) throws IOException {
try (BufferedReader reader = request.getReader()) {
Message message = BotUtils.parseUpdate(reader).message();
- User user_from = getUser(message.chat().id()).orElse(new User());
+ 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();
if (!chats.contains(message.chat().id())) {
@@ -192,12 +192,12 @@ public class TelegramBotHook {
return jdbc.update("INSERT INTO telegram(tg_id, tg_name, loginhash) VALUES(?,?,?)",
tgID, tgName, UUID.randomUUID().toString()) > 0;
}
- private Optional<User> getUser(long tgId) {
+ private int getUser(long tgId) {
try {
- return Optional.of(jdbc.queryForObject("SELECT id, nick, banned FROM users INNER JOIN telegram " +
- "ON telegram.user_id = users.id WHERE telegram.tg_id=?", new UserQueries.UserMapper(), tgId));
+ return jdbc.queryForObject("SELECT id, nick, banned FROM users INNER JOIN telegram " +
+ "ON telegram.user_id = users.id WHERE telegram.tg_id=?", Integer.class, tgId);
} catch (EmptyResultDataAccessException e) {
- return Optional.empty();
+ return 0;
}
}
private List<Long> getSubscribers(int uid) {