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

Commit

Permalink
Register new account to UnifiedPush if enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Oct 28, 2023
1 parent 1accbe1 commit 843f182
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit 843f182

Please sign in to comment.