From db49b6fa6bef2c28df43482d672451689a00e2d2 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 12 Apr 2021 19:34:06 +0200 Subject: [PATCH] Fix issue --- lib/helpers/preferences_helper.dart | 1 + lib/helpers/push_notifications_helper.dart | 34 +++++----------------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/lib/helpers/preferences_helper.dart b/lib/helpers/preferences_helper.dart index 7230891..18dffdc 100644 --- a/lib/helpers/preferences_helper.dart +++ b/lib/helpers/preferences_helper.dart @@ -22,6 +22,7 @@ const _PreferenceKeysName = { PreferencesKeyList.ENABLE_DARK_THEME: "dark_theme", PreferencesKeyList.FORCE_MOBILE_MODE: "force_mobile_mode", PreferencesKeyList.SHOW_PERFORMANCE_OVERLAY: "perfs_overlay", + PreferencesKeyList.PUSH_NOTIFICATIONS_STATUS: "push_notifications_status", }; class PreferencesHelper { diff --git a/lib/helpers/push_notifications_helper.dart b/lib/helpers/push_notifications_helper.dart index 6086bea..a92c181 100644 --- a/lib/helpers/push_notifications_helper.dart +++ b/lib/helpers/push_notifications_helper.dart @@ -30,38 +30,18 @@ class PushNotificationsHelper { /// /// Throws in case of failure static Future refreshLocalStatus() async { - final pref = await PreferencesHelper.getInstance(); - final response = await APIRequest.withLogin("push_notifications/status") .execWithThrowGetObject(); - switch (response["status"]) { - case "undefined": - await pref.removeKey(PreferencesKeyList.PUSH_NOTIFICATIONS_STATUS); - break; + var status = _PushNotificationsAPIMap[response["status"]]; + if (status == null) status = PushNotificationsStatus.UNDEFINED; - case "disabled": - await pref.setString( - PreferencesKeyList.PUSH_NOTIFICATIONS_STATUS, "disabled"); - break; - - case "firebase": - await pref.setString( - PreferencesKeyList.PUSH_NOTIFICATIONS_STATUS, "firebase"); - break; - - case "independent": - await pref.setString( - PreferencesKeyList.PUSH_NOTIFICATIONS_STATUS, "independent"); - // TODO : Invoke plugin to apply new WebSocket URL - break; - - default: - print( - "Push notifications status ${response["status"]} is unknown, defaulting to disabled!"); - await pref.setString( - PreferencesKeyList.PUSH_NOTIFICATIONS_STATUS, "disabled"); + if (status == PushNotificationsStatus.INDEPENDENT) { + // TODO : Invoke plugin to apply new WebSocket URL } + + await (await PreferencesHelper.getInstance()).setString( + PreferencesKeyList.PUSH_NOTIFICATIONS_STATUS, response["status"]); } /// Clear local push notifications status