Add utility function for permalink parsing

This commit is contained in:
Travis Ralston 2019-09-30 16:04:10 -06:00
parent 9bb1ebb89d
commit 3e5a39d646

View file

@ -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(":");
}