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

Commit 6e99b2f

Browse files
authored
Linkify mxc:// URLs as links to your media repo (#11213)
1 parent 7b3d0ad commit 6e99b2f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/linkify-matrix.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as linkifyjs from "linkifyjs";
1919
import { EventListeners, Opts, registerCustomProtocol, registerPlugin } from "linkifyjs";
2020
import linkifyElement from "linkify-element";
2121
import linkifyString from "linkify-string";
22-
import { User } from "matrix-js-sdk/src/matrix";
22+
import { getHttpUriForMxc, User } from "matrix-js-sdk/src/matrix";
2323

2424
import {
2525
parsePermalink,
@@ -186,6 +186,11 @@ export const options: Opts = {
186186

187187
formatHref: function (href: string, type: Type | string): string {
188188
switch (type) {
189+
case "url":
190+
if (href.startsWith("mxc://") && MatrixClientPeg.get()) {
191+
return getHttpUriForMxc(MatrixClientPeg.get()!.baseUrl, href);
192+
}
193+
// fallthrough
189194
case Type.RoomAlias:
190195
case Type.UserId:
191196
default: {
@@ -270,6 +275,8 @@ PERMITTED_URL_SCHEMES.forEach((scheme) => {
270275
}
271276
});
272277

278+
registerCustomProtocol("mxc", false);
279+
273280
export const linkify = linkifyjs;
274281
export const _linkifyElement = linkifyElement;
275282
export const _linkifyString = linkifyString;

0 commit comments

Comments
 (0)