From eb8de9c2c2fc3e0ea149944e49f42e15006d1eab Mon Sep 17 00:00:00 2001 From: Fabien Quatravaux Date: Sun, 12 Apr 2020 11:51:41 +0200 Subject: [PATCH 1/3] [dev] Reflect channel change in URL It means that if I go to a channel and refresh the page, I will be reconnected to this channel after refresh. --- app/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/index.js b/app/index.js index 15737e9..4d7f4f0 100644 --- a/app/index.js +++ b/app/index.js @@ -784,6 +784,11 @@ class GlobalBindings { this.requestMove = (user, channel) => { if (this.connected()) { user.model.setChannel(channel.model) + // reflect this change in URL + let currentUrl = url.parse(document.location.href, true) + currentUrl.query.channelName = channel.name() + delete currentUrl.search + window.history.pushState(null, channel.name(), url.format(currentUrl)) } } From b6237e86a665ffc78e5b2dad8437a1fb9b1bcbbf Mon Sep 17 00:00:00 2001 From: Fabien Quatravaux Date: Sat, 25 Apr 2020 13:25:24 +0200 Subject: [PATCH 2/3] [fix] Take care of subchannels --- app/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/index.js b/app/index.js index 4d7f4f0..0e8bafa 100644 --- a/app/index.js +++ b/app/index.js @@ -784,9 +784,18 @@ class GlobalBindings { this.requestMove = (user, channel) => { if (this.connected()) { user.model.setChannel(channel.model) + + // get full channel path + let path = channel.name() + let parent = channel.parent() + while( parent.name && parent.name() != 'Root' ){ + path = parent.name() + '/' + path + parent = parent.parent() + } // reflect this change in URL let currentUrl = url.parse(document.location.href, true) - currentUrl.query.channelName = channel.name() + currentUrl.query.channelName = path + // delete search param so that query one can be taken into account delete currentUrl.search window.history.pushState(null, channel.name(), url.format(currentUrl)) } From c0f030996627b03c1c98c232949be6377fda2f98 Mon Sep 17 00:00:00 2001 From: Fabien Quatravaux Date: Sat, 25 Apr 2020 14:39:15 +0200 Subject: [PATCH 3/3] [fix] Take care of Root channel --- app/index.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/index.js b/app/index.js index 0e8bafa..c83bec2 100644 --- a/app/index.js +++ b/app/index.js @@ -785,18 +785,24 @@ class GlobalBindings { if (this.connected()) { user.model.setChannel(channel.model) - // get full channel path - let path = channel.name() - let parent = channel.parent() - while( parent.name && parent.name() != 'Root' ){ - path = parent.name() + '/' + path - parent = parent.parent() - } - // reflect this change in URL let currentUrl = url.parse(document.location.href, true) - currentUrl.query.channelName = path // delete search param so that query one can be taken into account delete currentUrl.search + + // get full channel path + if( channel.parent() ){ // in case this channel is not Root + let parent = channel.parent() + currentUrl.query.channelName = channel.name() + while( parent.parent() ){ + currentUrl.query.channelName = parent.name() + '/' + currentUrl.query.channelName + parent = parent.parent() + } + } else { + // there is no channelName as we moved to Root + delete currentUrl.query.channelName + } + + // reflect this change in URL window.history.pushState(null, channel.name(), url.format(currentUrl)) } }