Skip to content

Commit

Permalink
chore: Optimize StatusMessageReply using more Loaders
Browse files Browse the repository at this point in the history
also fix the sender display name to respect ensName/nickname

Fixes: #9016
  • Loading branch information
caybro committed Jan 25, 2023
1 parent a8a3f52 commit 8569ea5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ method updateContactDetails*(self: Module, contactId: string) =
item.senderEnsVerified = updatedContact.details.ensVerified
if(item.quotedMessageAuthorDetails.details.id == contactId):
item.quotedMessageAuthorDetails = updatedContact
item.quotedMessageAuthorDisplayName = updatedContact.defaultDisplayName
item.quotedMessageAuthorAvatar = updatedContact.icon
if(item.messageContainsMentions):
let (message, _, err) = self.controller.getMessageDetails(item.id)
if(err.len == 0):
Expand Down
3 changes: 1 addition & 2 deletions src/app/modules/shared_models/message_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ proc initItem*(
if result.quotedMessageAuthorAvatar == "":
result.quotedMessageAuthorAvatar = quotedMessageDiscordMessage.author.avatarUrl
else:
result.quotedMessageAuthorDisplayName = if quotedMessageAuthorDetails.details.localNickname != "": quotedMessageAuthorDetails.details.localNickname
else: quotedMessageAuthorDetails.details.displayName
result.quotedMessageAuthorDisplayName = quotedMessageAuthorDetails.details.userDefaultDisplayName()
result.quotedMessageAuthorAvatar = quotedMessageAuthorDetails.details.image.thumbnail

if contentType == ContentType.DiscordMessage:
Expand Down
4 changes: 2 additions & 2 deletions ui/StatusQ/src/StatusQ/Components/StatusDateGroupLabel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ StatusBaseText {
property double messageTimestamp

readonly property int msInADay: 86400000
readonly property int lastMessageInDays: Math.floor(previousMessageTimestamp / msInADay)
readonly property int currentMessageInDays: Math.floor(messageTimestamp / msInADay)
readonly property int lastMessageInDays: previousMessageTimestamp / msInADay
readonly property int currentMessageInDays: messageTimestamp / msInADay

font.pixelSize: 13
color: Theme.palette.baseColor1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Item {
anchors.fill: parent

RowLayout {
Layout.fillWidth: true

StatusSmartIdenticon {
id: profileImage
Layout.alignment: Qt.AlignTop
Expand All @@ -78,7 +80,7 @@ Item {
acceptedButtons: Qt.LeftButton | Qt.RightButton
anchors.fill: parent
enabled: root.profileClickable
onClicked: replyProfileClicked(this, mouse)
onClicked: root.replyProfileClicked(this, mouse)
}
}
StatusBaseText {
Expand All @@ -89,44 +91,50 @@ Item {
text: replyDetails.amISender ? qsTr("You") : replyDetails.sender.displayName
}
}
// FIXME OPTIMIZE by using Loaders
StatusTextMessage {
objectName: "StatusMessage_replyDetails_textMessage"
Layout.fillWidth: true
textField.font.pixelSize: Theme.secondaryTextFontSize
textField.color: Theme.palette.baseColor1
visible: !!replyDetails.messageText && replyDetails.contentType !== StatusMessage.ContentType.Sticker
allowShowMore: false
stripHtmlTags: true
convertToSingleLine: true
messageDetails: root.replyDetails
}
StatusImageMessage {
Loader {
Layout.fillWidth: true
Layout.preferredHeight: imageAlias.paintedHeight
imageWidth: 56
source: replyDetails.contentType === StatusMessage.ContentType.Image ? replyDetails.messageContent : ""
visible: source
shapeType: StatusImageMessage.ShapeType.ROUNDED
asynchronous: true
active: !!replyDetails.messageText && replyDetails.contentType !== StatusMessage.ContentType.Sticker
visible: active
sourceComponent: StatusTextMessage {
objectName: "StatusMessage_replyDetails_textMessage"
textField.font.pixelSize: Theme.secondaryTextFontSize
textField.color: Theme.palette.baseColor1
allowShowMore: false
stripHtmlTags: true
convertToSingleLine: true
messageDetails: root.replyDetails
}
}
Item {
Loader {
Layout.fillWidth: true
Layout.preferredHeight: 48
Layout.alignment: Qt.AlignLeft
visible: replyDetails.contentType === StatusMessage.ContentType.Sticker
StatusSticker {
asset.width: 48
asset.height: 48
asset.name: replyDetails.messageContent
asset.isImage: true
asynchronous: true
active: replyDetails.contentType === StatusMessage.ContentType.Image
visible: active
sourceComponent: StatusImageMessage {
Layout.fillWidth: true
Layout.preferredHeight: imageAlias.paintedHeight
imageWidth: 56
source: replyDetails.messageContent
shapeType: StatusImageMessage.ShapeType.ROUNDED
}
}
Item {
StatusSticker {
asynchronous: true
active: replyDetails.contentType === StatusMessage.ContentType.Sticker
visible: active
asset.width: 48
asset.height: 48
asset.name: replyDetails.messageContent
asset.isImage: true
}
Loader {
Layout.fillWidth: true
Layout.preferredHeight: 22
visible: replyDetails.contentType === StatusMessage.ContentType.Audio
StatusAudioMessage {
id: audioMessage
asynchronous: true
active: replyDetails.contentType === StatusMessage.ContentType.Audio
visible: active
sourceComponent: StatusAudioMessage {
anchors.left: parent.left
width: 125
height: 22
Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Chat/panels/UserListPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Item {
messageContextMenu.isProfile = true
messageContextMenu.myPublicKey = userProfile.pubKey
messageContextMenu.selectedUserPublicKey = model.pubKey
messageContextMenu.selectedUserDisplayName = nickName || userName
messageContextMenu.selectedUserDisplayName = title
messageContextMenu.selectedUserIcon = model.icon
messageContextMenu.popup(4, 4)
} else if (mouse.button === Qt.LeftButton && !!messageContextMenu) {
Expand Down
2 changes: 1 addition & 1 deletion ui/imports/shared/views/chat/MessageView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Loader {
property string prevMessageSenderId: prevMessageAsJsonObj ? prevMessageAsJsonObj.senderId : ""
property var prevMessageAsJsonObj
property int nextMessageIndex: -1
property int nextMessageTimestamp: nextMessageAsJsonObj ? nextMessageAsJsonObj.timestamp : 0
property double nextMessageTimestamp: nextMessageAsJsonObj ? nextMessageAsJsonObj.timestamp : 0
property var nextMessageAsJsonObj

property bool editModeOn: false
Expand Down

0 comments on commit 8569ea5

Please sign in to comment.