Merge pull request #4137 from dpalou/MOBILE-4633

MOBILE-4633 message: Improve handle no permission error
main
Alfonso Salces 2024-08-01 14:50:45 +02:00 committed by GitHub
commit 21f785e4c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 2 deletions

View File

@ -29,6 +29,14 @@
</ion-list>
</ion-card>
@if (warningMessage()) {
<ion-card class="core-warning-card ion-margin-top">
<ion-item>
<ion-icon name="fas-triangle-exclamation" slot="start" aria-hidden="true" />
<ion-label>{{ warningMessage() }}</ion-label>
</ion-item>
</ion-card>
} @else {
<!-- Contactable privacy. -->
<ion-card>
<ion-item *ngIf="!advancedContactable" class="ion-text-wrap">
@ -72,6 +80,7 @@
<ng-container *ngTemplateOutlet="settings; context: {preferences: preferences}" />
</ng-container>
</ng-container>
}
</core-loading>
</ion-content>

View File

@ -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<string | undefined>(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;

View File

@ -20,6 +20,14 @@
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}" />
</ion-refresher>
<core-loading [hideUntil]="preferencesLoaded">
@if (warningMessage()) {
<ion-card class="core-warning-card ion-margin-top">
<ion-item>
<ion-icon name="fas-triangle-exclamation" slot="start" aria-hidden="true" />
<ion-label>{{ warningMessage() }}</ion-label>
</ion-item>
</ion-card>
} @else {
<ion-card>
<ion-item class="ion-text-wrap" *ngIf="preferences">
<ion-toggle [(ngModel)]="preferences.enableall" (ngModelChange)="enableAll(preferences.enableall)">
@ -52,6 +60,7 @@
<ng-container *ngTemplateOutlet="settings; context: {preferences: preferences}" />
</ng-container>
</ion-card>
}
</core-loading>
</ion-content>

View File

@ -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<string | undefined>(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;