diff --git a/src/utils/permalinks/RoomPermalinkCreator.js b/src/utils/permalinks/RoomPermalinkCreator.js index aeb7d3b72c..88bcd5768a 100644 --- a/src/utils/permalinks/RoomPermalinkCreator.js +++ b/src/utils/permalinks/RoomPermalinkCreator.js @@ -18,7 +18,7 @@ import MatrixClientPeg from "../../MatrixClientPeg"; import isIp from "is-ip"; import utils from 'matrix-js-sdk/lib/utils'; import SpecPermalinkConstructor, {baseUrl as matrixtoBaseUrl} from "./SpecPermalinkConstructor"; -import PermalinkConstructor from "./PermalinkConstructor"; +import PermalinkConstructor, {PermalinkParts} from "./PermalinkConstructor"; import RiotPermalinkConstructor from "./RiotPermalinkConstructor"; const SdkConfig = require("../../SdkConfig"); @@ -291,6 +291,17 @@ function getPermalinkConstructor(): PermalinkConstructor { return new SpecPermalinkConstructor(); } +export function parsePermalink(fullUrl: string): PermalinkParts { + const riotPrefix = SdkConfig.get()['permalinkPrefix']; + if (fullUrl.startsWith(matrixtoBaseUrl)) { + return new SpecPermalinkConstructor().parsePermalink(fullUrl); + } else if (riotPrefix && fullUrl.startsWith(riotPrefix)) { + return new RiotPermalinkConstructor(riotPrefix).parsePermalink(fullUrl); + } + + return null; // not a permalink we can handle +} + function getServerName(userId) { return userId.split(":").splice(1).join(":"); }