MOBILE-3509 forum: Support parent param in discussion links

main
Dani Palou 2020-08-04 12:09:26 +02:00
parent fc86308b21
commit 8b45f1c624
2 changed files with 46 additions and 26 deletions

View File

@ -85,6 +85,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
protected forumId: number; protected forumId: number;
protected postId: number; protected postId: number;
protected parent: number;
protected onlineObserver: any; protected onlineObserver: any;
protected syncObserver: any; protected syncObserver: any;
protected syncManualObserver: any; protected syncManualObserver: any;
@ -120,6 +121,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
this.discussionId = this.discussion ? this.discussion.discussion : navParams.get('discussionId'); this.discussionId = this.discussion ? this.discussion.discussion : navParams.get('discussionId');
this.trackPosts = navParams.get('trackPosts'); this.trackPosts = navParams.get('trackPosts');
this.postId = navParams.get('postId'); this.postId = navParams.get('postId');
this.parent = navParams.get('parent');
this.isOnline = this.appProvider.isOnline(); this.isOnline = this.appProvider.isOnline();
this.onlineObserver = network.onchange().subscribe(() => { this.onlineObserver = network.onchange().subscribe(() => {
@ -136,41 +138,56 @@ export class AddonModForumDiscussionPage implements OnDestroy {
/** /**
* View loaded. * View loaded.
*/ */
ionViewDidLoad(): void { async ionViewDidLoad(): Promise<void> {
this.sitesProvider.getCurrentSite().getLocalSiteConfig('AddonModForumDiscussionSort').catch(() => { if (this.parent) {
this.userProvider.getUserPreference('forum_displaymode').catch(() => { this.sort = 'nested'; // Force nested order.
// Ignore errors. } else {
}).then((value) => { this.sort = await this.getUserSort();
const sortValue = value && parseInt(value, 10); }
switch (sortValue) { await this.fetchPosts(true, false, true);
const scrollTo = this.postId || this.parent;
if (scrollTo) {
// Scroll to the post.
setTimeout(() => {
this.domUtils.scrollToElementBySelector(this.content, '#addon-mod_forum-post-' + scrollTo);
});
}
}
/**
* Get sort type configured by the current user.
*
* @return Promise resolved with the sort type.
*/
protected async getUserSort(): Promise<SortType> {
try {
const value = await this.sitesProvider.getCurrentSite().getLocalSiteConfig('AddonModForumDiscussionSort');
return value;
} catch (error) {
try {
const value = await this.userProvider.getUserPreference('forum_displaymode');
switch (Number(value)) {
case 1: case 1:
this.sort = 'flat-oldest'; return 'flat-oldest';
break;
case -1: case -1:
this.sort = 'flat-newest'; return 'flat-newest';
break;
case 3: case 3:
this.sort = 'nested'; return 'nested';
break;
case 2: // Threaded not implemented. case 2: // Threaded not implemented.
default: default:
// Not set, use default sort. // Not set, use default sort.
// @TODO add fallback to $CFG->forum_displaymode. // @TODO add fallback to $CFG->forum_displaymode.
} }
}); } catch (error) {
}).then((value) => { // Ignore errors.
this.sort = value; }
}).finally(() => { }
this.fetchPosts(true, false, true).then(() => {
if (this.postId) { return 'flat-oldest';
// Scroll to the post.
setTimeout(() => {
this.domUtils.scrollToElementBySelector(this.content, '#addon-mod_forum-post-' + this.postId);
});
}
});
});
} }
/** /**

View File

@ -60,6 +60,9 @@ export class AddonModForumDiscussionLinkHandler extends CoreContentLinksHandlerB
if (data.postid || params.urlHash) { if (data.postid || params.urlHash) {
pageParams.postId = parseInt(data.postid || params.urlHash.replace('p', '')); pageParams.postId = parseInt(data.postid || params.urlHash.replace('p', ''));
} }
if (params.parent) {
pageParams.parent = parseInt(params.parent);
}
this.linkHelper.goInSite(navCtrl, 'AddonModForumDiscussionPage', pageParams, siteId); this.linkHelper.goInSite(navCtrl, 'AddonModForumDiscussionPage', pageParams, siteId);
} }