Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Allow opening external Matrix URIs #7700

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import PerformanceMonitor, { PerformanceEntryNames } from "../../performance";
import UIStore, { UI_EVENTS } from "../../stores/UIStore";
import SoftLogout from './auth/SoftLogout';
import { makeRoomPermalink } from "../../utils/permalinks/Permalinks";
import MatrixSchemePermalinkConstructor from "../../utils/permalinks/MatrixSchemePermalinkConstructor";
import { copyPlaintext } from "../../utils/strings";
import { PosthogAnalytics } from '../../PosthogAnalytics';
import { initSentry } from "../../sentry";
Expand Down Expand Up @@ -1386,6 +1387,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {

StorageManager.tryPersistStorage();

navigator.registerProtocolHandler("matrix", "/#/%s");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

This may want to happen on an in-app user interaction (Toast?) so the user understands the impact, will need @matrix-org/product input

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd like to be consistent with other areas of the app and have a toast first. Redirecting to design for input


if (PosthogAnalytics.instance.isEnabled() && SettingsStore.isLevelSupported(SettingLevel.ACCOUNT)) {
this.initPosthogAnalyticsToast();
} else if (Analytics.canEnable() || CountlyAnalytics.instance.canEnable()) {
Expand Down Expand Up @@ -1895,6 +1898,39 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
action: 'view_group',
group_id: groupId,
});
} else if (screen.indexOf('matrix:') === 0) {
try {
const permalink = new MatrixSchemePermalinkConstructor().parsePermalink(screen);

if (permalink.userId) {
dis.dispatch({
action: 'view_user_info',
userId: permalink.userId,
});
} else if (permalink.roomIdOrAlias) {
const viewRoomPayload = {
action: Action.ViewRoom,
event_id: permalink.eventId,
via_servers: permalink.viaServers,
// If an event ID is given in the URL hash, notify RoomViewStore to mark
// it as highlighted, which will propagate to RoomView and highlight the
// associated EventTile.
highlighted: Boolean(permalink.eventId),
room_alias: undefined,
room_id: undefined,
};
if (permalink.roomIdOrAlias[0] === '#') {
viewRoomPayload.room_alias = permalink.roomIdOrAlias;
} else {
viewRoomPayload.room_id = permalink.roomIdOrAlias;
}

dis.dispatch(viewRoomPayload);
}
} catch {
logger.error("Invalid Matrix URI scheme permalink:", screen);
dis.dispatch({ action: 'view_last_screen' });
}
} else {
logger.info("Ignoring showScreen for '%s'", screen);
}
Expand Down