[MM-19919] Allow links to other servers to go directly to that server in the app (#1165)
* [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
This commit is contained in:
@@ -15,6 +15,8 @@ import DotsVerticalIcon from 'mdi-react/DotsVerticalIcon';
|
|||||||
|
|
||||||
import {ipcRenderer, remote} from 'electron';
|
import {ipcRenderer, remote} from 'electron';
|
||||||
|
|
||||||
|
import Utils from '../../utils/util';
|
||||||
|
|
||||||
import restoreButton from '../../assets/titlebar/chrome-restore.svg';
|
import restoreButton from '../../assets/titlebar/chrome-restore.svg';
|
||||||
import maximizeButton from '../../assets/titlebar/chrome-maximize.svg';
|
import maximizeButton from '../../assets/titlebar/chrome-maximize.svg';
|
||||||
import minimizeButton from '../../assets/titlebar/chrome-minimize.svg';
|
import minimizeButton from '../../assets/titlebar/chrome-minimize.svg';
|
||||||
@@ -369,6 +371,15 @@ export default class MainPage extends React.Component {
|
|||||||
this.handleSelect(key);
|
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 = () => {
|
handleMaximizeState = () => {
|
||||||
const win = remote.getCurrentWindow();
|
const win = remote.getCurrentWindow();
|
||||||
this.setState({maximized: win.isMaximized()});
|
this.setState({maximized: win.isMaximized()});
|
||||||
@@ -713,7 +724,7 @@ export default class MainPage extends React.Component {
|
|||||||
<MattermostView
|
<MattermostView
|
||||||
key={id}
|
key={id}
|
||||||
id={id}
|
id={id}
|
||||||
|
teams={this.props.teams}
|
||||||
useSpellChecker={this.props.useSpellChecker}
|
useSpellChecker={this.props.useSpellChecker}
|
||||||
onSelectSpellCheckerLocale={this.props.onSelectSpellCheckerLocale}
|
onSelectSpellCheckerLocale={this.props.onSelectSpellCheckerLocale}
|
||||||
src={teamUrl}
|
src={teamUrl}
|
||||||
@@ -721,6 +732,7 @@ export default class MainPage extends React.Component {
|
|||||||
onTargetURLChange={self.handleTargetURLChange}
|
onTargetURLChange={self.handleTargetURLChange}
|
||||||
onBadgeChange={handleBadgeChange}
|
onBadgeChange={handleBadgeChange}
|
||||||
onNotificationClick={handleNotificationClick}
|
onNotificationClick={handleNotificationClick}
|
||||||
|
handleInterTeamLink={self.handleInterTeamLink}
|
||||||
ref={id}
|
ref={id}
|
||||||
active={isActive}
|
active={isActive}
|
||||||
/>);
|
/>);
|
||||||
|
@@ -126,8 +126,14 @@ export default class MattermostView extends React.Component {
|
|||||||
shell.openExternal(e.url);
|
shell.openExternal(e.url);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if the link is external, use default os' application.
|
const parsedURL = Utils.parseURL(e.url);
|
||||||
ipcRenderer.send('confirm-protocol', destURL.protocol, 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 = {
|
MattermostView.propTypes = {
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
|
teams: PropTypes.array.isRequired,
|
||||||
withTab: PropTypes.bool,
|
withTab: PropTypes.bool,
|
||||||
onTargetURLChange: PropTypes.func,
|
onTargetURLChange: PropTypes.func,
|
||||||
onBadgeChange: PropTypes.func,
|
onBadgeChange: PropTypes.func,
|
||||||
@@ -369,6 +376,7 @@ MattermostView.propTypes = {
|
|||||||
active: PropTypes.bool,
|
active: PropTypes.bool,
|
||||||
useSpellChecker: PropTypes.bool,
|
useSpellChecker: PropTypes.bool,
|
||||||
onSelectSpellCheckerLocale: PropTypes.func,
|
onSelectSpellCheckerLocale: PropTypes.func,
|
||||||
|
handleInterTeamLink: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* eslint-enable react/no-set-state */
|
/* eslint-enable react/no-set-state */
|
||||||
|
@@ -93,7 +93,7 @@ function getServer(inputURL, teams) {
|
|||||||
|
|
||||||
// check server and subpath matches (without subpath pathname is \ so it always matches)
|
// check server and subpath matches (without subpath pathname is \ so it always matches)
|
||||||
if (parsedServerUrl.origin === parsedURL.origin && parsedURL.pathname.startsWith(parsedServerUrl.pathname)) {
|
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;
|
return null;
|
||||||
|
Reference in New Issue
Block a user