MOBILE-2618 message: Support new contactable setting

main
dpalou 2018-11-12 10:35:42 +01:00
parent ccafdd32cd
commit 38031ebdd5
7 changed files with 73 additions and 15 deletions

View File

@ -131,6 +131,10 @@
"addon.messages.blockcontact": "message", "addon.messages.blockcontact": "message",
"addon.messages.blockcontactconfirm": "local_moodlemobileapp", "addon.messages.blockcontactconfirm": "local_moodlemobileapp",
"addon.messages.blocknoncontacts": "message", "addon.messages.blocknoncontacts": "message",
"addon.messages.contactableprivacy": "message",
"addon.messages.contactableprivacy_coursemember": "message",
"addon.messages.contactableprivacy_onlycontacts": "message",
"addon.messages.contactableprivacy_site": "message",
"addon.messages.contactlistempty": "local_moodlemobileapp", "addon.messages.contactlistempty": "local_moodlemobileapp",
"addon.messages.contactname": "local_moodlemobileapp", "addon.messages.contactname": "local_moodlemobileapp",
"addon.messages.contacts": "message", "addon.messages.contacts": "message",
@ -1269,7 +1273,6 @@
"core.fileuploader.uploading": "local_moodlemobileapp", "core.fileuploader.uploading": "local_moodlemobileapp",
"core.fileuploader.uploadingperc": "local_moodlemobileapp", "core.fileuploader.uploadingperc": "local_moodlemobileapp",
"core.fileuploader.video": "local_moodlemobileapp", "core.fileuploader.video": "local_moodlemobileapp",
"core.login.findyoursite": "local_moodlemobileapp",
"core.folder": "moodle", "core.folder": "moodle",
"core.forcepasswordchangenotice": "moodle", "core.forcepasswordchangenotice": "moodle",
"core.fulllistofcourses": "moodle", "core.fulllistofcourses": "moodle",
@ -1329,6 +1332,7 @@
"core.login.erroraccesscontrolalloworigin": "local_moodlemobileapp", "core.login.erroraccesscontrolalloworigin": "local_moodlemobileapp",
"core.login.errordeletesite": "local_moodlemobileapp", "core.login.errordeletesite": "local_moodlemobileapp",
"core.login.errorupdatesite": "local_moodlemobileapp", "core.login.errorupdatesite": "local_moodlemobileapp",
"core.login.findyoursite": "local_moodlemobileapp",
"core.login.firsttime": "moodle", "core.login.firsttime": "moodle",
"core.login.forgotten": "moodle", "core.login.forgotten": "moodle",
"core.login.getanothercaptcha": "auth", "core.login.getanothercaptcha": "auth",

View File

@ -3,6 +3,10 @@
"blockcontact": "Block contact", "blockcontact": "Block contact",
"blockcontactconfirm": "You will no longer receive messages from this contact.", "blockcontactconfirm": "You will no longer receive messages from this contact.",
"blocknoncontacts": "Prevent non-contacts from messaging me", "blocknoncontacts": "Prevent non-contacts from messaging me",
"contactableprivacy": "Accept messages from:",
"contactableprivacy_coursemember": "My contacts and anyone in my courses",
"contactableprivacy_onlycontacts": "My contacts only",
"contactableprivacy_site": "Anyone on the site",
"contactlistempty": "The contact list is empty", "contactlistempty": "The contact list is empty",
"contactname": "Contact name", "contactname": "Contact name",
"contacts": "Contacts", "contacts": "Contacts",

View File

@ -8,12 +8,28 @@
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content> <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher> </ion-refresher>
<core-loading [hideUntil]="preferencesLoaded"> <core-loading [hideUntil]="preferencesLoaded">
<!-- Block non contacts. --> <!-- Contactable privacy. -->
<ion-card> <ion-card>
<ion-item> <ion-item *ngIf="!advancedContactable">
<ion-label>{{ 'addon.messages.blocknoncontacts' | translate }}</ion-label> <ion-label>{{ 'addon.messages.blocknoncontacts' | translate }}</ion-label>
<ion-toggle [(ngModel)]="blockNonContactsState" (ionChange)="blockNonContacts(blockNonContactsState)"></ion-toggle> <ion-toggle [(ngModel)]="contactablePrivacy" (ionChange)="saveContactablePrivacy(contactablePrivacy)"></ion-toggle>
</ion-item> </ion-item>
<ion-list *ngIf="advancedContactable" text-wrap radio-group [(ngModel)]="contactablePrivacy" (ionChange)="saveContactablePrivacy(contactablePrivacy)">
<ion-item-divider color="light">{{ 'addon.messages.contactableprivacy' | translate }}</ion-item-divider>
<ion-item>
<ion-label>{{ 'addon.messages.contactableprivacy_onlycontacts' | translate }}</ion-label>
<ion-radio [value]="onlyContactsValue"></ion-radio>
</ion-item>
<ion-item>
<ion-label>{{ 'addon.messages.contactableprivacy_coursemember' | translate }}</ion-label>
<ion-radio [value]="courseMemberValue"></ion-radio>
</ion-item>
<ion-item *ngIf="allowSiteMessaging">
<ion-label>{{ 'addon.messages.contactableprivacy_site' | translate }}</ion-label>
<ion-radio [value]="siteValue"></ion-radio>
</ion-item>
</ion-list>
</ion-card> </ion-card>
<ng-container *ngIf="preferences"> <ng-container *ngIf="preferences">

View File

@ -17,6 +17,7 @@ import { IonicPage } from 'ionic-angular';
import { AddonMessagesProvider } from '../../providers/messages'; import { AddonMessagesProvider } from '../../providers/messages';
import { CoreUserProvider } from '@core/user/providers/user'; import { CoreUserProvider } from '@core/user/providers/user';
import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreSitesProvider } from '@providers/sites';
/** /**
* Page that displays the messages settings page. * Page that displays the messages settings page.
@ -31,10 +32,21 @@ export class AddonMessagesSettingsPage implements OnDestroy {
preferences: any; preferences: any;
preferencesLoaded: boolean; preferencesLoaded: boolean;
blockNonContactsState = false; contactablePrivacy: number | boolean;
advancedContactable = false; // Whether the site supports "advanced" contactable privacy.
allowSiteMessaging = false;
onlyContactsValue = AddonMessagesProvider.MESSAGE_PRIVACY_ONLYCONTACTS;
courseMemberValue = AddonMessagesProvider.MESSAGE_PRIVACY_COURSEMEMBER;
siteValue = AddonMessagesProvider.MESSAGE_PRIVACY_SITE;
protected previousContactableValue: number | boolean;
constructor(private messagesProvider: AddonMessagesProvider, private domUtils: CoreDomUtilsProvider, constructor(private messagesProvider: AddonMessagesProvider, private domUtils: CoreDomUtilsProvider,
private userProvider: CoreUserProvider) { private userProvider: CoreUserProvider, sitesProvider: CoreSitesProvider) {
const currentSite = sitesProvider.getCurrentSite();
this.advancedContactable = currentSite && currentSite.isVersionGreaterEqualThan('3.6');
this.allowSiteMessaging = currentSite && currentSite.canUseAdvancedFeature('messagingallusers');
} }
/** /**
@ -54,7 +66,8 @@ 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) => {
this.preferences = preferences; this.preferences = preferences;
this.blockNonContactsState = preferences.blocknoncontacts; this.contactablePrivacy = preferences.blocknoncontacts;
this.previousContactableValue = this.contactablePrivacy;
}).catch((message) => { }).catch((message) => {
this.domUtils.showErrorModal(message); this.domUtils.showErrorModal(message);
}).finally(() => { }).finally(() => {
@ -85,19 +98,31 @@ export class AddonMessagesSettingsPage implements OnDestroy {
} }
/** /**
* Block non contacts. * Save the contactable privacy setting..
* *
* @param {boolean} block If it should be blocked or not. * @param {number|boolean} value The value to set.
*/ */
blockNonContacts(block: boolean): void { saveContactablePrivacy(value: number | boolean): void {
if (this.contactablePrivacy == this.previousContactableValue) {
// Value hasn't changed from previous, it probably means that we just fetched the value from the server.
return;
}
const modal = this.domUtils.showModalLoading('core.sending', true); const modal = this.domUtils.showModalLoading('core.sending', true);
this.userProvider.updateUserPreference('message_blocknoncontacts', block ? 1 : 0).then(() => {
if (!this.advancedContactable) {
// Convert from boolean to number.
value = value ? 1 : 0;
}
this.userProvider.updateUserPreference('message_blocknoncontacts', value).then(() => {
// Update the preferences since they were modified. // Update the preferences since they were modified.
this.updatePreferencesAfterDelay(); this.updatePreferencesAfterDelay();
this.previousContactableValue = this.contactablePrivacy;
}).catch((message) => { }).catch((message) => {
// Show error and revert change. // Show error and revert change.
this.domUtils.showErrorModal(message); this.domUtils.showErrorModal(message);
this.blockNonContactsState = !this.blockNonContactsState; this.contactablePrivacy = this.previousContactableValue;
}).finally(() => { }).finally(() => {
modal.dismiss(); modal.dismiss();
}); });
@ -148,7 +173,7 @@ export class AddonMessagesSettingsPage implements OnDestroy {
* *
* @param {any} refresher Refresher. * @param {any} refresher Refresher.
*/ */
refreshEvent(refresher: any): void { refreshPreferences(refresher: any): void {
this.messagesProvider.invalidateMessagePreferences().finally(() => { this.messagesProvider.invalidateMessagePreferences().finally(() => {
this.fetchPreferences().finally(() => { this.fetchPreferences().finally(() => {
refresher.complete(); refresher.complete();

View File

@ -37,6 +37,10 @@ export class AddonMessagesProvider {
static POLL_INTERVAL = 10000; static POLL_INTERVAL = 10000;
static PUSH_SIMULATION_COMPONENT = 'AddonMessagesPushSimulation'; static PUSH_SIMULATION_COMPONENT = 'AddonMessagesPushSimulation';
static MESSAGE_PRIVACY_COURSEMEMBER = 0; // Privacy setting for being messaged by anyone within courses user is member of.
static MESSAGE_PRIVACY_ONLYCONTACTS = 1; // Privacy setting for being messaged only by contacts.
static MESSAGE_PRIVACY_SITE = 2; // Privacy setting for being messaged by anyone on the site.
protected logger; protected logger;
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private appProvider: CoreAppProvider, constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private appProvider: CoreAppProvider,
@ -469,7 +473,7 @@ export class AddonMessagesProvider {
return site.read('core_message_get_user_message_preferences', {}, preSets).then((data) => { return site.read('core_message_get_user_message_preferences', {}, preSets).then((data) => {
if (data.preferences) { if (data.preferences) {
data.preferences.blocknoncontacts = !!data.blocknoncontacts; data.preferences.blocknoncontacts = data.blocknoncontacts;
return data.preferences; return data.preferences;
} }

View File

@ -131,6 +131,10 @@
"addon.messages.blockcontact": "Block contact", "addon.messages.blockcontact": "Block contact",
"addon.messages.blockcontactconfirm": "You will no longer receive messages from this contact.", "addon.messages.blockcontactconfirm": "You will no longer receive messages from this contact.",
"addon.messages.blocknoncontacts": "Prevent non-contacts from messaging me", "addon.messages.blocknoncontacts": "Prevent non-contacts from messaging me",
"addon.messages.contactableprivacy": "Accept messages from:",
"addon.messages.contactableprivacy_coursemember": "My contacts and anyone in my courses",
"addon.messages.contactableprivacy_onlycontacts": "My contacts only",
"addon.messages.contactableprivacy_site": "Anyone on the site",
"addon.messages.contactlistempty": "The contact list is empty", "addon.messages.contactlistempty": "The contact list is empty",
"addon.messages.contactname": "Contact name", "addon.messages.contactname": "Contact name",
"addon.messages.contacts": "Contacts", "addon.messages.contacts": "Contacts",

View File

@ -214,7 +214,8 @@ export class CoreSite {
3.2: 2016120500, 3.2: 2016120500,
3.3: 2017051503, 3.3: 2017051503,
3.4: 2017111300, 3.4: 2017111300,
3.5: 2018051700 3.5: 2018051700,
3.6: 2018111000 // @todo: Replace it with the right 3.6 date when released.
}; };
// Rest of variables. // Rest of variables.