Refactor matrix-linkify module (#7279)

Refactor the module to make it easier for upgrade and proper separation of code contexts
This commit is contained in:
Dariusz Niemczyk
2021-12-03 14:00:56 +00:00
committed by GitHub
parent 3b9e39ffca
commit 961fec9081
7 changed files with 99 additions and 206 deletions
+3 -3
View File
@@ -25,10 +25,10 @@ import { MatrixClientPeg } from "../../MatrixClientPeg";
import SpecPermalinkConstructor, { baseUrl as matrixtoBaseUrl } from "./SpecPermalinkConstructor";
import PermalinkConstructor, { PermalinkParts } from "./PermalinkConstructor";
import ElementPermalinkConstructor from "./ElementPermalinkConstructor";
import matrixLinkify from "../../linkify-matrix";
import SdkConfig from "../../SdkConfig";
import { logger } from "matrix-js-sdk/src/logger";
import { ELEMENT_URL_PATTERN } from "../../linkify-matrix";
// The maximum number of servers to pick when working out which servers
// to add to permalinks. The servers are appended as ?via=example.org
@@ -348,7 +348,7 @@ export function tryTransformPermalinkToLocalHref(permalink: string): string {
}
try {
const m = decodeURIComponent(permalink).match(matrixLinkify.ELEMENT_URL_PATTERN);
const m = decodeURIComponent(permalink).match(ELEMENT_URL_PATTERN);
if (m) {
return m[1];
}
@@ -386,7 +386,7 @@ export function getPrimaryPermalinkEntity(permalink: string): string {
// If not a permalink, try the vector patterns.
if (!permalinkParts) {
const m = permalink.match(matrixLinkify.ELEMENT_URL_PATTERN);
const m = permalink.match(ELEMENT_URL_PATTERN);
if (m) {
// A bit of a hack, but it gets the job done
const handler = new ElementPermalinkConstructor("http://localhost");