mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-07-08 12:50:29 +03:00
Merge pull request 'Optimizations regarding push' (#1127) from s1m/Fedilab:optimizations_push into develop
Reviewed-on: https://codeberg.org/tom79/Fedilab/pulls/1127
This commit is contained in:
commit
6d47a8736e
4 changed files with 31 additions and 26 deletions
|
@ -102,11 +102,7 @@ allprojects {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.unifiedpush.android:connector:3.0.4'
|
implementation 'org.unifiedpush.android:connector:3.0.4'
|
||||||
|
|
||||||
playstoreImplementation('org.unifiedpush.android:embedded-fcm-distributor:3.0.0') {
|
playstoreImplementation('org.unifiedpush.android:embedded-fcm-distributor:3.0.0')
|
||||||
exclude group: 'com.google.firebase', module: 'firebase-core'
|
|
||||||
exclude group: 'com.google.firebase', module: 'firebase-analytics'
|
|
||||||
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
|
|
||||||
}
|
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.7.0'
|
implementation 'androidx.appcompat:appcompat:1.7.0'
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,23 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
||||||
|
|
||||||
public class PushNotifications {
|
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) {
|
public static void registerPushNotifications(Context context, PushEndpoint pushEndpoint, String slug) {
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,14 @@
|
||||||
package app.fedilab.android.mastodon.services;
|
package app.fedilab.android.mastodon.services;
|
||||||
|
|
||||||
import static app.fedilab.android.mastodon.helper.Helper.TAG;
|
import android.content.Context;
|
||||||
|
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
|
|
||||||
|
|
||||||
import org.unifiedpush.android.connector.FailedReason;
|
import org.unifiedpush.android.connector.FailedReason;
|
||||||
import org.unifiedpush.android.connector.PushService;
|
import org.unifiedpush.android.connector.PushService;
|
||||||
import org.unifiedpush.android.connector.data.PushEndpoint;
|
import org.unifiedpush.android.connector.data.PushEndpoint;
|
||||||
import org.unifiedpush.android.connector.data.PushMessage;
|
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.NotificationsHelper;
|
||||||
import app.fedilab.android.mastodon.helper.PushNotifications;
|
import app.fedilab.android.mastodon.helper.PushNotifications;
|
||||||
|
|
||||||
|
@ -49,17 +41,11 @@ public class PushServiceImpl extends PushService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewEndpoint(@NonNull PushEndpoint pushEndpoint, @NonNull String slug) {
|
public void onNewEndpoint(@NonNull PushEndpoint pushEndpoint, @NonNull String slug) {
|
||||||
if (getApplicationContext() != null) {
|
Context context = getApplicationContext();
|
||||||
|
if (context != null) {
|
||||||
synchronized (this) {
|
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
|
PushNotifications
|
||||||
.registerPushNotifications(getApplicationContext(), pushEndpoint, slug);
|
.registerPushNotifications(context, pushEndpoint, slug);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
editor.putString(getApplicationContext().getString(R.string.SET_STORED_ENDPOINT) + slug, pushEndpoint.getUrl());
|
|
||||||
editor.commit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +56,13 @@ public class PushServiceImpl extends PushService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1169,7 +1169,6 @@
|
||||||
<string name="SET_TRANSLATOR_HOST_LINGVA" translatable="false">lingva.ml</string>
|
<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_DOMAIN" translatable="false">SET_TRANSLATOR_DOMAIN</string>
|
||||||
<string name="SET_TRANSLATOR" translatable="false">SET_TRANSLATOR</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_VERSION" translatable="false">SET_TRANSLATOR_VERSION</string>
|
||||||
|
|
||||||
<string name="SET_TRANSLATOR_API_KEY" translatable="false">SET_TRANSLATOR_API_KEY</string>
|
<string name="SET_TRANSLATOR_API_KEY" translatable="false">SET_TRANSLATOR_API_KEY</string>
|
||||||
|
|
Loading…
Reference in a new issue