feat: make `UserNameLabel` render local nick names and ENS names
In timeline status update messages we want to render the ENS name next to a local nickname in case it exists. This commit extends the `UsernameLabel` to do just that. Closes #1488
This commit is contained in:
parent
066fd9f7e5
commit
e11139df12
|
@ -244,7 +244,7 @@ QtObject:
|
||||||
proc pushMessages*(self:ChatsView, messages: var seq[Message]) =
|
proc pushMessages*(self:ChatsView, messages: var seq[Message]) =
|
||||||
for msg in messages.mitems:
|
for msg in messages.mitems:
|
||||||
self.upsertChannel(msg.chatId)
|
self.upsertChannel(msg.chatId)
|
||||||
msg.alias = self.status.chat.getUserName(msg.fromAuthor, msg.alias)
|
msg.userName = self.status.chat.getUserName(msg.fromAuthor, msg.alias)
|
||||||
self.messageList[msg.chatId].add(msg)
|
self.messageList[msg.chatId].add(msg)
|
||||||
self.messagePushed()
|
self.messagePushed()
|
||||||
if self.channelOpenTime.getOrDefault(msg.chatId, high(int64)) < msg.timestamp.parseFloat.fromUnixFloat.toUnix:
|
if self.channelOpenTime.getOrDefault(msg.chatId, high(int64)) < msg.timestamp.parseFloat.fromUnixFloat.toUnix:
|
||||||
|
|
|
@ -33,6 +33,8 @@ type
|
||||||
EmojiReactions = UserRole + 22
|
EmojiReactions = UserRole + 22
|
||||||
CommandParameters = UserRole + 23
|
CommandParameters = UserRole + 23
|
||||||
LinkUrls = UserRole + 24
|
LinkUrls = UserRole + 24
|
||||||
|
Alias = UserRole + 25
|
||||||
|
LocalName = UserRole + 26
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
|
@ -115,7 +117,7 @@ QtObject:
|
||||||
let message = self.messages[index.row]
|
let message = self.messages[index.row]
|
||||||
let chatMessageRole = role.ChatMessageRoles
|
let chatMessageRole = role.ChatMessageRoles
|
||||||
case chatMessageRole:
|
case chatMessageRole:
|
||||||
of ChatMessageRoles.UserName: result = newQVariant(message.alias)
|
of ChatMessageRoles.UserName: result = newQVariant(message.userName)
|
||||||
of ChatMessageRoles.Message: result = newQVariant(self.renderBlock(message))
|
of ChatMessageRoles.Message: result = newQVariant(self.renderBlock(message))
|
||||||
of ChatMessageRoles.PlainText: result = newQVariant(message.text)
|
of ChatMessageRoles.PlainText: result = newQVariant(message.text)
|
||||||
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
|
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
|
||||||
|
@ -149,6 +151,8 @@ QtObject:
|
||||||
"commandState": message.commandParameters.commandState,
|
"commandState": message.commandParameters.commandState,
|
||||||
"signature": message.commandParameters.signature
|
"signature": message.commandParameters.signature
|
||||||
}))
|
}))
|
||||||
|
of ChatMessageRoles.Alias: result = newQVariant(message.alias)
|
||||||
|
of ChatMessageRoles.LocalName: result = newQVariant(message.localName)
|
||||||
|
|
||||||
method roleNames(self: ChatMessageList): Table[int, string] =
|
method roleNames(self: ChatMessageList): Table[int, string] =
|
||||||
{
|
{
|
||||||
|
@ -175,7 +179,9 @@ QtObject:
|
||||||
ChatMessageRoles.AudioDurationMs.int: "audioDurationMs",
|
ChatMessageRoles.AudioDurationMs.int: "audioDurationMs",
|
||||||
ChatMessageRoles.EmojiReactions.int: "emojiReactions",
|
ChatMessageRoles.EmojiReactions.int: "emojiReactions",
|
||||||
ChatMessageRoles.LinkUrls.int: "linkUrls",
|
ChatMessageRoles.LinkUrls.int: "linkUrls",
|
||||||
ChatMessageRoles.CommandParameters.int: "commandParameters"
|
ChatMessageRoles.CommandParameters.int: "commandParameters",
|
||||||
|
ChatMessageRoles.Alias.int:"alias",
|
||||||
|
ChatMessageRoles.LocalName.int:"localName"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc getMessageIndex(self: ChatMessageList, messageId: string): int {.slot.} =
|
proc getMessageIndex(self: ChatMessageList, messageId: string): int {.slot.} =
|
||||||
|
@ -188,7 +194,9 @@ QtObject:
|
||||||
|
|
||||||
let message = self.messages[index]
|
let message = self.messages[index]
|
||||||
case data:
|
case data:
|
||||||
of "userName": result = (message.alias)
|
of "userName": result = (message.userName)
|
||||||
|
of "alias": result = (message.alias)
|
||||||
|
of "localName": result = (message.localName)
|
||||||
of "message": result = (message.text)
|
of "message": result = (message.text)
|
||||||
of "identicon": result = (message.identicon)
|
of "identicon": result = (message.identicon)
|
||||||
of "timestamp": result = $(message.timestamp)
|
of "timestamp": result = $(message.timestamp)
|
||||||
|
@ -246,6 +254,8 @@ QtObject:
|
||||||
for c in contacts:
|
for c in contacts:
|
||||||
for m in self.messages.mitems:
|
for m in self.messages.mitems:
|
||||||
if m.fromAuthor == c.id:
|
if m.fromAuthor == c.id:
|
||||||
m.alias = userNameOrAlias(c)
|
m.userName = userNameOrAlias(c)
|
||||||
|
m.alias = c.alias
|
||||||
|
m.localName = c.localNickname
|
||||||
|
|
||||||
self.dataChanged(topLeft, bottomRight, @[ChatMessageRoles.Username.int])
|
self.dataChanged(topLeft, bottomRight, @[ChatMessageRoles.Username.int])
|
||||||
|
|
|
@ -31,6 +31,8 @@ type CommandParameters* = object
|
||||||
|
|
||||||
type Message* = object
|
type Message* = object
|
||||||
alias*: string
|
alias*: string
|
||||||
|
userName*: string
|
||||||
|
localName*: string
|
||||||
chatId*: string
|
chatId*: string
|
||||||
clock*: int
|
clock*: int
|
||||||
commandParameters*: CommandParameters
|
commandParameters*: CommandParameters
|
||||||
|
|
|
@ -171,6 +171,8 @@ proc toMessage*(jsonMsg: JsonNode): Message =
|
||||||
|
|
||||||
var message = Message(
|
var message = Message(
|
||||||
alias: jsonMsg{"alias"}.getStr,
|
alias: jsonMsg{"alias"}.getStr,
|
||||||
|
userName: "",
|
||||||
|
localName: "",
|
||||||
chatId: jsonMsg{"localChatId"}.getStr,
|
chatId: jsonMsg{"localChatId"}.getStr,
|
||||||
clock: jsonMsg{"clock"}.getInt,
|
clock: jsonMsg{"clock"}.getInt,
|
||||||
contentType: contentType,
|
contentType: contentType,
|
||||||
|
|
|
@ -283,6 +283,8 @@ ScrollView {
|
||||||
fromAuthor: model.fromAuthor
|
fromAuthor: model.fromAuthor
|
||||||
chatId: model.chatId
|
chatId: model.chatId
|
||||||
userName: model.userName
|
userName: model.userName
|
||||||
|
alias: model.alias
|
||||||
|
localName: model.localName
|
||||||
message: model.message
|
message: model.message
|
||||||
plainText: model.plainText
|
plainText: model.plainText
|
||||||
identicon: model.identicon
|
identicon: model.identicon
|
||||||
|
|
|
@ -7,6 +7,8 @@ import "../components"
|
||||||
Item {
|
Item {
|
||||||
property string fromAuthor: "0x0011223344556677889910"
|
property string fromAuthor: "0x0011223344556677889910"
|
||||||
property string userName: "Jotaro Kujo"
|
property string userName: "Jotaro Kujo"
|
||||||
|
property string alias: ""
|
||||||
|
property string localName: ""
|
||||||
property string message: "That's right. We're friends... Of justice, that is."
|
property string message: "That's right. We're friends... Of justice, that is."
|
||||||
property string plainText: "That's right. We're friends... Of justice, that is."
|
property string plainText: "That's right. We're friends... Of justice, that is."
|
||||||
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQAQMAAAC6caSPAAAABlBMVEXMzMz////TjRV2AAAAAWJLR0QB/wIt3gAAACpJREFUGBntwYEAAAAAw6D7Uw/gCtUAAAAAAAAAAAAAAAAAAAAAAAAAgBNPsAABAjKCqQAAAABJRU5ErkJggg=="
|
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQAQMAAAC6caSPAAAABlBMVEXMzMz////TjRV2AAAAAWJLR0QB/wIt3gAAACpJREFUGBntwYEAAAAAw6D7Uw/gCtUAAAAAAAAAAAAAAAAAAAAAAAAAgBNPsAABAjKCqQAAAABJRU5ErkJggg=="
|
||||||
|
|
|
@ -33,6 +33,9 @@ Item {
|
||||||
// anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top
|
// anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: chatImage.right
|
anchors.left: chatImage.right
|
||||||
|
userName: messageItem.userName
|
||||||
|
localName: messageItem.localName
|
||||||
|
alias: messageItem.alias
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatReply {
|
ChatReply {
|
||||||
|
|
|
@ -32,6 +32,9 @@ Item {
|
||||||
anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top
|
anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top
|
||||||
anchors.topMargin: 0
|
anchors.topMargin: 0
|
||||||
anchors.left: chatImage.right
|
anchors.left: chatImage.right
|
||||||
|
userName: messageItem.userName
|
||||||
|
localName: messageItem.localName
|
||||||
|
alias: messageItem.alias
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
|
@ -2,14 +2,34 @@ import QtQuick 2.3
|
||||||
import "../../../../../shared"
|
import "../../../../../shared"
|
||||||
import "../../../../../imports"
|
import "../../../../../imports"
|
||||||
|
|
||||||
StyledTextEdit {
|
Item {
|
||||||
id: chatName
|
id: root
|
||||||
|
height: childrenRect.height
|
||||||
|
width: chatName.width + ensOrAlias.width + ensOrAlias.anchors.leftMargin
|
||||||
|
property string userName: ""
|
||||||
|
property string localName: ""
|
||||||
|
property string alias: ""
|
||||||
|
property alias label: chatName
|
||||||
visible: isMessage && authorCurrentMsg != authorPrevMsg
|
visible: isMessage && authorCurrentMsg != authorPrevMsg
|
||||||
height: this.visible ? 18 : 0
|
|
||||||
//% "You"
|
StyledTextEdit {
|
||||||
text: !isCurrentUser ? Utils.removeStatusEns(userName) : qsTrId("You")
|
id: chatName
|
||||||
color: (userName.startsWith("@") || isCurrentUser) ? Style.current.blue : Style.current.textColor
|
text: {
|
||||||
font.bold: true
|
if (isCurrentUser) {
|
||||||
|
return qsTr("You")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.localName !== "") {
|
||||||
|
return root.localName
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.userName !== "") {
|
||||||
|
return Utils.removeStatusEns(root.userName)
|
||||||
|
}
|
||||||
|
return Utils.removeStatusEns(root.alias)
|
||||||
|
}
|
||||||
|
color: text.startsWith("@") || isCurrentUser || root.localName !== "" ? Style.current.blue : Style.current.secondaryText
|
||||||
|
font.weight: Font.Medium
|
||||||
font.pixelSize: Style.current.secondaryTextFontSize
|
font.pixelSize: Style.current.secondaryTextFontSize
|
||||||
readOnly: true
|
readOnly: true
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
|
@ -18,8 +38,26 @@ StyledTextEdit {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
onEntered: {
|
||||||
|
parent.font.underline = true
|
||||||
|
}
|
||||||
|
onExited: {
|
||||||
|
parent.font.underline = false
|
||||||
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
clickMessage(true)
|
clickMessage(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
id: ensOrAlias
|
||||||
|
visible: root.localName !== "" && root.userName.startsWith("@")
|
||||||
|
text: root.userName
|
||||||
|
color: Style.current.secondaryText
|
||||||
|
font.pixelSize: chatName.font.pixelSize
|
||||||
|
anchors.left: chatName.right
|
||||||
|
anchors.leftMargin: chatName.visible ? 4 : 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,8 +259,8 @@ Item {
|
||||||
|
|
||||||
UsernameLabel {
|
UsernameLabel {
|
||||||
id: chatName
|
id: chatName
|
||||||
text: "@" + (profileModel.ens.preferredUsername.replace(".stateofus.eth", ""))
|
label.text: "@" + (profileModel.ens.preferredUsername.replace(".stateofus.eth", ""))
|
||||||
color: Style.current.blue
|
label.color: Style.current.blue
|
||||||
anchors.leftMargin: 20
|
anchors.leftMargin: 20
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.topMargin: 0
|
anchors.topMargin: 0
|
||||||
|
|
Loading…
Reference in New Issue