Convert alias links in room header topics to local permalinks
Fixes https://github.com/vector-im/riot-web/issues/12605pull/21833/head
parent
7aba168c34
commit
d820356990
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {baseUrl} from "./utils/permalinks/SpecPermalinkConstructor";
|
import {baseUrl} from "./utils/permalinks/SpecPermalinkConstructor";
|
||||||
import {tryTransformPermalinkToLocalHref} from "./utils/permalinks/Permalinks";
|
import {tryTransformEntityToPermalink, tryTransformPermalinkToLocalHref} from "./utils/permalinks/Permalinks";
|
||||||
|
|
||||||
function matrixLinkify(linkify) {
|
function matrixLinkify(linkify) {
|
||||||
// Text tokens
|
// Text tokens
|
||||||
|
@ -221,7 +221,7 @@ matrixLinkify.options = {
|
||||||
case 'userid':
|
case 'userid':
|
||||||
case 'groupid':
|
case 'groupid':
|
||||||
default: {
|
default: {
|
||||||
return tryTransformPermalinkToLocalHref(href);
|
return tryTransformEntityToPermalink(href);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -290,6 +290,25 @@ export function isPermalinkHost(host: string): boolean {
|
||||||
return getPermalinkConstructor().isPermalinkHost(host);
|
return getPermalinkConstructor().isPermalinkHost(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms an entity (permalink, room alias, user ID, etc) into a local URL
|
||||||
|
* if possible. If the given entity is not found to be valid enough to be converted
|
||||||
|
* then a null value will be returned.
|
||||||
|
* @param {string} entity The entity to transform.
|
||||||
|
* @returns {string|null} The transformed permalink or null if unable.
|
||||||
|
*/
|
||||||
|
export function tryTransformEntityToPermalink(entity: string): string {
|
||||||
|
if (!entity) return null;
|
||||||
|
|
||||||
|
// Check to see if it is a bare entity for starters
|
||||||
|
if (entity[0] === '#' || entity[0] === '!') return makeRoomPermalink(entity);
|
||||||
|
if (entity[0] === '@') return makeUserPermalink(entity);
|
||||||
|
if (entity[0] === '+') return makeGroupPermalink(entity);
|
||||||
|
|
||||||
|
// Then try and merge it into a permalink
|
||||||
|
return tryTransformPermalinkToLocalHref(entity);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms a permalink (or possible permalink) into a local URL if possible. If
|
* Transforms a permalink (or possible permalink) into a local URL if possible. If
|
||||||
* the given permalink is found to not be a permalink, it'll be returned unaltered.
|
* the given permalink is found to not be a permalink, it'll be returned unaltered.
|
||||||
|
|
Loading…
Reference in New Issue