Color user mentions

This commit is contained in:
miruka 2020-03-23 13:30:40 -04:00
parent 688f36b7f1
commit 3c64b33cb7
3 changed files with 25 additions and 2 deletions

View File

@ -1,5 +1,8 @@
# TODO
- cpu usage
- room.mentions += 1 key error before registration
## Main goals for next version
- Redacting messages

View File

@ -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 "<style type='text/css'>" + lines.join("\n") + "</style>"
}
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
(

View File

@ -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:
'<style type"text/css">\n' + styleSheet + '\n</style>\n'