MOBILE-2989 forum: Check whether the set pin state WS is available

main
Albert Gasset 2019-05-02 10:42:46 +02:00
parent 8cdca2ebd9
commit ad6d5019f1
2 changed files with 23 additions and 5 deletions

View File

@ -351,12 +351,16 @@ export class AddonModForumDiscussionPage implements OnDestroy {
this.ratingInfo = ratingInfo;
});
}).then(() => {
if (this.forumProvider.isSetPinStateAvailableForSite()) {
// Use the canAddDiscussion WS to check if the user can pin discussions.
return this.forumProvider.canAddDiscussionToAll(this.forumId).then((response) => {
this.canPin = !!response.canpindiscussions;
}).catch(() => {
this.canPin = false;
});
} else {
this.canPin = false;
}
}).then(() => {
return this.ratingOffline.hasRatings('mod_forum', 'post', 'module', this.cmId, this.discussionId).then((hasRatings) => {
this.hasOfflineRatings = hasRatings;

View File

@ -14,6 +14,7 @@
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { CoreSite } from '@classes/site';
import { CoreAppProvider } from '@providers/app';
import { CoreFilepoolProvider } from '@providers/filepool';
import { CoreGroupsProvider } from '@providers/groups';
@ -784,6 +785,19 @@ export class AddonModForumProvider {
});
}
/**
* Returns whether the set pin state WS is available.
*
* @param {CoreSite} [site] Site. If not defined, current site.
* @return {boolean} Whether it's available.
* @since 3.7
*/
isSetPinStateAvailableForSite(site?: CoreSite): boolean {
site = site || this.sitesProvider.getCurrentSite();
return this.sitesProvider.wsAvailableInCurrentSite('mod_forum_set_pin_state');
}
/**
* Pin or unpin a discussion.
*