From 9821e160c1555c628e5be49a0ee1faf994bb98a0 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Wed, 9 Mar 2022 11:02:28 +0100 Subject: [PATCH] fix(@dekstop/chat): editing a message does not update the reply Fixes #4891 --- .../chat_content/messages/module.nim | 7 +++++++ .../chat_section/chat_content/messages/view.nim | 6 +++++- src/app/modules/shared_models/message_model.nim | 5 +++++ .../AppLayouts/Chat/views/ChatMessagesView.qml | 1 + .../shared/views/chat/CompactMessageView.qml | 16 +++++++++++++++- ui/imports/shared/views/chat/MessageView.qml | 1 + 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/app/modules/main/chat_section/chat_content/messages/module.nim b/src/app/modules/main/chat_section/chat_content/messages/module.nim index 83b9564e1d..012a1e8be9 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/module.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/module.nim @@ -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() diff --git a/src/app/modules/main/chat_section/chat_content/messages/view.nim b/src/app/modules/main/chat_section/chat_content/messages/view.nim index 305ca4bbb6..4e559a831d 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/view.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/view.nim @@ -161,4 +161,8 @@ QtObject: self.delegate.leaveChat() proc didIJoinedChat(self: View): bool {.slot.} = - return self.delegate.didIJoinedChat() \ No newline at end of file + return self.delegate.didIJoinedChat() + + proc refreshAMessageUserRespondedTo(self: View, msgId: string) {.signal.} + proc emitRefreshAMessageUserRespondedToSignal*(self: View, msgId: string) = + self.refreshAMessageUserRespondedTo(msgId) \ No newline at end of file diff --git a/src/app/modules/shared_models/message_model.nim b/src/app/modules/shared_models/message_model.nim index b0e1ce6461..982282849c 100644 --- a/src/app/modules/shared_models/message_model.nim +++ b/src/app/modules/shared_models/message_model.nim @@ -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): diff --git a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml index 3b6bb8df7a..327a359e9f 100644 --- a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml @@ -248,6 +248,7 @@ Item { isChatBlocked: root.isChatBlocked messageContextMenu: messageContextMenuInst + itemIndex: index messageId: model.id communityId: model.communityId responseToMessageWithId: model.responseToMessageWithId diff --git a/ui/imports/shared/views/chat/CompactMessageView.qml b/ui/imports/shared/views/chat/CompactMessageView.qml index ae7a6e311f..4e5da7f995 100644 --- a/ui/imports/shared/views/chat/CompactMessageView.qml +++ b/ui/imports/shared/views/chat/CompactMessageView.qml @@ -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); diff --git a/ui/imports/shared/views/chat/MessageView.qml b/ui/imports/shared/views/chat/MessageView.qml index 5e0d87a088..74357f93a7 100644 --- a/ui/imports/shared/views/chat/MessageView.qml +++ b/ui/imports/shared/views/chat/MessageView.qml @@ -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: ""