From 3c64b33cb76aa7899f0d14c3a7f1b85769eaad14 Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 23 Mar 2020 13:30:40 -0400 Subject: [PATCH] Color user mentions --- TODO.md | 3 +++ src/gui/Pages/Chat/Timeline/EventContent.qml | 20 +++++++++++++++++++- src/themes/Midnight.qpl | 4 +++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 70784cf5..53bf8ff8 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,8 @@ # TODO +- cpu usage +- room.mentions += 1 key error before registration + ## Main goals for next version - Redacting messages diff --git a/src/gui/Pages/Chat/Timeline/EventContent.qml b/src/gui/Pages/Chat/Timeline/EventContent.qml index fc51bfb7..ae9d1c1e 100644 --- a/src/gui/Pages/Chat/Timeline/EventContent.qml +++ b/src/gui/Pages/Chat/Timeline/EventContent.qml @@ -11,6 +11,24 @@ HRowLayout { layoutDirection: onRight ? Qt.RightToLeft: Qt.LeftToRight + readonly property var mentions: JSON.parse(model.mentions) + + readonly property string mentionsCSS: { + const lines = [] + + for (const [name, link] of mentions) { + if (name.startsWith("#") || name.startsWith("!")) continue + + lines.push( + `.mention[data-mention='${name}'] { color: ` + + utils.nameColor(name) + + "}" + ) + } + + return "" + } + readonly property string senderText: hideNameLine ? "" : ( `<${smallAvatar ? "span" : "div"} class='sender'>` + @@ -109,7 +127,7 @@ HRowLayout { textFormat: Text.RichText text: // CSS - theme.chat.message.styleInclude + + theme.chat.message.styleInclude + mentionsCSS + // Sender name & message body ( diff --git a/src/themes/Midnight.qpl b/src/themes/Midnight.qpl index a0069664..bfa54b52 100644 --- a/src/themes/Midnight.qpl +++ b/src/themes/Midnight.qpl @@ -388,7 +388,9 @@ chat: "h6 { font-size: " + fontSize.smaller + "px }" + ".sender { margin-bottom: " + spacing / 2 + " }" + - ".quote { color: " + quote + " }" + ".quote { color: " + quote + " }" + + + ".mention { text-decoration: none; }" string styleInclude: '\n'