From 86a6d48546b649251e2715e651a4de27d1a7ba4f Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 5 Dec 2024 11:32:49 -0500 Subject: [PATCH] fix(pins): fix edits not showing in the pinned messages until restart Fixes #16639 --- .../chat_section/chat_content/controller.nim | 6 ++++++ .../chat_content/io_interface.nim | 11 ++++++---- .../main/chat_section/chat_content/module.nim | 21 +++++++++++++++++++ src/app_service/service/message/service.nim | 2 +- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/app/modules/main/chat_section/chat_content/controller.nim b/src/app/modules/main/chat_section/chat_content/controller.nim index b6e1953261..373e0bb75b 100644 --- a/src/app/modules/main/chat_section/chat_content/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/controller.nim @@ -184,6 +184,12 @@ proc init*(self: Controller) = return self.delegate.onGroupChatDetailsUpdated(args.newName, args.newColor, args.newImage) + self.events.on(SIGNAL_MESSAGE_EDITED) do(e: Args): + let args = MessageEditedArgs(e) + if(self.chatId != args.chatId): + return + self.delegate.onMessageEdited(args.message) + proc getMyChatId*(self: Controller): string = return self.chatId diff --git a/src/app/modules/main/chat_section/chat_content/io_interface.nim b/src/app/modules/main/chat_section/chat_content/io_interface.nim index 527bd27bb6..554169aead 100644 --- a/src/app/modules/main/chat_section/chat_content/io_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/io_interface.nim @@ -1,9 +1,9 @@ import NimQml import ../item as chat_item -import ../../../../../app_service/service/message/dto/pinned_message -import ../../../../../app_service/service/chat/dto/chat - +import app_service/service/message/dto/pinned_message +import app_service/service/chat/dto/chat +import app_service/service/message/dto/message type AccessInterface* {.pure inheritable.} = ref object of RootObj @@ -31,7 +31,10 @@ method newPinnedMessagesLoaded*(self: AccessInterface, pinnedMessages: seq[Pinne method onUnpinMessage*(self: AccessInterface, messageId: string) {.base.} = raise newException(ValueError, "No implementation available") -method onPinMessage*(self: AccessInterface, mmessageId: string, actionInitiatedBy: string) {.base.} = +method onPinMessage*(self: AccessInterface, messageId: string, actionInitiatedBy: string) {.base.} = + raise newException(ValueError, "No implementation available") + +method onMessageEdited*(self: AccessInterface, message: MessageDto) {.base.} = raise newException(ValueError, "No implementation available") method onChatMuted*(self: AccessInterface) {.base.} = diff --git a/src/app/modules/main/chat_section/chat_content/module.nim b/src/app/modules/main/chat_section/chat_content/module.nim index 5ff64e1885..032c691b59 100644 --- a/src/app/modules/main/chat_section/chat_content/module.nim +++ b/src/app/modules/main/chat_section/chat_content/module.nim @@ -271,6 +271,27 @@ method onPinMessage*(self: Module, messageId: string, actionInitiatedBy: string) self.view.pinnedModel().insertItemBasedOnClock(item) +method onMessageEdited*(self: Module, message: MessageDto) = + let index = self.view.pinnedModel().findIndexForMessageId(message.id) + if index == -1: + return + + let itemBeforeChange = self.view.pinnedModel().getItemWithMessageId(message.id) + let mentionedUsersPks = itemBeforeChange.mentionedUsersPks + let communityChats = self.controller.getCommunityDetails().chats + + self.view.pinnedModel().updateEditedMsg( + message.id, + self.controller.getRenderedText(message.parsedText, communityChats), + message.text, + message.parsedText, + message.contentType, + message.mentioned, + message.containsContactMentions(), + message.links, + message.mentionedUsersPks + ) + method getMyChatId*(self: Module): string = self.controller.getMyChatId() diff --git a/src/app_service/service/message/service.nim b/src/app_service/service/message/service.nim index aa3c17df86..5bc9a390c5 100644 --- a/src/app_service/service/message/service.nim +++ b/src/app_service/service/message/service.nim @@ -519,7 +519,7 @@ QtObject: self.events.emit(SIGNAL_PINNED_MESSAGES_LOADED, data) except Exception as e: - error "Erorr load pinned messages for chat async", msg = e.msg + error "Error load pinned messages for chat async", msg = e.msg # notify view, this is important self.events.emit(SIGNAL_PINNED_MESSAGES_LOADED, PinnedMessagesLoadedArgs())