diff --git a/src/qml/Component/Timeline/LinkPreviewDelegate.qml b/src/qml/Component/Timeline/LinkPreviewDelegate.qml index 20b103510..d6699c7e7 100644 --- a/src/qml/Component/Timeline/LinkPreviewDelegate.qml +++ b/src/qml/Component/Timeline/LinkPreviewDelegate.qml @@ -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) diff --git a/src/qml/Component/Timeline/RichLabel.qml b/src/qml/Component/Timeline/RichLabel.qml index 843915643..3c512a14a 100644 --- a/src/qml/Component/Timeline/RichLabel.qml +++ b/src/qml/Component/Timeline/RichLabel.qml @@ -16,22 +16,10 @@ TextEdit { property bool isEmote: false - /* Turn all links which aren't already in tags into 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]) {