Skip to content

Commit

Permalink
[MM-19919] Allow links to other servers to go directly to that server…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
devinbinnie committed Jan 23, 2020
1 parent d7b4894 commit 4bd67f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/browser/components/MainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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()});
Expand Down Expand Up @@ -713,14 +724,15 @@ export default class MainPage extends React.Component {
<MattermostView
key={id}
id={id}

teams={this.props.teams}
useSpellChecker={this.props.useSpellChecker}
onSelectSpellCheckerLocale={this.props.onSelectSpellCheckerLocale}
src={teamUrl}
name={team.name}
onTargetURLChange={self.handleTargetURLChange}
onBadgeChange={handleBadgeChange}
onNotificationClick={handleNotificationClick}
handleInterTeamLink={self.handleInterTeamLink}
ref={id}
active={isActive}
/>);
Expand Down
12 changes: 10 additions & 2 deletions src/browser/components/MattermostView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});

Expand Down Expand Up @@ -362,13 +368,15 @@ 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,
src: PropTypes.string,
active: PropTypes.bool,
useSpellChecker: PropTypes.bool,
onSelectSpellCheckerLocale: PropTypes.func,
handleInterTeamLink: PropTypes.func,
};

/* eslint-enable react/no-set-state */
2 changes: 1 addition & 1 deletion src/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4bd67f1

Please sign in to comment.