diff options
author | Vitaly Takmazov | 2015-12-30 13:58:27 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2015-12-30 13:58:27 +0300 |
commit | 3977558af5ec48fd84ecb79d3acad3f13763e154 (patch) | |
tree | c9af7290ab29f8bf49190bac6d3bbfb953284717 /src/main/java/com/juick | |
parent | 9f73b893abc93c92895453bc8b91c008aea75b63 (diff) |
fix push flow, WIP
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r-- | src/main/java/com/juick/PushComponent.java | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/src/main/java/com/juick/PushComponent.java b/src/main/java/com/juick/PushComponent.java index 0f806827..2102f77d 100644 --- a/src/main/java/com/juick/PushComponent.java +++ b/src/main/java/com/juick/PushComponent.java @@ -23,6 +23,7 @@ import com.google.android.gcm.server.Result; import com.google.android.gcm.server.Sender; import com.juick.json.MessageSerializer; import com.juick.server.PushQueries; +import com.juick.server.MessagesQueries; import com.juick.xmpp.JID; import com.juick.xmpp.Message.MessageListener; import com.juick.xmpp.utils.XmlUtils; @@ -163,19 +164,40 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe if (jmsg == null) { return; } + logger.info("Message to push: " + msg.toString()); - int uid_to = jmsg.User.UID; + boolean isPM = jmsg.MID == 0; + boolean isReply = jmsg.RID > 0; + int senderID = 0, recipientID = 0; + // reply pushed to original sender + if (isReply) { + com.juick.Message op = MessagesQueries.getMessage(sql, jmsg.MID); + senderID = op.User.UID; + // do not notify self + if (jmsg.User.UID == op.User.UID) { + return; + } + } + if (isPM) { + // PM + try { + recipientID = Integer.parseInt(msg.to.Username); + } catch (NumberFormatException e) { + logger.info("Wrong PM recipient: " + msg.to.Username); + return; + } + } /*** ANDROID ***/ ArrayList<String> regids; - if (uid_to > 0) { + if (isPM) { regids = new ArrayList<String>(); - String targetId = PushQueries.getAndroidRegID(sql, uid_to); + String targetId = PushQueries.getAndroidRegID(sql, recipientID); if (targetId != null && !targetId.isEmpty()) { regids.add(targetId); } } else { - regids = PushQueries.getAndroidSubscribers(sql, jmsg.User.UID); + regids = PushQueries.getAndroidSubscribers(sql, senderID); } if (!regids.isEmpty()) { @@ -198,14 +220,14 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe /*** WinPhone ***/ ArrayList<String> urls; - if (uid_to > 0) { + if (isPM) { urls = new ArrayList<String>(); - String targetURL = PushQueries.getWinPhoneURL(sql, uid_to); + String targetURL = PushQueries.getWinPhoneURL(sql, recipientID); if (targetURL != null && !targetURL.isEmpty()) { urls.add(targetURL); } } else { - urls = PushQueries.getWinPhoneSubscribers(sql, jmsg.User.UID); + urls = PushQueries.getWinPhoneSubscribers(sql, senderID); } if (!urls.isEmpty()) { @@ -213,12 +235,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe if (!jmsg.Tags.isEmpty()) { text1 += ":" + XmlUtils.escape(jmsg.getTagsString()); } - String text2; - if (jmsg.Text.length() > 250) { - text2 = XmlUtils.escape(jmsg.Text.substring(0, 255)) + "..."; - } else { - text2 = XmlUtils.escape(jmsg.Text); - } + String text2 = XmlUtils.escape(jmsg.Text); String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<toast>" + "<visual>" @@ -242,14 +259,14 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe /*** iOS ***/ List<String> tokens; - if (uid_to > 0) { + if (isPM) { tokens = new ArrayList<String>(); - String targetToken = PushQueries.getAPNSToken(sql, uid_to); + String targetToken = PushQueries.getAPNSToken(sql, recipientID); if (targetToken != null && !targetToken.isEmpty()) { tokens.add(targetToken); } } else { - tokens = PushQueries.getAPNSSubscribers(sql, jmsg.User.UID); + tokens = PushQueries.getAPNSSubscribers(sql, senderID); } if (!tokens.isEmpty()) { ApnsService service = APNS.newService().withCert("/etc/juick/ios.p12", "juick") |