aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------deps/com.juick.server10
-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
-rw-r--r--src/test/java/com/juick/tests/ApiTests.java4
5 files changed, 15 insertions, 15 deletions
diff --git a/deps/com.juick.server b/deps/com.juick.server
-Subproject a41109795f6f6a3803d52606df9bd1a0da641f4
+Subproject b633724c75081eb05b70ceee74636f19576a448
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) {
diff --git a/src/test/java/com/juick/tests/ApiTests.java b/src/test/java/com/juick/tests/ApiTests.java
index 5bd90509..2bae183d 100644
--- a/src/test/java/com/juick/tests/ApiTests.java
+++ b/src/test/java/com/juick/tests/ApiTests.java
@@ -94,7 +94,7 @@ public class ApiTests {
@Test
public void messageTests() {
int user_id = UserQueries.createUser(jdbc, "me", "secret");
- User user = UserQueries.getUserByUID(jdbc, user_id);
+ User user = UserQueries.getUserByUID(jdbc, user_id).orElse(new User());
Assert.assertEquals("it should be me", "me", user.getUName());
int mid = MessagesQueries.createMessage(jdbc, user_id, "yo", null, new ArrayList<>());
Message msg = MessagesQueries.getMessage(jdbc, mid);
@@ -113,7 +113,7 @@ public class ApiTests {
Message msg2 = MessagesQueries.getMessage(jdbc, mid2);
org.junit.Assert.assertEquals(1, msg2.Tags.size());
int ugnich_id = UserQueries.createUser(jdbc, "ugnich", "x");
- User ugnich = UserQueries.getUserByUID(jdbc, ugnich_id);
+ User ugnich = UserQueries.getUserByUID(jdbc, ugnich_id).orElse(new User());
int rid = MessagesQueries.createReply(jdbc, msg2.getMID(), 0, ugnich.getUID(), "bla-bla", null);
org.junit.Assert.assertEquals(1, rid);
Message msg3 = MessagesQueries.getMessage(jdbc, mid2);