1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-08-07 21:23:00 +03:00

Linkify mxc:// URLs as links to your media repo (#11213)

This commit is contained in:
Michael Telatynski
2023-07-11 08:25:51 +01:00
committed by GitHub
parent 7b3d0ad209
commit 6e99b2fca3

View File

@@ -19,7 +19,7 @@ import * as linkifyjs from "linkifyjs";
import { EventListeners, Opts, registerCustomProtocol, registerPlugin } from "linkifyjs"; import { EventListeners, Opts, registerCustomProtocol, registerPlugin } from "linkifyjs";
import linkifyElement from "linkify-element"; import linkifyElement from "linkify-element";
import linkifyString from "linkify-string"; import linkifyString from "linkify-string";
import { User } from "matrix-js-sdk/src/matrix"; import { getHttpUriForMxc, User } from "matrix-js-sdk/src/matrix";
import { import {
parsePermalink, parsePermalink,
@@ -186,6 +186,11 @@ export const options: Opts = {
formatHref: function (href: string, type: Type | string): string { formatHref: function (href: string, type: Type | string): string {
switch (type) { switch (type) {
case "url":
if (href.startsWith("mxc://") && MatrixClientPeg.get()) {
return getHttpUriForMxc(MatrixClientPeg.get()!.baseUrl, href);
}
// fallthrough
case Type.RoomAlias: case Type.RoomAlias:
case Type.UserId: case Type.UserId:
default: { default: {
@@ -270,6 +275,8 @@ PERMITTED_URL_SCHEMES.forEach((scheme) => {
} }
}); });
registerCustomProtocol("mxc", false);
export const linkify = linkifyjs; export const linkify = linkifyjs;
export const _linkifyElement = linkifyElement; export const _linkifyElement = linkifyElement;
export const _linkifyString = linkifyString; export const _linkifyString = linkifyString;