fix(@dekstop/chat): editing a message does not update the reply

Fixes #4891
This commit is contained in:
Sale Djenic 2022-03-09 11:02:28 +01:00 committed by saledjenic
parent 4ff700681f
commit 9821e160c1
6 changed files with 34 additions and 2 deletions

View File

@ -421,6 +421,13 @@ method onMessageEdited*(self: Module, message: MessageDto) =
message.links
)
let messagesIds = self.view.model().findIdsOfTheMessagesWhichRespondedToMessageWithId(message.id)
for msgId in messagesIds:
# refreshing an item calling `self.view.model().refreshItemWithId(msgId)` doesn't work from some very weird reason
# and that would be the correct way of updating item instead sending this signal. We should check this once we refactor
# qml part.
self.view.emitRefreshAMessageUserRespondedToSignal(msgId)
method onHistoryCleared*(self: Module) =
self.view.model().clear()

View File

@ -161,4 +161,8 @@ QtObject:
self.delegate.leaveChat()
proc didIJoinedChat(self: View): bool {.slot.} =
return self.delegate.didIJoinedChat()
return self.delegate.didIJoinedChat()
proc refreshAMessageUserRespondedTo(self: View, msgId: string) {.signal.}
proc emitRefreshAMessageUserRespondedToSignal*(self: View, msgId: string) =
self.refreshAMessageUserRespondedTo(msgId)

View File

@ -196,6 +196,11 @@ QtObject:
return i
return -1
proc findIdsOfTheMessagesWhichRespondedToMessageWithId*(self: Model, messageId: string): seq[string] =
for i in 0 ..< self.items.len:
if(self.items[i].responseToMessageWithId == messageId):
result.add(self.items[i].id)
proc findIndexBasedOnTimestampToInsertTo(self: Model, timestamp: int64): int =
for i in 0 ..< self.items.len:
if(timestamp > self.items[i].timestamp):

View File

@ -248,6 +248,7 @@ Item {
isChatBlocked: root.isChatBlocked
messageContextMenu: messageContextMenuInst
itemIndex: index
messageId: model.id
communityId: model.communityId
responseToMessageWithId: model.responseToMessageWithId

View File

@ -74,6 +74,15 @@ Item {
height: messageContainer.height + messageContainer.anchors.topMargin
+ (dateGroupLbl.visible ? dateGroupLbl.height + dateGroupLbl.anchors.topMargin : 0)
Connections {
target: root.messageStore.messageModule
enabled: responseTo !== ""
onRefreshAMessageUserRespondedTo: {
if(msgId === messageId)
chatReply.resetOriginalMessage()
}
}
Timer {
id: ensureMessageFullyVisibleTimer
interval: 1
@ -283,7 +292,7 @@ Item {
// stickerData: !!rootStore ? rootStore.chatsModelInst.messageView.messageList.getMessageData(replyMessageIndex, "sticker") : null
active: responseTo !== "" && !activityCenterMessage
Component.onCompleted: {
function resetOriginalMessage() {
if(!root.messageStore)
return
let obj = root.messageStore.getMessageByIdAsJson(responseTo)
@ -300,6 +309,11 @@ Item {
repliedMessageContent = obj.messageText
repliedMessageImage = obj.messageImage
}
Component.onCompleted: {
resetOriginalMessage()
}
onScrollToBottom: {
// Not Refactored Yet
// messageStore.scrollToBottom(isit, root.container);

View File

@ -27,6 +27,7 @@ Column {
// without an explicit need to fetch those details via message store/module.
property bool isChatBlocked: false
property int itemIndex: -1
property string messageId: ""
property string communityId: ""
property string responseToMessageWithId: ""