From 4bd67f17f1dd54ce3785f10e818bd948f7444510 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Thu, 23 Jan 2020 11:49:14 -0500 Subject: [PATCH] [MM-19919] Allow links to other servers to go directly to that server in the app (#1165) (#1166) * [MM-19919] Allow links to other servers to go directly to that server in the app * Added index to getSerrver() and used that for handling inter team links --- src/browser/components/MainPage.jsx | 14 +++++++++++++- src/browser/components/MattermostView.jsx | 12 ++++++++++-- src/utils/util.js | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/browser/components/MainPage.jsx b/src/browser/components/MainPage.jsx index 4528d02c829..a7942ee4478 100644 --- a/src/browser/components/MainPage.jsx +++ b/src/browser/components/MainPage.jsx @@ -15,6 +15,8 @@ import DotsVerticalIcon from 'mdi-react/DotsVerticalIcon'; import {ipcRenderer, remote} from 'electron'; +import Utils from '../../utils/util'; + import restoreButton from '../../assets/titlebar/chrome-restore.svg'; import maximizeButton from '../../assets/titlebar/chrome-maximize.svg'; import minimizeButton from '../../assets/titlebar/chrome-minimize.svg'; @@ -369,6 +371,15 @@ export default class MainPage extends React.Component { this.handleSelect(key); }; + handleInterTeamLink = (linkUrl) => { + const selectedTeam = Utils.getServer(linkUrl, this.props.teams); + if (!selectedTeam) { + return; + } + this.refs[`mattermostView${selectedTeam.index}`].handleDeepLink(linkUrl.href); + this.setState({key: selectedTeam.index}); + } + handleMaximizeState = () => { const win = remote.getCurrentWindow(); this.setState({maximized: win.isMaximized()}); @@ -713,7 +724,7 @@ export default class MainPage extends React.Component { ); diff --git a/src/browser/components/MattermostView.jsx b/src/browser/components/MattermostView.jsx index a4ed429b386..8e1ec4ab2db 100644 --- a/src/browser/components/MattermostView.jsx +++ b/src/browser/components/MattermostView.jsx @@ -126,8 +126,14 @@ export default class MattermostView extends React.Component { shell.openExternal(e.url); } } else { - // if the link is external, use default os' application. - ipcRenderer.send('confirm-protocol', destURL.protocol, e.url); + const parsedURL = Utils.parseURL(e.url); + const serverURL = Utils.getServer(parsedURL, this.props.teams); + if (serverURL !== null && Utils.isTeamUrl(serverURL.url, parsedURL)) { + this.props.handleInterTeamLink(parsedURL); + } else { + // if the link is external, use default os' application. + ipcRenderer.send('confirm-protocol', destURL.protocol, e.url); + } } }); @@ -362,6 +368,7 @@ export default class MattermostView extends React.Component { MattermostView.propTypes = { name: PropTypes.string, id: PropTypes.string, + teams: PropTypes.array.isRequired, withTab: PropTypes.bool, onTargetURLChange: PropTypes.func, onBadgeChange: PropTypes.func, @@ -369,6 +376,7 @@ MattermostView.propTypes = { active: PropTypes.bool, useSpellChecker: PropTypes.bool, onSelectSpellCheckerLocale: PropTypes.func, + handleInterTeamLink: PropTypes.func, }; /* eslint-enable react/no-set-state */ diff --git a/src/utils/util.js b/src/utils/util.js index aa25957fcbf..46795732bd6 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -93,7 +93,7 @@ function getServer(inputURL, teams) { // check server and subpath matches (without subpath pathname is \ so it always matches) if (parsedServerUrl.origin === parsedURL.origin && parsedURL.pathname.startsWith(parsedServerUrl.pathname)) { - return {name: teams[i].name, url: parsedServerUrl}; + return {name: teams[i].name, url: parsedServerUrl, index: i}; } } return null;