diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-07-01 08:42:54 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-07-01 08:42:54 +0200 |
commit | 037932dc02ff27cd452cd37378aa66d0bfcd5d7f (patch) | |
tree | 4bb9f580df46f1b2f3520a58d470d9849cec555e /src/main/java/de/pixart/messenger/services/XmppConnectionService.java | |
parent | 66a57e01292d576dc7df6480ad8f3fa9090094d5 (diff) |
attempt to unregister when receiving push for channel no longer joined
when receiving a FCM push message for a channel the user is no longer in (this can happen when the disable command failed) an attempt will be made to explicitly unregister from the app server (which in turn will then send item-not-found on next push)
Diffstat (limited to 'src/main/java/de/pixart/messenger/services/XmppConnectionService.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 9d9be2a5b..ff96f255d 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -609,6 +609,7 @@ public class XmppConnectionService extends Service { toggleForegroundService(true); } String pushedAccountHash = null; + String pushedChannelHash = null; boolean interactive = false; if (action != null) { final String uuid = intent.getStringExtra("uuid"); @@ -721,6 +722,7 @@ public class XmppConnectionService extends Service { break; case ACTION_FCM_MESSAGE_RECEIVED: pushedAccountHash = intent.getStringExtra("account"); + pushedChannelHash = intent.getStringExtra("channel"); Log.d(Config.LOGTAG, "push message arrived in service. account=" + pushedAccountHash); break; case Intent.ACTION_SEND: @@ -734,13 +736,18 @@ public class XmppConnectionService extends Service { synchronized (this) { WakeLockHelper.acquire(wakeLock); boolean pingNow = ConnectivityManager.CONNECTIVITY_ACTION.equals(action) || (Config.POST_CONNECTIVITY_CHANGE_PING_INTERVAL > 0 && ACTION_POST_CONNECTIVITY_CHANGE.equals(action)); - HashSet<Account> pingCandidates = new HashSet<>(); + final HashSet<Account> pingCandidates = new HashSet<>(); + final String androidId = PhoneHelper.getAndroidId(this); for (Account account : accounts) { + final boolean pushWasMeantForThisAccount = CryptoHelper.getAccountFingerprint(account, androidId).equals(pushedAccountHash); pingNow |= processAccountState(account, interactive, "ui".equals(action), - CryptoHelper.getAccountFingerprint(account, PhoneHelper.getAndroidId(this)).equals(pushedAccountHash), + pushWasMeantForThisAccount, pingCandidates); + if (pushWasMeantForThisAccount && pushedChannelHash != null) { + checkMucStillJoined(account, pushedAccountHash, androidId); + } } if (pingNow) { for (Account account : pingCandidates) { @@ -876,6 +883,20 @@ public class XmppConnectionService extends Service { editor.apply(); } + private void checkMucStillJoined(final Account account, final String hash, final String androidId) { + for (final Conversation conversation : this.conversations) { + if (conversation.getAccount() == account && conversation.getMode() == Conversational.MODE_MULTI) { + Jid jid = conversation.getJid().asBareJid(); + final String currentHash = CryptoHelper.getFingerprint(jid, androidId); + if (currentHash.equals(hash)) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received cloud push notification for MUC " + jid); + return; + } + } + } + mPushManagementService.unregisterChannel(account, hash); + } + public void reinitializeMuclumbusService() { mChannelDiscoveryService.initializeMuclumbusService(); } @@ -914,7 +935,7 @@ public class XmppConnectionService extends Service { } @Override - public void userInputRequried(PendingIntent pi, Message object) { + public void userInputRequired(PendingIntent pi, Message object) { } }); |