From 580ae15af65d595fe142d1a21c336bc873d6292f Mon Sep 17 00:00:00 2001 From: S1m <31284753+p1gp1g@users.noreply.github.com> Date: Tue, 29 Aug 2023 12:22:12 +0200 Subject: [PATCH] Fix unifiedpush (#785) * [UnifiedPush] Register the new endpoint * [UnifiedPush] Get account linked to instance --- .../android/UnifiedPushNotificationReceiver.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/UnifiedPushNotificationReceiver.java b/mastodon/src/main/java/org/joinmastodon/android/UnifiedPushNotificationReceiver.java index 3d7b0d3a9..2fc060c0f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/UnifiedPushNotificationReceiver.java +++ b/mastodon/src/main/java/org/joinmastodon/android/UnifiedPushNotificationReceiver.java @@ -27,9 +27,9 @@ public class UnifiedPushNotificationReceiver extends MessagingReceiver{ public void onNewEndpoint(@NotNull Context context, @NotNull String endpoint, @NotNull String instance) { // Called when a new endpoint be used for sending push messages Log.d(TAG, "onNewEndpoint: New Endpoint " + endpoint + " for "+ instance); - AccountSession account = AccountSessionManager.getInstance().getLastActiveAccount(); + AccountSession account = AccountSessionManager.getInstance().tryGetAccount(instance); if (account != null) - account.getPushSubscriptionManager().registerAccountForPush(null); + account.getPushSubscriptionManager().registerAccountForPush(null, endpoint); } @Override @@ -37,7 +37,7 @@ public class UnifiedPushNotificationReceiver extends MessagingReceiver{ // called when the registration is not possible, eg. no network Log.d(TAG, "onRegistrationFailed: " + instance); //re-register for gcm - AccountSession account = AccountSessionManager.getInstance().getLastActiveAccount(); + AccountSession account = AccountSessionManager.getInstance().tryGetAccount(instance); if (account != null) account.getPushSubscriptionManager().registerAccountForPush(null); } @@ -47,7 +47,7 @@ public class UnifiedPushNotificationReceiver extends MessagingReceiver{ // called when this application is unregistered from receiving push messages Log.d(TAG, "onUnregistered: " + instance); //re-register for gcm - AccountSession account = AccountSessionManager.getInstance().getLastActiveAccount(); + AccountSession account = AccountSessionManager.getInstance().tryGetAccount(instance); if (account != null) account.getPushSubscriptionManager().registerAccountForPush(null); } @@ -55,7 +55,10 @@ public class UnifiedPushNotificationReceiver extends MessagingReceiver{ @Override public void onMessage(@NotNull Context context, @NotNull byte[] message, @NotNull String instance) { // Called when a new message is received. The message contains the full POST body of the push message - AccountSession account = AccountSessionManager.getInstance().getAccount(instance); + AccountSession account = AccountSessionManager.getInstance().tryGetAccount(instance); + + if (account == null) + return; //this is stupid // Mastodon stores the info to decrypt the message in the HTTP headers, which are not accessible in UnifiedPush,