forked from EVOgeek/Vmeda.Online
MOBILE-2620 messages: New web services for blocking/unblocking users
parent
617ecb041d
commit
70dd9302ec
|
@ -70,7 +70,7 @@ export class AddonMessagesProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block a contact.
|
* Block a user.
|
||||||
*
|
*
|
||||||
* @param {number} userId User ID of the person to block.
|
* @param {number} userId User ID of the person to block.
|
||||||
* @param {string} [siteId] Site ID. If not defined, use current site.
|
* @param {string} [siteId] Site ID. If not defined, use current site.
|
||||||
|
@ -78,11 +78,22 @@ export class AddonMessagesProvider {
|
||||||
*/
|
*/
|
||||||
blockContact(userId: number, siteId?: string): Promise<any> {
|
blockContact(userId: number, siteId?: string): Promise<any> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
|
let promise;
|
||||||
|
if (site.wsAvailable('core_message_block_user')) {
|
||||||
|
// Since Moodle 3.6
|
||||||
const params = {
|
const params = {
|
||||||
userids: [ userId ]
|
userid: site.getUserId(),
|
||||||
|
blockeduserid: userId,
|
||||||
};
|
};
|
||||||
|
promise = site.write('core_message_block_user', params);
|
||||||
|
} else {
|
||||||
|
const params = {
|
||||||
|
userids: [userId]
|
||||||
|
};
|
||||||
|
promise = site.write('core_message_block_contacts', params);
|
||||||
|
}
|
||||||
|
|
||||||
return site.write('core_message_block_contacts', params).then(() => {
|
return promise.then(() => {
|
||||||
return this.invalidateAllContactsCache(site.getUserId(), site.getId());
|
return this.invalidateAllContactsCache(site.getUserId(), site.getId());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1157,14 +1168,25 @@ export class AddonMessagesProvider {
|
||||||
*/
|
*/
|
||||||
unblockContact(userId: number, siteId?: string): Promise<any> {
|
unblockContact(userId: number, siteId?: string): Promise<any> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
|
let promise;
|
||||||
|
if (site.wsAvailable('core_message_unblock_user')) {
|
||||||
|
// Since Moodle 3.6
|
||||||
const params = {
|
const params = {
|
||||||
userids: [ userId ]
|
userid: site.getUserId(),
|
||||||
},
|
unblockeduserid: userId,
|
||||||
preSets = {
|
};
|
||||||
|
promise = site.write('core_message_unblock_user', params);
|
||||||
|
} else {
|
||||||
|
const params = {
|
||||||
|
userids: [userId]
|
||||||
|
};
|
||||||
|
const preSets = {
|
||||||
responseExpected: false
|
responseExpected: false
|
||||||
};
|
};
|
||||||
|
promise = site.write('core_message_unblock_contacts', params, preSets);
|
||||||
|
}
|
||||||
|
|
||||||
return site.write('core_message_unblock_contacts', params, preSets).then(() => {
|
return promise.then(() => {
|
||||||
return this.invalidateAllContactsCache(site.getUserId(), site.getId());
|
return this.invalidateAllContactsCache(site.getUserId(), site.getId());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue