From f51f2a11978cdf9fe0fb483220b92bad1933a217 Mon Sep 17 00:00:00 2001 From: FineFindus <63370021+FineFindus@users.noreply.github.com> Date: Thu, 7 Sep 2023 18:28:32 +0200 Subject: [PATCH] fix: use random account id in notification endpoint (#806) Closes https://github.com/sk22/megalodon/issues/803. This was due to registering with the actual accounId, whilst saving a random one. Once receiving a notification, the id could not be found. --- .../android/api/PushSubscriptionManager.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java b/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java index c1253ac3c..046c55531 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java @@ -130,12 +130,11 @@ public class PushSubscriptionManager{ return; } - String endpoint = "https://app.joinmastodon.org/relay-to/fcm/"+deviceToken+"/"+accountID; + String endpoint = "https://app.joinmastodon.org/relay-to/fcm/"+deviceToken+"/"; registerAccountForPush(subscription, endpoint); } public void registerAccountForPush(PushSubscription subscription, String endpoint){ - MastodonAPIController.runInBackground(()->{ Log.d(TAG, "registerAccountForPush: started for "+accountID); String encodedPublicKey, encodedAuthKey, pushAccountID; @@ -164,7 +163,13 @@ public class PushSubscriptionManager{ Log.e(TAG, "registerAccountForPush: error generating encryption key", e); return; } - new RegisterForPushNotifications(endpoint, + + //work-around for adding the randomAccountId + String newEndpoint = endpoint; + if (endpoint.startsWith("https://app.joinmastodon.org/relay-to/fcm/")) + newEndpoint += pushAccountID; + + new RegisterForPushNotifications(newEndpoint, encodedPublicKey, encodedAuthKey, subscription==null ? PushSubscription.Alerts.ofAll() : subscription.alerts,