Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBILE-4633 message: Improve handle no permission error #4137

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/addons/messages/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ <h2>{{ 'core.settings.general' | translate }}</h2>
</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">
Expand Down Expand Up @@ -72,6 +80,7 @@ <h2>{{ 'addon.messages.contactableprivacy' | translate }}</h2>
<ng-container *ngTemplateOutlet="settings; context: {preferences: preferences}" />
</ng-container>
</ng-container>
}
</core-loading>
</ion-content>

Expand Down
11 changes: 10 additions & 1 deletion src/addons/messages/pages/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/addons/notifications/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ <h1>{{ 'addon.notifications.notifications' | translate }}</h1>
<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)">
Expand Down Expand Up @@ -52,6 +60,7 @@ <h1>{{ 'addon.notifications.notifications' | translate }}</h1>
<ng-container *ngTemplateOutlet="settings; context: {preferences: preferences}" />
</ng-container>
</ion-card>
}
</core-loading>

</ion-content>
Expand Down
12 changes: 11 additions & 1 deletion src/addons/notifications/pages/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down