aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/juick/api/Messages.java2
-rw-r--r--src/main/java/com/juick/api/PM.java2
-rw-r--r--src/main/java/com/juick/api/TelegramBotHook.java12
3 files changed, 8 insertions, 8 deletions
diff --git a/src/main/java/com/juick/api/Messages.java b/src/main/java/com/juick/api/Messages.java
index d86193f1..18c868f4 100644
--- a/src/main/java/com/juick/api/Messages.java
+++ b/src/main/java/com/juick/api/Messages.java
@@ -165,7 +165,7 @@ public class Messages {
msg.from = new JID("juick", "juick.com", null);
msg.to = new JID(null, "crosspost.juick.com", null);
JuickMessage jmsg = new JuickMessage(m);
- jmsg.setUser(UserQueries.getUserByUID(sql, 11574));
+ jmsg.setUser(UserQueries.getUserByUID(sql, 11574).get());
msg.childs.add(jmsg);
msg.to.Username = "twitter";
diff --git a/src/main/java/com/juick/api/PM.java b/src/main/java/com/juick/api/PM.java
index 3ca9eada..c7123d0a 100644
--- a/src/main/java/com/juick/api/PM.java
+++ b/src/main/java/com/juick/api/PM.java
@@ -77,7 +77,7 @@ public class PM {
msg.from = new JID("juick", "juick.com", null);
msg.to = new JID(Integer.toString(uid), "push.juick.com", null);
JuickMessage jmsg = new JuickMessage();
- jmsg.setUser(UserQueries.getUserByUID(sql, vuid));
+ jmsg.setUser(UserQueries.getUserByUID(sql, vuid).get());
jmsg.setText(body);
msg.childs.add(jmsg);
xmpp.send(msg);
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) {