MOBILE-3631 messages: Fix splitview + route params subscription loop

main
Pau Ferrer Ocaña 2021-02-01 12:03:55 +01:00
parent cf2ea354a2
commit dce706be42
4 changed files with 30 additions and 21 deletions

View File

@ -166,16 +166,15 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
* Setup code for the page. * Setup code for the page.
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.route.queryParams.subscribe(async () => {
// Disable the profile button if we're already coming from a profile. // Disable the profile button if we're already coming from a profile.
const backViewPage = CoreNavigator.instance.getPreviousPath(); const backViewPage = CoreNavigator.instance.getPreviousPath();
this.showInfo = !backViewPage || !CoreTextUtils.instance.matchesGlob(backViewPage, '**/user/profile'); this.showInfo = !backViewPage || !CoreTextUtils.instance.matchesGlob(backViewPage, '**/user/profile');
this.route.queryParams.subscribe(async (params) => {
this.loaded = false; this.loaded = false;
this.conversationId = CoreNavigator.instance.getRouteNumberParam('conversationId') || undefined; this.conversationId = CoreNavigator.instance.getRouteNumberParam('conversationId', params) || undefined;
this.userId = CoreNavigator.instance.getRouteNumberParam('userId') || undefined; this.userId = CoreNavigator.instance.getRouteNumberParam('userId', params) || undefined;
this.showKeyboard = CoreNavigator.instance.getRouteBooleanParam('showKeyboard') || false; this.showKeyboard = CoreNavigator.instance.getRouteBooleanParam('showKeyboard', params) || false;
await this.fetchData(); await this.fetchData();

View File

@ -146,9 +146,9 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy {
* Component loaded. * Component loaded.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.route.queryParams.subscribe(async () => { this.route.queryParams.subscribe(async (params) => {
const discussionUserId = CoreNavigator.instance.getRouteNumberParam('discussionUserId') || const discussionUserId = CoreNavigator.instance.getRouteNumberParam('discussionUserId', params) ||
CoreNavigator.instance.getRouteNumberParam('userId') || undefined; CoreNavigator.instance.getRouteNumberParam('userId', params) || undefined;
if (this.loaded && this.discussionUserId == discussionUserId) { if (this.loaded && this.discussionUserId == discussionUserId) {
return; return;

View File

@ -280,11 +280,11 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
* Component loaded. * Component loaded.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.route.queryParams.subscribe(async () => { this.route.queryParams.subscribe(async (params) => {
// Conversation to load. // Conversation to load.
this.conversationId = CoreNavigator.instance.getRouteNumberParam('conversationId') || undefined; this.conversationId = CoreNavigator.instance.getRouteNumberParam('conversationId', params) || undefined;
if (!this.conversationId) { if (!this.conversationId) {
this.discussionUserId = CoreNavigator.instance.getRouteNumberParam('discussionUserId') || undefined; this.discussionUserId = CoreNavigator.instance.getRouteNumberParam('discussionUserId', params) || undefined;
} }
if (this.conversationId || this.discussionUserId) { if (this.conversationId || this.discussionUserId) {

View File

@ -241,9 +241,19 @@ export class CoreNavigatorService {
* @param name Name of the parameter. * @param name Name of the parameter.
* @return Value of the parameter, undefined if not found. * @return Value of the parameter, undefined if not found.
*/ */
getRouteParam<T = unknown>(name: string): T | undefined { getRouteParam<T = unknown>(name: string, params?: Params): T | undefined {
let value: any;
if (!params) {
const route = this.getCurrentRoute(); const route = this.getCurrentRoute();
const value = route.snapshot.queryParams[name] ?? route.snapshot.params[name]; if (!route.snapshot) {
return;
}
value = route.snapshot.queryParams[name] ?? route.snapshot.params[name];
} else {
value = params[name];
}
const storedParam = this.storedParams[value]; const storedParam = this.storedParams[value];
// Remove the parameter from our map if it's in there. // Remove the parameter from our map if it's in there.
@ -259,8 +269,8 @@ export class CoreNavigatorService {
* @param name Name of the parameter. * @param name Name of the parameter.
* @return Value of the parameter, undefined if not found. * @return Value of the parameter, undefined if not found.
*/ */
getRouteNumberParam(name: string): number | undefined { getRouteNumberParam(name: string, params?: Params): number | undefined {
const value = this.getRouteParam<string>(name); const value = this.getRouteParam<string>(name, params);
return value !== undefined ? Number(value) : value; return value !== undefined ? Number(value) : value;
} }
@ -272,8 +282,8 @@ export class CoreNavigatorService {
* @param name Name of the parameter. * @param name Name of the parameter.
* @return Value of the parameter, undefined if not found. * @return Value of the parameter, undefined if not found.
*/ */
getRouteBooleanParam(name: string): boolean | undefined { getRouteBooleanParam(name: string, params?: Params): boolean | undefined {
const value = this.getRouteParam<string>(name); const value = this.getRouteParam<string>(name, params);
return value !== undefined ? Boolean(value) : value; return value !== undefined ? Boolean(value) : value;
} }