diff options
-rw-r--r-- | juick-core/src/main/java/com/juick/server/PushQueries.java | 28 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/PushComponent.java | 6 |
2 files changed, 9 insertions, 25 deletions
diff --git a/juick-core/src/main/java/com/juick/server/PushQueries.java b/juick-core/src/main/java/com/juick/server/PushQueries.java index f4c98fcf..904b3c0d 100644 --- a/juick-core/src/main/java/com/juick/server/PushQueries.java +++ b/juick-core/src/main/java/com/juick/server/PushQueries.java @@ -4,12 +4,10 @@ */ package com.juick.server; -import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.StringUtils; import java.util.List; -import java.util.Optional; /** * @@ -17,13 +15,8 @@ import java.util.Optional; */ public class PushQueries { - public static Optional<String> getAndroidRegID(JdbcTemplate sql, int uid) { - try { - return Optional.of(sql.queryForObject("SELECT regid FROM android WHERE user_id=?", String.class, uid)); - } catch (EmptyResultDataAccessException e) { - return Optional.empty(); - } - + public static List<String> getAndroidRegID(JdbcTemplate sql, int uid) { + return sql.queryForList("SELECT regid FROM android WHERE user_id=?", String.class, uid); } public static List<String> getAndroidTokens(JdbcTemplate sql, List<Integer> uids) { @@ -31,12 +24,8 @@ public class PushQueries { "ON (users.id=android.user_id) WHERE users.id IN (" + StringUtils.collectionToCommaDelimitedString(uids) + ")", String.class); } - public static Optional<String> getWinPhoneURL(JdbcTemplate sql, int uid) { - try { - return Optional.of(sql.queryForObject("SELECT url FROM winphone WHERE user_id=?", String.class, uid)); - } catch (EmptyResultDataAccessException e) { - return Optional.empty(); - } + public static List<String> getWinPhoneURL(JdbcTemplate sql, int uid) { + return sql.queryForList("SELECT url FROM winphone WHERE user_id=?", String.class, uid); } public static List<String> getWindowsTokens(JdbcTemplate sql, List<Integer> uids) { @@ -44,17 +33,12 @@ public class PushQueries { "ON (users.id=winphone.user_id) WHERE users.id IN (" + StringUtils.collectionToCommaDelimitedString(uids) + ")", String.class); } - public static Optional<String> getAPNSToken(JdbcTemplate sql, int uid) { - try { - return Optional.of(sql.queryForObject("SELECT token from ios WHERE user_id=?", String.class, uid)); - } catch (EmptyResultDataAccessException e) { - return Optional.empty(); - } + public static List<String> getAPNSToken(JdbcTemplate sql, int uid) { + return sql.queryForList("SELECT token from ios WHERE user_id=?", String.class, uid); } public static List<String> getAPNSTokens(JdbcTemplate sql, List<Integer> uids) { return sql.queryForList("SELECT token FROM ios INNER JOIN users " + "ON (users.id=ios.user_id) WHERE users.id IN (" + StringUtils.collectionToCommaDelimitedString(uids) + ")", String.class); } - } diff --git a/juick-www/src/main/java/com/juick/www/PushComponent.java b/juick-www/src/main/java/com/juick/www/PushComponent.java index 67366628..65fbcef0 100644 --- a/juick-www/src/main/java/com/juick/www/PushComponent.java +++ b/juick-www/src/main/java/com/juick/www/PushComponent.java @@ -158,7 +158,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe /*** ANDROID ***/ final List<String> regids = new ArrayList<>(); if (isPM) { - PushQueries.getAndroidRegID(sql, pmTo).ifPresent(regids::add); + regids.addAll(PushQueries.getAndroidRegID(sql, pmTo)); } else { List<Integer> uids = subscribedUsers.stream().map(com.juick.User::getUID).collect(Collectors.toList()); if (uids.size() > 0) { @@ -189,7 +189,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe /*** WinPhone ***/ final List<String> urls = new ArrayList<>(); if (isPM) { - PushQueries.getWinPhoneURL(sql, pmTo).ifPresent(urls::add); + urls.addAll(PushQueries.getWinPhoneURL(sql, pmTo)); } else { List<Integer> uids = subscribedUsers.stream().map(com.juick.User::getUID).collect(Collectors.toList()); if (uids.size() > 0) { @@ -234,7 +234,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe /*** iOS ***/ final List<String> tokens = new ArrayList<>(); if (isPM) { - PushQueries.getAPNSToken(sql, pmTo).ifPresent(tokens::add); + tokens.addAll(PushQueries.getAPNSToken(sql, pmTo)); } else { List<Integer> uids = subscribedUsers.stream().map(com.juick.User::getUID).collect(Collectors.toList()); if (uids.size() > 0) { |