fix(replies): Fire dataChanged when contact changed in reply

Closes: #7687
This commit is contained in:
Boris Melnik 2022-10-07 17:17:24 +03:00 committed by Iuri Matias
parent 7ffb99e724
commit 4cfa4e5451
4 changed files with 43 additions and 2 deletions

View File

@ -430,7 +430,13 @@ QtObject:
if(index < 0 or index >= self.items.len):
return
self.items[index].toJsonNode()
proc updateContactInReplies(self: Model, messageId: string) =
for i in 0 ..< self.items.len:
if (self.items[i].responseToMessageWithId == messageId):
let index = self.createIndex(i, 0, nil)
self.dataChanged(index, index, @[ModelRole.ResponseToMessageWithId.int])
iterator modelContactUpdateIterator*(self: Model, contactId: string): Item =
for i in 0 ..< self.items.len:
yield self.items[i]
@ -451,6 +457,7 @@ QtObject:
if(roles.len > 0):
let index = self.createIndex(i, 0, nil)
self.dataChanged(index, index, roles)
self.updateContactInReplies(self.items[i].id)
proc setEditModeOn*(self: Model, messageId: string) =
let ind = self.findIndexForMessageId(messageId)

View File

@ -240,6 +240,18 @@ Item {
// }
// }
Connections {
target: chatLogView.model
onDataChanged: {
if (roles.indexOf(Constants.messageModelRoles.responseToMessageWithId) !== -1) {
let item = chatLogView.itemAtIndex(topLeft.row)
if (item) {
item.updateReplyInfo()
}
}
}
}
delegate: MessageView {
id: msgDelegate

View File

@ -233,6 +233,18 @@ Loader {
}
}
function updateReplyInfo() {
switch(messageContentType) {
case Constants.messageContentType.chatIdentifier:
case Constants.messageContentType.fetchMoreMessagesButton:
case Constants.messageContentType.systemMessagePrivateGroupType:
case Constants.messageContentType.gapType:
return
default:
item.replyMessage = item.getReplyMessage()
}
}
QtObject {
id: d
@ -396,9 +408,15 @@ Loader {
readonly property int contentType: convertContentType(root.messageContentType)
readonly property bool isReply: root.responseTo !== ""
readonly property var replyMessage: root.messageStore && isReply && root.responseToExistingMessage ? root.messageStore.getMessageByIdAsJson(root.responseTo) : null
property var replyMessage: getReplyMessage()
readonly property string replySenderId: replyMessage ? replyMessage.senderId : ""
function getReplyMessage() {
return root.messageStore && isReply && root.responseToExistingMessage ? root.messageStore.getMessageByIdAsJson(root.responseTo) : null
}
function editCompletedHandler(newMessageText) {
const message = root.rootStore.plainText(StatusQUtils.Emoji.deparse(newMessageText))
if (message.length <= 0)

View File

@ -235,6 +235,10 @@ QtObject {
readonly property int discordMessageType: 12
}
readonly property QtObject messageModelRoles: QtObject {
readonly property int responseToMessageWithId: 262 // ModelRole.ResponseToMessageWithId
}
readonly property QtObject profilePicturesVisibility: QtObject {
readonly property int contactsOnly: 1
readonly property int everyone: 2