MOBILE-3213 forum: Check user preferences on sort
parent
b44a4ae464
commit
8a6063f00a
|
@ -22,6 +22,7 @@ import { CoreSitesProvider } from '@providers/sites';
|
||||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||||
import { CoreFileUploaderProvider } from '@core/fileuploader/providers/fileuploader';
|
import { CoreFileUploaderProvider } from '@core/fileuploader/providers/fileuploader';
|
||||||
|
import { CoreUserProvider } from '@core/user/providers/user';
|
||||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||||
import { CoreRatingProvider, CoreRatingInfo } from '@core/rating/providers/rating';
|
import { CoreRatingProvider, CoreRatingInfo } from '@core/rating/providers/rating';
|
||||||
import { CoreRatingOfflineProvider } from '@core/rating/providers/offline';
|
import { CoreRatingOfflineProvider } from '@core/rating/providers/offline';
|
||||||
|
@ -57,7 +58,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
|
||||||
isOnline: boolean;
|
isOnline: boolean;
|
||||||
isSplitViewOn: boolean;
|
isSplitViewOn: boolean;
|
||||||
postHasOffline: boolean;
|
postHasOffline: boolean;
|
||||||
sort: SortType = 'flat-oldest';
|
sort: SortType = 'nested';
|
||||||
trackPosts: boolean;
|
trackPosts: boolean;
|
||||||
replyData = {
|
replyData = {
|
||||||
replyingTo: 0,
|
replyingTo: 0,
|
||||||
|
@ -96,19 +97,20 @@ export class AddonModForumDiscussionPage implements OnDestroy {
|
||||||
constructor(navParams: NavParams,
|
constructor(navParams: NavParams,
|
||||||
network: Network,
|
network: Network,
|
||||||
zone: NgZone,
|
zone: NgZone,
|
||||||
private appProvider: CoreAppProvider,
|
protected appProvider: CoreAppProvider,
|
||||||
private eventsProvider: CoreEventsProvider,
|
protected eventsProvider: CoreEventsProvider,
|
||||||
private sitesProvider: CoreSitesProvider,
|
protected sitesProvider: CoreSitesProvider,
|
||||||
private domUtils: CoreDomUtilsProvider,
|
protected domUtils: CoreDomUtilsProvider,
|
||||||
private utils: CoreUtilsProvider,
|
protected utils: CoreUtilsProvider,
|
||||||
private translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
private uploaderProvider: CoreFileUploaderProvider,
|
protected uploaderProvider: CoreFileUploaderProvider,
|
||||||
private forumProvider: AddonModForumProvider,
|
protected forumProvider: AddonModForumProvider,
|
||||||
private forumOffline: AddonModForumOfflineProvider,
|
protected forumOffline: AddonModForumOfflineProvider,
|
||||||
private forumHelper: AddonModForumHelperProvider,
|
protected forumHelper: AddonModForumHelperProvider,
|
||||||
private forumSync: AddonModForumSyncProvider,
|
protected forumSync: AddonModForumSyncProvider,
|
||||||
private ratingOffline: CoreRatingOfflineProvider,
|
protected ratingOffline: CoreRatingOfflineProvider,
|
||||||
@Optional() private svComponent: CoreSplitViewComponent,
|
protected userProvider: CoreUserProvider,
|
||||||
|
@Optional() protected svComponent: CoreSplitViewComponent,
|
||||||
protected navCtrl: NavController) {
|
protected navCtrl: NavController) {
|
||||||
this.courseId = navParams.get('courseId');
|
this.courseId = navParams.get('courseId');
|
||||||
this.cmId = navParams.get('cmId');
|
this.cmId = navParams.get('cmId');
|
||||||
|
@ -134,7 +136,29 @@ export class AddonModForumDiscussionPage implements OnDestroy {
|
||||||
* View loaded.
|
* View loaded.
|
||||||
*/
|
*/
|
||||||
ionViewDidLoad(): void {
|
ionViewDidLoad(): void {
|
||||||
this.sitesProvider.getCurrentSite().getLocalSiteConfig('AddonModForumDiscussionSort', this.sort).then((value) => {
|
this.sitesProvider.getCurrentSite().getLocalSiteConfig('AddonModForumDiscussionSort').catch(() => {
|
||||||
|
this.userProvider.getUserPreference('forum_displaymode').catch(() => {
|
||||||
|
// Ignore errors.
|
||||||
|
}).then((value) => {
|
||||||
|
const sortValue = value && parseInt(value, 10);
|
||||||
|
|
||||||
|
switch (sortValue) {
|
||||||
|
case 1:
|
||||||
|
this.sort = 'flat-oldest';
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
this.sort = 'flat-newest';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
this.sort = 'nested';
|
||||||
|
break;
|
||||||
|
case 2: // Threaded not implemented.
|
||||||
|
default:
|
||||||
|
// Not set, use default sort.
|
||||||
|
// @TODO add fallback to $CFG->forum_displaymode.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).then((value) => {
|
||||||
this.sort = value;
|
this.sort = value;
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.fetchPosts(true, false, true).then(() => {
|
this.fetchPosts(true, false, true).then(() => {
|
||||||
|
|
Loading…
Reference in New Issue