You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-05 23:10:41 +03:00
implement group links in matrixLinkify:MATRIXTO. Simplify if/else w/ map
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -169,11 +169,18 @@ matrixLinkify.VECTOR_URL_PATTERN = "^(?:https?:\/\/)?(?:"
|
|||||||
+ "(?:www\\.)?(?:riot|vector)\\.im/(?:app|beta|staging|develop)/"
|
+ "(?:www\\.)?(?:riot|vector)\\.im/(?:app|beta|staging|develop)/"
|
||||||
+ ")(#.*)";
|
+ ")(#.*)";
|
||||||
|
|
||||||
matrixLinkify.MATRIXTO_URL_PATTERN = "^(?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/((#|@|!).*)";
|
matrixLinkify.MATRIXTO_URL_PATTERN = "^(?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/([#@!+].*)";
|
||||||
matrixLinkify.MATRIXTO_MD_LINK_PATTERN =
|
matrixLinkify.MATRIXTO_MD_LINK_PATTERN =
|
||||||
'\\[([^\\]]*)\\]\\((?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/((#|@|!)[^\\)]*)\\)';
|
'\\[([^\\]]*)\\]\\((?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/([#@!+][^\\)]*)\\)';
|
||||||
matrixLinkify.MATRIXTO_BASE_URL= baseUrl;
|
matrixLinkify.MATRIXTO_BASE_URL= baseUrl;
|
||||||
|
|
||||||
|
const matrixToEntityMap = {
|
||||||
|
'@': '#/user/',
|
||||||
|
'#': '#/room/',
|
||||||
|
'!': '#/room/',
|
||||||
|
'+': '#/group/',
|
||||||
|
};
|
||||||
|
|
||||||
matrixLinkify.options = {
|
matrixLinkify.options = {
|
||||||
events: function(href, type) {
|
events: function(href, type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -204,24 +211,20 @@ matrixLinkify.options = {
|
|||||||
case 'userid':
|
case 'userid':
|
||||||
case 'groupid':
|
case 'groupid':
|
||||||
return matrixLinkify.MATRIXTO_BASE_URL + '/#/' + href;
|
return matrixLinkify.MATRIXTO_BASE_URL + '/#/' + href;
|
||||||
default:
|
default: {
|
||||||
var m;
|
|
||||||
// FIXME: horrible duplication with HtmlUtils' transform tags
|
// FIXME: horrible duplication with HtmlUtils' transform tags
|
||||||
m = href.match(matrixLinkify.VECTOR_URL_PATTERN);
|
let m = href.match(matrixLinkify.VECTOR_URL_PATTERN);
|
||||||
if (m) {
|
if (m) {
|
||||||
return m[1];
|
return m[1];
|
||||||
}
|
}
|
||||||
m = href.match(matrixLinkify.MATRIXTO_URL_PATTERN);
|
m = href.match(matrixLinkify.MATRIXTO_URL_PATTERN);
|
||||||
if (m) {
|
if (m) {
|
||||||
const entity = m[1];
|
const entity = m[1];
|
||||||
if (entity[0] === '@') {
|
if (matrixToEntityMap[entity[0]]) return matrixToEntityMap[entity[0]] + entity;
|
||||||
return '#/user/' + entity;
|
|
||||||
} else if (entity[0] === '#' || entity[0] === '!') {
|
|
||||||
return '#/room/' + entity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return href;
|
return href;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user