From 843f182e0a67091f4aff89dee4eb02e57696a4be Mon Sep 17 00:00:00 2001 From: sim Date: Sat, 28 Oct 2023 18:52:58 +0200 Subject: [PATCH] Register new account to UnifiedPush if enabled --- .../android/api/session/AccountSessionManager.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java index 56b411a6ef..cd959a85ae 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java @@ -1,5 +1,7 @@ package org.joinmastodon.android.api.session; +import static org.unifiedpush.android.connector.UnifiedPush.getDistributor; + import android.app.Activity; import android.app.NotificationManager; import android.content.ComponentName; @@ -34,6 +36,7 @@ import org.joinmastodon.android.model.LegacyFilter; import org.joinmastodon.android.model.Instance; import org.joinmastodon.android.model.Token; +import org.unifiedpush.android.connector.UnifiedPush; import java.io.File; import java.io.FileInputStream; @@ -101,6 +104,7 @@ private AccountSessionManager(){ } public void addAccount(Instance instance, Token token, Account self, Application app, AccountActivationInfo activationInfo){ + Context context = MastodonApp.context; instances.put(instance.uri, instance); AccountSession session=new AccountSession(token, self, app, instance.uri, activationInfo==null, activationInfo); sessions.put(session.getID(), session); @@ -113,7 +117,14 @@ public void addAccount(Instance instance, Token token, Account self, Application MastodonAPIController.runInBackground(()->writeInstanceInfoFile(wrapper, instance.uri)); updateMoreInstanceInfo(instance, instance.uri); - if(PushSubscriptionManager.arePushNotificationsAvailable()){ + if (!UnifiedPush.getDistributor(context).isEmpty()) { + UnifiedPush.registerApp( + context, + session.getID(), + new ArrayList<>(), + context.getPackageName() + ); + } else if(PushSubscriptionManager.arePushNotificationsAvailable()){ session.getPushSubscriptionManager().registerAccountForPush(null); } maybeUpdateShortcuts();