From bdd031eac2b4ea70d43c03c0c11b26a4760405ea Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 10 Feb 2017 15:09:45 +0000 Subject: [PATCH 1/2] Enable branded URLs again by parsing the path client-side Use the first path segment to key off config.teamTokenMap, which contains a mapping to teamTokens. The client then behaves as before, keeping the path in the address bar constant with no redirects required. --- src/components/structures/MatrixChat.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 8fdcf15e1b..75ae51e9e5 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -191,6 +191,17 @@ module.exports = React.createClass({ MatrixClientPeg.opts.initialSyncLimit = this.props.config.sync_timeline_limit; } + // To enable things like riot.im/geektime in a nicer way than rewriting the URL + // and appending a team token query parameter, use the first path segment to + // indicate a team, with "public" team tokens stored in the config teamTokenMap. + let routedTeamToken = null; + if (this.props.config.teamTokenMap) { + const teamName = window.location.pathname.split('/')[1]; + if (this.props.config.teamTokenMap.hasOwnProperty(teamName)) { + routedTeamToken = this.props.config.teamTokenMap[teamName]; + } + } + // Persist the team token across refreshes using sessionStorage. A new window or // tab will not persist sessionStorage, but refreshes will. if (this.props.startingFragmentQueryParams.team_token) { @@ -202,8 +213,13 @@ module.exports = React.createClass({ // Use the locally-stored team token first, then as a fall-back, check to see if // a referral link was used, which will contain a query parameter `team_token`. - this._teamToken = window.localStorage.getItem('mx_team_token') || + this._teamToken = routedTeamToken || + window.localStorage.getItem('mx_team_token') || window.sessionStorage.getItem('mx_team_token'); + + if (this._teamToken) { + console.info(`Team token set to ${this._teamToken}`); + } }, componentDidMount: function() { From 75deb5584495f07247772eb65b42ef68b983b4eb Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 13 Feb 2017 11:48:03 +0000 Subject: [PATCH 2/2] Null check on teamName --- src/components/structures/MatrixChat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 75ae51e9e5..8d08c19001 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -197,7 +197,7 @@ module.exports = React.createClass({ let routedTeamToken = null; if (this.props.config.teamTokenMap) { const teamName = window.location.pathname.split('/')[1]; - if (this.props.config.teamTokenMap.hasOwnProperty(teamName)) { + if (teamName && this.props.config.teamTokenMap.hasOwnProperty(teamName)) { routedTeamToken = this.props.config.teamTokenMap[teamName]; } }