From a074a489f646f7962c790326572a26fe6f419e18 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 10 Jul 2023 13:59:08 +0100 Subject: [PATCH] Linkify mxc:// URLs as links to your media repo --- src/linkify-matrix.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/linkify-matrix.ts b/src/linkify-matrix.ts index 400a3ba1531..5534d785fba 100644 --- a/src/linkify-matrix.ts +++ b/src/linkify-matrix.ts @@ -19,7 +19,7 @@ import * as linkifyjs from "linkifyjs"; import { EventListeners, Opts, registerCustomProtocol, registerPlugin } from "linkifyjs"; import linkifyElement from "linkify-element"; import linkifyString from "linkify-string"; -import { User } from "matrix-js-sdk/src/matrix"; +import { getHttpUriForMxc, User } from "matrix-js-sdk/src/matrix"; import { parsePermalink, @@ -185,6 +185,11 @@ export const options: Opts = { formatHref: function (href: string, type: Type | string): string { switch (type) { + case "url": + if (href.startsWith("mxc://") && MatrixClientPeg.get()) { + return getHttpUriForMxc(MatrixClientPeg.get()!.baseUrl, href); + } + // fallthrough case Type.RoomAlias: case Type.UserId: default: { @@ -244,6 +249,8 @@ registerPlugin(Type.UserId, ({ scanner, parser }) => { registerCustomProtocol("matrix", true); +registerCustomProtocol("mxc", false); + export const linkify = linkifyjs; export const _linkifyElement = linkifyElement; export const _linkifyString = linkifyString;