Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Fix: registering multi account for UnifiedPush #907

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ private void onUnifiedPushClick(){
return;
}

UnifiedPush.unregisterApp(
getContext(),
accountID
);

//re-register to fcm
AccountSessionManager.getInstance().getAccount(accountID).getPushSubscriptionManager().registerAccountForPush(getPushSubscription());
for (AccountSession accountSession : AccountSessionManager.getInstance().getLoggedInAccounts()) {
UnifiedPush.unregisterApp(
getContext(),
accountSession.getID()
);

//re-register to fcm
accountSession.getPushSubscriptionManager().registerAccountForPush(getPushSubscription());
}
unifiedPushItem.toggle();
rebindItem(unifiedPushItem);
}
Expand All @@ -350,12 +352,14 @@ private void showUnifiedPushRegisterDialog(List<String> distributors){
(dialog, which)->{
String userDistrib = distributors.get(which);
UnifiedPush.saveDistributor(getContext(), userDistrib);
UnifiedPush.registerApp(
getContext(),
accountID,
new ArrayList<>(),
getContext().getPackageName()
);
for (AccountSession accountSession : AccountSessionManager.getInstance().getLoggedInAccounts()){
UnifiedPush.registerApp(
getContext(),
accountSession.getID(),
new ArrayList<>(),
getContext().getPackageName()
);
}
unifiedPushItem.toggle();
rebindItem(unifiedPushItem);
}).setOnCancelListener(d->rebindItem(unifiedPushItem)).show();
Expand Down