From d556681a773c8bd695ca58c325a132b3de2c0c44 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 12 Jul 2016 09:35:14 +0300 Subject: Push: using all user tokens for PMs --- .../main/java/com/juick/server/PushQueries.java | 28 +++++----------------- .../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 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 getAndroidRegID(JdbcTemplate sql, int uid) { + return sql.queryForList("SELECT regid FROM android WHERE user_id=?", String.class, uid); } public static List getAndroidTokens(JdbcTemplate sql, List 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 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 getWinPhoneURL(JdbcTemplate sql, int uid) { + return sql.queryForList("SELECT url FROM winphone WHERE user_id=?", String.class, uid); } public static List getWindowsTokens(JdbcTemplate sql, List 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 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 getAPNSToken(JdbcTemplate sql, int uid) { + return sql.queryForList("SELECT token from ios WHERE user_id=?", String.class, uid); } public static List getAPNSTokens(JdbcTemplate sql, List 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 regids = new ArrayList<>(); if (isPM) { - PushQueries.getAndroidRegID(sql, pmTo).ifPresent(regids::add); + regids.addAll(PushQueries.getAndroidRegID(sql, pmTo)); } else { List 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 urls = new ArrayList<>(); if (isPM) { - PushQueries.getWinPhoneURL(sql, pmTo).ifPresent(urls::add); + urls.addAll(PushQueries.getWinPhoneURL(sql, pmTo)); } else { List 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 tokens = new ArrayList<>(); if (isPM) { - PushQueries.getAPNSToken(sql, pmTo).ifPresent(tokens::add); + tokens.addAll(PushQueries.getAPNSToken(sql, pmTo)); } else { List uids = subscribedUsers.stream().map(com.juick.User::getUID).collect(Collectors.toList()); if (uids.size() > 0) { -- cgit v1.2.3