From 392a4b2b41ff3ee02cae96f394b2bc92945c2de5 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 31 Jul 2024 15:57:19 +0200 Subject: [PATCH] MOBILE-4633 message: Improve handle no permission error --- src/addons/messages/pages/settings/settings.html | 9 +++++++++ src/addons/messages/pages/settings/settings.ts | 11 ++++++++++- .../notifications/pages/settings/settings.html | 9 +++++++++ src/addons/notifications/pages/settings/settings.ts | 12 +++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/addons/messages/pages/settings/settings.html b/src/addons/messages/pages/settings/settings.html index 606842fa1..0ab1a16dc 100644 --- a/src/addons/messages/pages/settings/settings.html +++ b/src/addons/messages/pages/settings/settings.html @@ -29,6 +29,14 @@ + @if (warningMessage()) { + + + + + } @else { @@ -72,6 +80,7 @@ + } diff --git a/src/addons/messages/pages/settings/settings.ts b/src/addons/messages/pages/settings/settings.ts index 91d9e6c2b..81387bc89 100644 --- a/src/addons/messages/pages/settings/settings.ts +++ b/src/addons/messages/pages/settings/settings.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit, signal } from '@angular/core'; import { AddonMessagesProvider, AddonMessagesMessagePreferences, AddonMessagesMessagePreferencesNotification, @@ -27,6 +27,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreConstants } from '@/core/constants'; import { AddonNotificationsPreferencesNotificationProcessorState } from '@addons/notifications/services/notifications'; import { CorePlatform } from '@services/platform'; +import { CoreTextUtils } from '@services/utils/text'; /** * Page that displays the messages settings page. @@ -49,6 +50,7 @@ export class AddonMessagesSettingsPage implements OnInit, OnDestroy { siteValue = AddonMessagesProvider.MESSAGE_PRIVACY_SITE; groupMessagingEnabled = false; sendOnEnter = false; + warningMessage = signal(undefined); protected loggedInOffLegacyMode = false; protected previousContactableValue?: number | boolean; @@ -106,7 +108,14 @@ export class AddonMessagesSettingsPage implements OnInit, OnDestroy { this.preferences = preferences; this.contactablePrivacy = preferences.blocknoncontacts; this.previousContactableValue = this.contactablePrivacy; + this.warningMessage.set(undefined); } catch (error) { + if (error.errorcode === 'nopermissions') { + this.warningMessage.set(CoreTextUtils.getErrorMessageFromError(error)); + + return; + } + CoreDomUtils.showErrorModal(error); } finally { this.preferencesLoaded = true; diff --git a/src/addons/notifications/pages/settings/settings.html b/src/addons/notifications/pages/settings/settings.html index 46804c15a..c3ec1194e 100644 --- a/src/addons/notifications/pages/settings/settings.html +++ b/src/addons/notifications/pages/settings/settings.html @@ -20,6 +20,14 @@ + @if (warningMessage()) { + + + + + } @else { @@ -52,6 +60,7 @@ + } diff --git a/src/addons/notifications/pages/settings/settings.ts b/src/addons/notifications/pages/settings/settings.ts index 7b9b891ca..be282aa1a 100644 --- a/src/addons/notifications/pages/settings/settings.ts +++ b/src/addons/notifications/pages/settings/settings.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Component, OnInit, OnDestroy, signal } from '@angular/core'; import { CoreConfig } from '@services/config'; import { CoreLocalNotifications } from '@services/local-notifications'; @@ -39,6 +39,7 @@ import { CoreNavigator } from '@services/navigator'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { Translate } from '@singletons'; +import { CoreTextUtils } from '@services/utils/text'; /** * Page that displays notifications settings. @@ -58,6 +59,7 @@ export class AddonNotificationsSettingsPage implements OnInit, OnDestroy { canChangeSound: boolean; processorHandlers: AddonMessageOutputHandlerData[] = []; loggedInOffLegacyMode = false; + warningMessage = signal(undefined); protected updateTimeout?: number; protected logView: () => void; @@ -99,6 +101,8 @@ export class AddonNotificationsSettingsPage implements OnInit, OnDestroy { try { const preferences = await AddonNotifications.getNotificationPreferences(); + this.warningMessage.set(undefined); + // Initialize current processor. Load "Mobile" (airnotifier) if available. let currentProcessor = preferences.processors.find((processor) => processor.name == this.currentProcessorName); if (!currentProcessor) { @@ -116,6 +120,12 @@ export class AddonNotificationsSettingsPage implements OnInit, OnDestroy { this.logView(); } catch (error) { + if (error.errorcode === 'nopermissions') { + this.warningMessage.set(CoreTextUtils.getErrorMessageFromError(error)); + + return; + } + CoreDomUtils.showErrorModal(error); } finally { this.preferencesLoaded = true;