Fix rendering of custom emoticons
This commit is contained in:
@@ -11,21 +11,11 @@ import org.kde.neochat 1.0
|
||||
|
||||
RowLayout {
|
||||
id: row
|
||||
readonly property var customEmojiLinksRegex: /data-mx-emoticon="" src="(\bhttps?:\/\/[^\s\<\>\"\']*[^\s\<\>\"\'])/g
|
||||
readonly property var customEmojiLinks: {
|
||||
let links = [];
|
||||
// we need all this because QML JS doesn't support String.matchAll introduced in ECMAScript 2020
|
||||
let match = customEmojiLinksRegex.exec(model.display);
|
||||
while (match !== null) {
|
||||
links.push(match[1])
|
||||
match = customEmojiLinksRegex.exec(model.display);
|
||||
}
|
||||
return links;
|
||||
}
|
||||
property var links: model.display.match(/(\bhttps?:\/\/[^\s\<\>\"\']*[^\s\<\>\"\'])/g)
|
||||
|
||||
property var links: model.display.match(/\bhttps?:\/\/[^\s\<\>\"\']+/g)
|
||||
// don't show previews for room links or user mentions or custom emojis
|
||||
.filter(link => !(
|
||||
link.includes("https://matrix.to") || (customEmojiLinks && customEmojiLinks.includes(link))
|
||||
link.includes("https://matrix.to") || link.includes("/_matrix/media/r0/download/")
|
||||
))
|
||||
// remove ending fullstops and commas
|
||||
.map(link => (link.length && [".", ","].includes(link[link.length-1])) ? link.substring(0, link.length-1) : link)
|
||||
|
||||
@@ -16,22 +16,10 @@ TextEdit {
|
||||
|
||||
property bool isEmote: false
|
||||
|
||||
/* Turn all links which aren't already in <a> tags into <a> hyperlinks */
|
||||
readonly property var customEmojiLinksRegex: /data-mx-emoticon="" src="(\bhttps?:\/\/[^\s\<\>\"\']*[^\s\<\>\"\'])/g
|
||||
readonly property var customEmojiLinks: {
|
||||
let links = [];
|
||||
// we need all this because QML JS doesn't support String.matchAll introduced in ECMAScript 2020
|
||||
let match = customEmojiLinksRegex.exec(model.display);
|
||||
while (match !== null) {
|
||||
links.push(match[1])
|
||||
match = customEmojiLinksRegex.exec(model.display);
|
||||
}
|
||||
return links;
|
||||
}
|
||||
readonly property var linkRegex: /(href=["'])?(\b(https?):\/\/[^\s\<\>\"\'\\]+)/g
|
||||
property string textMessage: model.display.includes("http")
|
||||
? model.display.replace(linkRegex, function() {
|
||||
if (customEmojiLinks && customEmojiLinks.includes(arguments[0])) {
|
||||
if (arguments[0].includes("/_matrix/media/r0/download/")) {
|
||||
return arguments[0];
|
||||
}
|
||||
if (arguments[1]) {
|
||||
|
||||
Reference in New Issue
Block a user