linkify vector.im URLs directly into the app, both from HTML and non-HTML messages
This commit is contained in:
parent
68a391e24b
commit
1aed9ccbf4
2 changed files with 40 additions and 9 deletions
|
@ -98,6 +98,8 @@ function matrixLinkify(linkify) {
|
|||
matrixLinkify.onUserClick = function(e, userId) { e.preventDefault(); };
|
||||
matrixLinkify.onAliasClick = function(e, roomAlias) { e.preventDefault(); };
|
||||
|
||||
matrixLinkify.VECTOR_URL_PATTERN = /(https?:\/\/)?(www\.)?vector\.im\/(beta|staging|develop)?\/(#.*)/;
|
||||
|
||||
matrixLinkify.options = {
|
||||
events: function (href, type) {
|
||||
switch (type) {
|
||||
|
@ -118,14 +120,33 @@ matrixLinkify.options = {
|
|||
|
||||
formatHref: function (href, type) {
|
||||
switch (type) {
|
||||
case 'roomalias':
|
||||
return '#/room/' + href;
|
||||
case 'userid':
|
||||
return '#';
|
||||
default:
|
||||
return href;
|
||||
case 'roomalias':
|
||||
return '#/room/' + href;
|
||||
case 'userid':
|
||||
return '#';
|
||||
case 'url':
|
||||
// intercept vector links directly into the app
|
||||
// FIXME: use matrix.to asap, as this is fragile as sin
|
||||
var m = href.match(matrixLinkify.VECTOR_URL_PATTERN);
|
||||
return m ? m[4] : href;
|
||||
default:
|
||||
return href;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
target: function(href, type) {
|
||||
if (type === 'url') {
|
||||
if (href.match(matrixLinkify.VECTOR_URL_PATTERN)) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return '_blank';
|
||||
}
|
||||
}
|
||||
else {
|
||||
return '_blank';
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = matrixLinkify;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue