Clean up pushers on start

This commit is contained in:
Christian Pauly
2020-05-13 11:00:12 +02:00
parent 975fb1a45c
commit a6af658501
3 changed files with 45 additions and 14 deletions

View File

@ -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<void> 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 {