From ec60b63c682f89e87b9de343c944709c9b2fd687 Mon Sep 17 00:00:00 2001 From: sim Date: Tue, 25 Feb 2025 10:20:03 +0100 Subject: [PATCH] Unregister push endpoint onUnregistered --- .../mastodon/helper/PushNotifications.java | 17 +++++++++++++++++ .../mastodon/services/PushServiceImpl.java | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/PushNotifications.java b/app/src/main/java/app/fedilab/android/mastodon/helper/PushNotifications.java index 6721d12d..c996e4ff 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/PushNotifications.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/PushNotifications.java @@ -45,6 +45,23 @@ import retrofit2.converter.gson.GsonConverterFactory; public class PushNotifications { + public static void unregisterPushNotifications(Context context, String slug) { + new Thread(() -> { + String[] slugArray = slug.split("@"); + BaseAccount accountDb = null; + try { + accountDb = new Account(context).getUniqAccount(slugArray[0], slugArray[1]); + } catch (DBException e) { + e.printStackTrace(); + } + + if (accountDb == null) { + return; + } + MastodonNotificationsService mastodonNotificationsService = init(context, accountDb.instance); + mastodonNotificationsService.deletePushsubscription(accountDb.token); + }); + } public static void registerPushNotifications(Context context, PushEndpoint pushEndpoint, String slug) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/services/PushServiceImpl.java b/app/src/main/java/app/fedilab/android/mastodon/services/PushServiceImpl.java index 34633fc7..e00d624e 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/services/PushServiceImpl.java +++ b/app/src/main/java/app/fedilab/android/mastodon/services/PushServiceImpl.java @@ -56,6 +56,13 @@ public class PushServiceImpl extends PushService { } @Override - public void onUnregistered(@NonNull String s) { + public void onUnregistered(@NonNull String slug) { + Context context = getApplicationContext(); + if (context != null) { + synchronized (this) { + PushNotifications + .unregisterPushNotifications(context, slug); + } + } } }