Commit b26b10c6 authored by sim's avatar sim
Browse files

Always register push endpoint

The mastodon server may remove the endpoint if the push server
has been in an inconsistent state (returning a 404), or the endpoint
may not be restored after a backup, or other edge cases
parent f93533f9
Loading
Loading
Loading
Loading
+5 −19
Original line number Diff line number Diff line
package app.fedilab.android.mastodon.services;

import static app.fedilab.android.mastodon.helper.Helper.TAG;


import android.content.SharedPreferences;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;


import org.unifiedpush.android.connector.FailedReason;
import org.unifiedpush.android.connector.PushService;
import org.unifiedpush.android.connector.data.PushEndpoint;
import org.unifiedpush.android.connector.data.PushMessage;

import app.fedilab.android.R;

import app.fedilab.android.mastodon.helper.NotificationsHelper;
import app.fedilab.android.mastodon.helper.PushNotifications;

@@ -49,17 +41,11 @@ public class PushServiceImpl extends PushService {

    @Override
    public void onNewEndpoint(@NonNull PushEndpoint pushEndpoint, @NonNull String slug) {
        if (getApplicationContext() != null) {
        Context context = getApplicationContext();
        if (context != null) {
            synchronized (this) {
                SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                String storedEnpoint = sharedpreferences.getString(getApplicationContext().getString(R.string.SET_STORED_ENDPOINT) + slug, null);
                if (storedEnpoint == null || !storedEnpoint.equals(pushEndpoint.getUrl())) {
                PushNotifications
                            .registerPushNotifications(getApplicationContext(), pushEndpoint, slug);
                    SharedPreferences.Editor editor = sharedpreferences.edit();
                    editor.putString(getApplicationContext().getString(R.string.SET_STORED_ENDPOINT) + slug, pushEndpoint.getUrl());
                    editor.commit();
                }
                        .registerPushNotifications(context, pushEndpoint, slug);
            }
        }
    }
+0 −1
Original line number Diff line number Diff line
@@ -1169,7 +1169,6 @@
    <string name="SET_TRANSLATOR_HOST_LINGVA" translatable="false">lingva.ml</string>
    <string name="SET_TRANSLATOR_DOMAIN" translatable="false">SET_TRANSLATOR_DOMAIN</string>
    <string name="SET_TRANSLATOR" translatable="false">SET_TRANSLATOR</string>
    <string name="SET_STORED_ENDPOINT" translatable="false">SET_STORED_ENDPOINT</string>
    <string name="SET_TRANSLATOR_VERSION" translatable="false">SET_TRANSLATOR_VERSION</string>

    <string name="SET_TRANSLATOR_API_KEY" translatable="false">SET_TRANSLATOR_API_KEY</string>