Merge pull request #1636 from dpalou/MOBILE-2758
MOBILE-2758 message: Simplify message preferencesmain
commit
62a37720da
|
@ -37,36 +37,55 @@
|
||||||
<ion-card list *ngFor="let notification of component.notifications">
|
<ion-card list *ngFor="let notification of component.notifications">
|
||||||
<ion-item-divider color="light" text-wrap>
|
<ion-item-divider color="light" text-wrap>
|
||||||
<ion-row no-padding>
|
<ion-row no-padding>
|
||||||
<ion-col no-padding>{{ notification.displayname }}</ion-col>
|
<ng-container *ngIf="!groupMessagingEnabled">
|
||||||
<ion-col col-2 text-center no-padding class="hidden-phone">{{ 'core.settings.loggedin' | translate }}</ion-col>
|
<ion-col no-padding>{{ notification.displayname }}</ion-col>
|
||||||
<ion-col col-2 text-center no-padding class="hidden-phone">{{ 'core.settings.loggedoff' | translate }}</ion-col>
|
<ion-col col-2 text-center no-padding class="hidden-phone">{{ 'core.settings.loggedin' | translate }}</ion-col>
|
||||||
|
<ion-col *ngIf="!groupMessagingEnabled" col-2 text-center no-padding class="hidden-phone">{{ 'core.settings.loggedoff' | translate }}</ion-col>
|
||||||
|
</ng-container>
|
||||||
|
<ng-container *ngIf="groupMessagingEnabled">
|
||||||
|
<ion-col no-padding>{{ 'addon.notifications.notificationpreferences' | translate }}</ion-col>
|
||||||
|
</ng-container>
|
||||||
</ion-row>
|
</ion-row>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<ng-container *ngFor="let processor of notification.processors">
|
<ng-container *ngFor="let processor of notification.processors">
|
||||||
<!-- Tablet view -->
|
<!-- If group messaging is enabled, display a simplified view. -->
|
||||||
<ion-row text-wrap class="hidden-phone" align-items-center>
|
<ng-container *ngIf="groupMessagingEnabled">
|
||||||
<ion-col margin-horizontal>{{ processor.displayname }}</ion-col>
|
<ion-item text-wrap>
|
||||||
<ion-col col-2 text-center *ngFor="let state of ['loggedin', 'loggedoff']">
|
<ion-label>{{ processor.displayname }}</ion-label>
|
||||||
<!-- If notifications not disabled, show toggle. -->
|
<ion-spinner item-end *ngIf="!preferences.disableall && notification.updating"></ion-spinner>
|
||||||
<ion-spinner [hidden]="preferences.disableall || !(notification.updating && notification.updating[state])"></ion-spinner>
|
<ion-toggle item-end *ngIf="!preferences.disableall && !processor.locked" [(ngModel)]="processor.checked" (ionChange)="changePreference(notification, '', processor)" [disabled]="notification.updating">
|
||||||
<ion-toggle *ngIf="!preferences.disableall && !processor.locked" [(ngModel)]="processor[state].checked" (ionChange)="changePreference(notification, state, processor)" [disabled]="notification.updating && notification.updating[state]">
|
|
||||||
</ion-toggle>
|
</ion-toggle>
|
||||||
<div padding class="text-gray" *ngIf="!preferences.disableall && processor.locked">{{'core.settings.locked' | translate }}</div>
|
<ion-note item-end *ngIf="!preferences.disableall && processor.locked">{{ processor.lockedmessage }}</ion-note>
|
||||||
<!-- If notifications are disabled, show "Disabled" instead of toggle. -->
|
<ion-note item-end *ngIf="preferences.disableall">{{ 'core.settings.disabled' | translate }}</ion-note>
|
||||||
<span *ngIf="preferences.disableall">{{ 'core.settings.disabled' | translate }}</span>
|
</ion-item>
|
||||||
</ion-col>
|
</ng-container>
|
||||||
</ion-row>
|
|
||||||
<!-- Phone view -->
|
<ng-container *ngIf="!groupMessagingEnabled">
|
||||||
<ion-list-header text-wrap class="hidden-tablet">{{ processor.displayname }}</ion-list-header>
|
<!-- Tablet view -->
|
||||||
<!-- If notifications not disabled, show toggles. If notifications are disabled, show "Disabled" instead of toggle. -->
|
<ion-row text-wrap class="hidden-phone" align-items-center>
|
||||||
<ion-item *ngFor="let state of ['loggedin', 'loggedoff']" text-wrap class="hidden-tablet">
|
<ion-col margin-horizontal>{{ processor.displayname }}</ion-col>
|
||||||
<ion-label>{{ 'core.settings.' + state | translate }}</ion-label>
|
<ion-col col-2 text-center *ngFor="let state of ['loggedin', 'loggedoff']">
|
||||||
<ion-spinner item-end *ngIf="!preferences.disableall && (notification.updating && notification.updating[state])"></ion-spinner>
|
<!-- If notifications not disabled, show toggle. -->
|
||||||
<ion-toggle item-end *ngIf="!preferences.disableall && !processor.locked" [(ngModel)]="processor[state].checked" (ionChange)="changePreference(notification, state, processor)" [disabled]="notification.updating && notification.updating[state]">
|
<ion-spinner [hidden]="preferences.disableall || !(notification.updating && notification.updating[state])"></ion-spinner>
|
||||||
</ion-toggle>
|
<ion-toggle *ngIf="!preferences.disableall && !processor.locked" [(ngModel)]="processor[state].checked" (ionChange)="changePreference(notification, state, processor)" [disabled]="notification.updating && notification.updating[state]">
|
||||||
<ion-note item-end *ngIf="!preferences.disableall && processor.locked">{{'core.settings.locked' | translate }}</ion-note>
|
</ion-toggle>
|
||||||
<ion-note item-end *ngIf="preferences.disableall">{{ 'core.settings.disabled' | translate }}</ion-note>
|
<div padding class="text-gray" *ngIf="!preferences.disableall && processor.locked">{{'core.settings.locked' | translate }}</div>
|
||||||
</ion-item>
|
<!-- If notifications are disabled, show "Disabled" instead of toggle. -->
|
||||||
|
<span *ngIf="preferences.disableall">{{ 'core.settings.disabled' | translate }}</span>
|
||||||
|
</ion-col>
|
||||||
|
</ion-row>
|
||||||
|
<!-- Phone view -->
|
||||||
|
<ion-list-header text-wrap class="hidden-tablet">{{ processor.displayname }}</ion-list-header>
|
||||||
|
<!-- If notifications not disabled, show toggles. If notifications are disabled, show "Disabled" instead of toggle. -->
|
||||||
|
<ion-item *ngFor="let state of ['loggedin', 'loggedoff']" text-wrap class="hidden-tablet">
|
||||||
|
<ion-label>{{ 'core.settings.' + state | translate }}</ion-label>
|
||||||
|
<ion-spinner item-end *ngIf="!preferences.disableall && (notification.updating && notification.updating[state])"></ion-spinner>
|
||||||
|
<ion-toggle item-end *ngIf="!preferences.disableall && !processor.locked" [(ngModel)]="processor[state].checked" (ionChange)="changePreference(notification, state, processor)" [disabled]="notification.updating && notification.updating[state]">
|
||||||
|
</ion-toggle>
|
||||||
|
<ion-note item-end *ngIf="!preferences.disableall && processor.locked">{{'core.settings.locked' | translate }}</ion-note>
|
||||||
|
<ion-note item-end *ngIf="preferences.disableall">{{ 'core.settings.disabled' | translate }}</ion-note>
|
||||||
|
</ion-item>
|
||||||
|
</ng-container>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</ion-card>
|
</ion-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -38,6 +38,7 @@ export class AddonMessagesSettingsPage implements OnDestroy {
|
||||||
onlyContactsValue = AddonMessagesProvider.MESSAGE_PRIVACY_ONLYCONTACTS;
|
onlyContactsValue = AddonMessagesProvider.MESSAGE_PRIVACY_ONLYCONTACTS;
|
||||||
courseMemberValue = AddonMessagesProvider.MESSAGE_PRIVACY_COURSEMEMBER;
|
courseMemberValue = AddonMessagesProvider.MESSAGE_PRIVACY_COURSEMEMBER;
|
||||||
siteValue = AddonMessagesProvider.MESSAGE_PRIVACY_SITE;
|
siteValue = AddonMessagesProvider.MESSAGE_PRIVACY_SITE;
|
||||||
|
groupMessagingEnabled: boolean;
|
||||||
|
|
||||||
protected previousContactableValue: number | boolean;
|
protected previousContactableValue: number | boolean;
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ export class AddonMessagesSettingsPage implements OnDestroy {
|
||||||
const currentSite = sitesProvider.getCurrentSite();
|
const currentSite = sitesProvider.getCurrentSite();
|
||||||
this.advancedContactable = currentSite && currentSite.isVersionGreaterEqualThan('3.6');
|
this.advancedContactable = currentSite && currentSite.isVersionGreaterEqualThan('3.6');
|
||||||
this.allowSiteMessaging = currentSite && currentSite.canUseAdvancedFeature('messagingallusers');
|
this.allowSiteMessaging = currentSite && currentSite.canUseAdvancedFeature('messagingallusers');
|
||||||
|
this.groupMessagingEnabled = this.messagesProvider.isGroupMessagingEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,6 +67,22 @@ export class AddonMessagesSettingsPage implements OnDestroy {
|
||||||
*/
|
*/
|
||||||
protected fetchPreferences(): Promise<any> {
|
protected fetchPreferences(): Promise<any> {
|
||||||
return this.messagesProvider.getMessagePreferences().then((preferences) => {
|
return this.messagesProvider.getMessagePreferences().then((preferences) => {
|
||||||
|
if (this.groupMessagingEnabled) {
|
||||||
|
// Simplify the preferences.
|
||||||
|
for (const component of preferences.components) {
|
||||||
|
// Only display get the notification preferences.
|
||||||
|
component.notifications = component.notifications.filter((notification) => {
|
||||||
|
return notification.preferencekey == AddonMessagesProvider.NOTIFICATION_PREFERENCES_KEY;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const notification of component.notifications) {
|
||||||
|
for (const processor of notification.processors) {
|
||||||
|
processor.checked = processor.loggedin.checked || processor.loggedoff.checked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.preferences = preferences;
|
this.preferences = preferences;
|
||||||
this.contactablePrivacy = preferences.blocknoncontacts;
|
this.contactablePrivacy = preferences.blocknoncontacts;
|
||||||
this.previousContactableValue = this.contactablePrivacy;
|
this.previousContactableValue = this.contactablePrivacy;
|
||||||
|
@ -136,36 +154,70 @@ export class AddonMessagesSettingsPage implements OnDestroy {
|
||||||
* @param {any} processor Notification processor.
|
* @param {any} processor Notification processor.
|
||||||
*/
|
*/
|
||||||
changePreference(notification: any, state: string, processor: any): void {
|
changePreference(notification: any, state: string, processor: any): void {
|
||||||
const processorState = processor[state],
|
if (this.groupMessagingEnabled) {
|
||||||
preferenceName = notification.preferencekey + '_' + processorState.name,
|
// Update both states at the same time.
|
||||||
valueArray = [];
|
const valueArray = [],
|
||||||
let value = 'none';
|
promises = [];
|
||||||
|
let value = 'none';
|
||||||
|
|
||||||
notification.processors.forEach((processor) => {
|
notification.processors.forEach((processor) => {
|
||||||
if (processor[state].checked) {
|
if (processor.checked) {
|
||||||
valueArray.push(processor.name);
|
valueArray.push(processor.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (value.length > 0) {
|
||||||
|
value = valueArray.join(',');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (value.length > 0) {
|
notification.updating = true;
|
||||||
value = valueArray.join(',');
|
|
||||||
|
promises.push(this.userProvider.updateUserPreference(notification.preferencekey + '_loggedin', value));
|
||||||
|
promises.push(this.userProvider.updateUserPreference(notification.preferencekey + '_loggedoff', value));
|
||||||
|
|
||||||
|
Promise.all(promises).then(() => {
|
||||||
|
// Update the preferences since they were modified.
|
||||||
|
this.updatePreferencesAfterDelay();
|
||||||
|
}).catch((error) => {
|
||||||
|
// Show error and revert change.
|
||||||
|
this.domUtils.showErrorModal(error);
|
||||||
|
processor.checked = !processor.checked;
|
||||||
|
}).finally(() => {
|
||||||
|
notification.updating = false;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Update only the specified state.
|
||||||
|
const processorState = processor[state],
|
||||||
|
preferenceName = notification.preferencekey + '_' + processorState.name,
|
||||||
|
valueArray = [];
|
||||||
|
let value = 'none';
|
||||||
|
|
||||||
|
notification.processors.forEach((processor) => {
|
||||||
|
if (processor[state].checked) {
|
||||||
|
valueArray.push(processor.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (value.length > 0) {
|
||||||
|
value = valueArray.join(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!notification.updating) {
|
||||||
|
notification.updating = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
notification.updating[state] = true;
|
||||||
|
this.userProvider.updateUserPreference(preferenceName, value).then(() => {
|
||||||
|
// Update the preferences since they were modified.
|
||||||
|
this.updatePreferencesAfterDelay();
|
||||||
|
}).catch((message) => {
|
||||||
|
// Show error and revert change.
|
||||||
|
this.domUtils.showErrorModal(message);
|
||||||
|
processorState.checked = !processorState.checked;
|
||||||
|
}).finally(() => {
|
||||||
|
notification.updating[state] = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!notification.updating) {
|
|
||||||
notification.updating = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
notification.updating[state] = true;
|
|
||||||
this.userProvider.updateUserPreference(preferenceName, value).then(() => {
|
|
||||||
// Update the preferences since they were modified.
|
|
||||||
this.updatePreferencesAfterDelay();
|
|
||||||
}).catch((message) => {
|
|
||||||
// Show error and revert change.
|
|
||||||
this.domUtils.showErrorModal(message);
|
|
||||||
processorState.checked = !processorState.checked;
|
|
||||||
}).finally(() => {
|
|
||||||
notification.updating[state] = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -45,6 +45,8 @@ export class AddonMessagesProvider {
|
||||||
static MESSAGE_CONVERSATION_TYPE_GROUP = 2; // A group conversation.
|
static MESSAGE_CONVERSATION_TYPE_GROUP = 2; // A group conversation.
|
||||||
static LIMIT_MESSAGES = 50;
|
static LIMIT_MESSAGES = 50;
|
||||||
|
|
||||||
|
static NOTIFICATION_PREFERENCES_KEY = 'message_provider_moodle_instantmessage';
|
||||||
|
|
||||||
protected logger;
|
protected logger;
|
||||||
|
|
||||||
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private appProvider: CoreAppProvider,
|
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private appProvider: CoreAppProvider,
|
||||||
|
|
Loading…
Reference in New Issue