1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Attempt to auto-configure push notifications to remove one tour pane

This commit is contained in:
2021-04-26 10:49:33 +02:00
parent 5da8a64d3d
commit 8a581d158a
6 changed files with 67 additions and 28 deletions

View File

@ -1,8 +1,10 @@
import 'package:comunic/helpers/firebase_messaging_helper.dart';
import 'package:comunic/helpers/independent_push_notifications_helper.dart';
import 'package:comunic/helpers/preferences_helper.dart';
import 'package:comunic/helpers/server_config_helper.dart';
import 'package:comunic/models/api_request.dart';
import 'package:comunic/utils/flutter_utils.dart';
import 'package:flutter/material.dart';
/// Push notifications helper
///
@ -58,6 +60,34 @@ class PushNotificationsHelper {
IndependentPushNotificationsHelper.disable();
}
/// Configure push notifications
static Future<void> configure(
BuildContext context, PushNotificationsStatus newStatus) async {
String firebaseToken = "";
switch (newStatus) {
case PushNotificationsStatus.DISABLED:
break;
case PushNotificationsStatus.FIREBASE:
await FirebaseMessagingHelper.preConfigure();
firebaseToken = await FirebaseMessagingHelper.getToken();
break;
case PushNotificationsStatus.INDEPENDENT:
if (await IndependentPushNotificationsHelper.needPreConfiguration())
await IndependentPushNotificationsHelper.preConfigure(context);
break;
default:
throw new Exception("Unknown status!");
}
await PushNotificationsHelper.clearLocalStatus();
await PushNotificationsHelper.setNewStatus(newStatus,
firebaseToken: firebaseToken);
await PushNotificationsHelper.refreshLocalStatus();
}
/// Set new push notification status on the server
static Future<void> setNewStatus(
PushNotificationsStatus newStatus, {