From 300aea25618521b820c752997314c0e7f895afd1 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Tue, 21 Jul 2020 08:56:26 +0000 Subject: [PATCH] Only show the no google services toast once --- lib/components/matrix.dart | 2 +- lib/utils/firebase_controller.dart | 21 ++++++++++++++++----- lib/views/login.dart | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index aa59c82..bb0886a 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -81,7 +81,7 @@ class MatrixState extends State { client.connect(); if (await initLoginState == LoginState.logged && !kIsWeb) { await FirebaseController.setupFirebase( - client, + this, widget.clientName, ); } diff --git a/lib/utils/firebase_controller.dart b/lib/utils/firebase_controller.dart index 5efe800..efd8b99 100644 --- a/lib/utils/firebase_controller.dart +++ b/lib/utils/firebase_controller.dart @@ -13,6 +13,7 @@ import 'package:bot_toast/bot_toast.dart'; import 'package:path_provider/path_provider.dart'; import 'package:famedlysdk/famedlysdk.dart'; import 'famedlysdk_store.dart'; +import '../components/matrix.dart'; abstract class FirebaseController { static final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); @@ -26,7 +27,9 @@ abstract class FirebaseController { 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 { + static Future setupFirebase( + MatrixState matrix, String clientName) async { + final client = matrix.client; if (Platform.isIOS) iOS_Permission(); String token; @@ -36,10 +39,18 @@ abstract class FirebaseController { token = null; } if (token?.isEmpty ?? true) { - BotToast.showText( - text: L10n.of(context).noGoogleServicesWarning, - duration: Duration(seconds: 15), - ); + final storeItem = + await matrix.store.getItem('chat.fluffy.show_no_google'); + final configOptionMissing = storeItem == null || storeItem.isEmpty; + if (configOptionMissing || (!configOptionMissing && storeItem == '1')) { + BotToast.showText( + text: L10n.of(context).noGoogleServicesWarning, + duration: Duration(seconds: 15), + ); + if (configOptionMissing) { + await matrix.store.setItem('chat.fluffy.show_no_google', '0'); + } + } return; } final pushers = await client.api.requestPushers(); diff --git a/lib/views/login.dart b/lib/views/login.dart index 8f36078..18761d8 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -57,7 +57,7 @@ class _LoginState extends State { if (!kIsWeb) { try { await FirebaseController.setupFirebase( - matrix.client, + matrix, matrix.widget.clientName, ); } catch (exception) {