diff --git a/src/addons/messages/pages/discussion/discussion.page.ts b/src/addons/messages/pages/discussion/discussion.page.ts index fc51c4034..eeaab6792 100644 --- a/src/addons/messages/pages/discussion/discussion.page.ts +++ b/src/addons/messages/pages/discussion/discussion.page.ts @@ -166,16 +166,15 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView * Setup code for the page. */ async ngOnInit(): Promise { + // Disable the profile button if we're already coming from a profile. + const backViewPage = CoreNavigator.instance.getPreviousPath(); + this.showInfo = !backViewPage || !CoreTextUtils.instance.matchesGlob(backViewPage, '**/user/profile'); - this.route.queryParams.subscribe(async () => { - // Disable the profile button if we're already coming from a profile. - const backViewPage = CoreNavigator.instance.getPreviousPath(); - this.showInfo = !backViewPage || !CoreTextUtils.instance.matchesGlob(backViewPage, '**/user/profile'); - + this.route.queryParams.subscribe(async (params) => { this.loaded = false; - this.conversationId = CoreNavigator.instance.getRouteNumberParam('conversationId') || undefined; - this.userId = CoreNavigator.instance.getRouteNumberParam('userId') || undefined; - this.showKeyboard = CoreNavigator.instance.getRouteBooleanParam('showKeyboard') || false; + this.conversationId = CoreNavigator.instance.getRouteNumberParam('conversationId', params) || undefined; + this.userId = CoreNavigator.instance.getRouteNumberParam('userId', params) || undefined; + this.showKeyboard = CoreNavigator.instance.getRouteBooleanParam('showKeyboard', params) || false; await this.fetchData(); diff --git a/src/addons/messages/pages/discussions-35/discussions.page.ts b/src/addons/messages/pages/discussions-35/discussions.page.ts index f8ca2fe7e..613a08974 100644 --- a/src/addons/messages/pages/discussions-35/discussions.page.ts +++ b/src/addons/messages/pages/discussions-35/discussions.page.ts @@ -146,9 +146,9 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy { * Component loaded. */ ngOnInit(): void { - this.route.queryParams.subscribe(async () => { - const discussionUserId = CoreNavigator.instance.getRouteNumberParam('discussionUserId') || - CoreNavigator.instance.getRouteNumberParam('userId') || undefined; + this.route.queryParams.subscribe(async (params) => { + const discussionUserId = CoreNavigator.instance.getRouteNumberParam('discussionUserId', params) || + CoreNavigator.instance.getRouteNumberParam('userId', params) || undefined; if (this.loaded && this.discussionUserId == discussionUserId) { return; diff --git a/src/addons/messages/pages/group-conversations/group-conversations.page.ts b/src/addons/messages/pages/group-conversations/group-conversations.page.ts index 40af29f07..b367b472d 100644 --- a/src/addons/messages/pages/group-conversations/group-conversations.page.ts +++ b/src/addons/messages/pages/group-conversations/group-conversations.page.ts @@ -280,11 +280,11 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy { * Component loaded. */ ngOnInit(): void { - this.route.queryParams.subscribe(async () => { + this.route.queryParams.subscribe(async (params) => { // Conversation to load. - this.conversationId = CoreNavigator.instance.getRouteNumberParam('conversationId') || undefined; + this.conversationId = CoreNavigator.instance.getRouteNumberParam('conversationId', params) || undefined; if (!this.conversationId) { - this.discussionUserId = CoreNavigator.instance.getRouteNumberParam('discussionUserId') || undefined; + this.discussionUserId = CoreNavigator.instance.getRouteNumberParam('discussionUserId', params) || undefined; } if (this.conversationId || this.discussionUserId) { diff --git a/src/core/services/navigator.ts b/src/core/services/navigator.ts index 431ec6132..79e32efcd 100644 --- a/src/core/services/navigator.ts +++ b/src/core/services/navigator.ts @@ -241,9 +241,19 @@ export class CoreNavigatorService { * @param name Name of the parameter. * @return Value of the parameter, undefined if not found. */ - getRouteParam(name: string): T | undefined { - const route = this.getCurrentRoute(); - const value = route.snapshot.queryParams[name] ?? route.snapshot.params[name]; + getRouteParam(name: string, params?: Params): T | undefined { + let value: any; + + if (!params) { + const route = this.getCurrentRoute(); + if (!route.snapshot) { + return; + } + + value = route.snapshot.queryParams[name] ?? route.snapshot.params[name]; + } else { + value = params[name]; + } const storedParam = this.storedParams[value]; // Remove the parameter from our map if it's in there. @@ -259,8 +269,8 @@ export class CoreNavigatorService { * @param name Name of the parameter. * @return Value of the parameter, undefined if not found. */ - getRouteNumberParam(name: string): number | undefined { - const value = this.getRouteParam(name); + getRouteNumberParam(name: string, params?: Params): number | undefined { + const value = this.getRouteParam(name, params); return value !== undefined ? Number(value) : value; } @@ -272,8 +282,8 @@ export class CoreNavigatorService { * @param name Name of the parameter. * @return Value of the parameter, undefined if not found. */ - getRouteBooleanParam(name: string): boolean | undefined { - const value = this.getRouteParam(name); + getRouteBooleanParam(name: string, params?: Params): boolean | undefined { + const value = this.getRouteParam(name, params); return value !== undefined ? Boolean(value) : value; }