mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 16:25:17 +00:00
Attempt to auto-configure push notifications to remove one tour pane
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
import 'package:comunic/helpers/firebase_messaging_helper.dart';
|
||||
import 'package:comunic/helpers/independent_push_notifications_helper.dart';
|
||||
import 'package:comunic/helpers/push_notifications_helper.dart';
|
||||
import 'package:comunic/helpers/server_config_helper.dart';
|
||||
import 'package:comunic/models/config.dart';
|
||||
@ -162,35 +160,12 @@ class PushNotificationsConfigurationWidgetState
|
||||
|
||||
Future<bool> submit() async {
|
||||
try {
|
||||
String firebaseToken = "";
|
||||
|
||||
if (currStatus == await PushNotificationsHelper.getLocalStatus()) {
|
||||
widget.onConfigured();
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (currStatus) {
|
||||
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(currStatus,
|
||||
firebaseToken: firebaseToken);
|
||||
await PushNotificationsHelper.refreshLocalStatus();
|
||||
await PushNotificationsHelper.configure(context, currStatus);
|
||||
|
||||
widget.onConfigured();
|
||||
} catch (e, s) {
|
||||
|
@ -1,4 +1,6 @@
|
||||
import 'package:comunic/helpers/preferences_helper.dart';
|
||||
import 'package:comunic/helpers/push_notifications_helper.dart';
|
||||
import 'package:comunic/helpers/server_config_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/models/config.dart';
|
||||
import 'package:comunic/models/user.dart';
|
||||
@ -12,6 +14,7 @@ import 'package:comunic/ui/widgets/tour/presentation_pane.dart';
|
||||
import 'package:comunic/ui/widgets/tour/tour_notifications_pane.dart';
|
||||
import 'package:comunic/utils/account_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/log_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Tour route
|
||||
@ -41,9 +44,27 @@ class TourRouteState extends State<TourRoute> {
|
||||
|
||||
int _defaultIndex = 0;
|
||||
|
||||
bool areNotificationsConfigured = false;
|
||||
|
||||
Future<void> _init() async {
|
||||
currUser =
|
||||
await UsersHelper().getSingleWithThrow(userID(), forceDownload: true);
|
||||
|
||||
// Pre-configure notifications
|
||||
final notificationsStatus = await PushNotificationsHelper.getLocalStatus();
|
||||
if (!PushNotificationsHelper.arePushNotificationsAvailable ||
|
||||
notificationsStatus != PushNotificationsStatus.UNDEFINED)
|
||||
areNotificationsConfigured = true;
|
||||
|
||||
// Attempt to automatically register to FCM
|
||||
else if (srvConfig.notificationsPolicy.hasFirebase) {
|
||||
try {
|
||||
await PushNotificationsHelper.configure(
|
||||
context, PushNotificationsStatus.FIREBASE);
|
||||
} catch (e, s) {
|
||||
logError(e, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rebuild() => setState(() {});
|
||||
@ -53,7 +74,7 @@ class TourRouteState extends State<TourRoute> {
|
||||
await _key.currentState.refresh();
|
||||
}
|
||||
|
||||
List<Widget> get _list => config().toursEntriesBuilder != null
|
||||
List<Widget> get _list => (config().toursEntriesBuilder != null
|
||||
? config().toursEntriesBuilder(this)
|
||||
: [
|
||||
FirstTourPane(),
|
||||
@ -69,6 +90,7 @@ class TourRouteState extends State<TourRoute> {
|
||||
pushNotificationsKey: pushNotificationsKey,
|
||||
onConfigured: () => setState(() {}),
|
||||
onChanged: () => setState(() {}),
|
||||
visible: !areNotificationsConfigured,
|
||||
),
|
||||
|
||||
PresentationPane(
|
||||
@ -96,7 +118,14 @@ class TourRouteState extends State<TourRoute> {
|
||||
"${tr("Your data is YOUR DATA. We will never use it or sell it.")}\n\n${tr("If you do not trust us, you can always check out our source code to verify it!")}",
|
||||
),
|
||||
LastTourPane(),
|
||||
];
|
||||
])
|
||||
..removeWhere((pane) {
|
||||
if (pane is PresentationPane) {
|
||||
PresentationPane p = pane;
|
||||
return !(p.visible ?? true);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LoginRoutesTheme(
|
||||
|
Reference in New Issue
Block a user