diff --git a/lib/utils/firebase_controller.dart b/lib/utils/firebase_controller.dart index d0991ca..1bf23c5 100644 --- a/lib/utils/firebase_controller.dart +++ b/lib/utils/firebase_controller.dart @@ -22,6 +22,9 @@ abstract class FirebaseController { static const String CHANNEL_ID = 'fluffychat_push'; static const String CHANNEL_NAME = 'FluffyChat push channel'; static const String CHANNEL_DESCRIPTION = 'Push notifications for FluffyChat'; + static const String APP_ID = 'chat.fluffy.fluffychat'; + static const String GATEWAY_URL = 'https://janian.de:7023/'; + static const String PUSHER_FORMAT = 'event_id_only'; static Future setupFirebase(Client client, String clientName) async { if (Platform.isIOS) iOS_Permission(); @@ -39,17 +42,45 @@ abstract class FirebaseController { ); return; } - await client.setPushers( - token, - "http", - "chat.fluffy.fluffychat", - clientName, - client.deviceName, - "en", - "https://janian.de:7023/", - append: false, - format: "event_id_only", - ); + final pushers = await client.getPushers(); + final currentPushers = pushers.where((pusher) => pusher.pushkey == token); + if (currentPushers.length == 1 && + currentPushers.first.kind == 'http' && + currentPushers.first.appId == APP_ID && + currentPushers.first.appDisplayName == clientName && + currentPushers.first.deviceDisplayName == client.deviceName && + currentPushers.first.lang == 'en' && + currentPushers.first.data.url == GATEWAY_URL && + currentPushers.first.data.format == PUSHER_FORMAT) { + debugPrint("[Push] Pusher already set"); + } else { + if (currentPushers.isNotEmpty) { + for (final currentPusher in currentPushers) { + await client.setPushers( + token, + 'null', + currentPusher.appId, + currentPusher.appDisplayName, + currentPusher.deviceDisplayName, + currentPusher.lang, + currentPusher.data.url, + append: true, + ); + debugPrint("[Push] Remove legacy pusher for this device"); + } + } + await client.setPushers( + token, + "http", + APP_ID, + clientName, + client.deviceName, + "en", + GATEWAY_URL, + append: false, + format: PUSHER_FORMAT, + ); + } Function goToRoom = (dynamic message) async { try { diff --git a/pubspec.lock b/pubspec.lock index cd398f8..232d8f1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -124,8 +124,8 @@ packages: dependency: "direct main" description: path: "." - ref: "4b2d4913b3e720f62698c46dfa6b17d5f0e1aa49" - resolved-ref: "4b2d4913b3e720f62698c46dfa6b17d5f0e1aa49" + ref: "2525b3d9f156fa303ca9283a96fd8cf8db154dd9" + resolved-ref: "2525b3d9f156fa303ca9283a96fd8cf8db154dd9" url: "https://gitlab.com/famedly/famedlysdk.git" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index 4b492e4..e5b83e9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: famedlysdk: git: url: https://gitlab.com/famedly/famedlysdk.git - ref: 4b2d4913b3e720f62698c46dfa6b17d5f0e1aa49 + ref: 2525b3d9f156fa303ca9283a96fd8cf8db154dd9 localstorage: ^3.0.1+4 bubble: ^1.1.9+1