From cfd227f9f29f40aa172ecccca0e7ca4105d7d4e1 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Tue, 25 Jan 2022 11:08:58 +0100 Subject: [PATCH] fix(@chat): react to on clear history fixes #4527 --- .../main/chat_section/chat_content/messages/controller.nim | 6 ++++++ .../main/chat_section/chat_content/messages/module.nim | 3 +++ .../private_interfaces/module_view_delegate_interface.nim | 3 +++ src/app/modules/shared_models/message_model.nim | 6 +++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app/modules/main/chat_section/chat_content/messages/controller.nim b/src/app/modules/main/chat_section/chat_content/messages/controller.nim index 389e93fbeb..1172bb6b2f 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/controller.nim @@ -115,6 +115,12 @@ method init*(self: Controller) = return self.delegate.onMessageEdited(args.message) + self.events.on(SIGNAL_CHAT_HISTORY_CLEARED) do (e: Args): + var args = ChatArgs(e) + if(self.chatId != args.chatId): + return + self.delegate.onHistoryCleared() + method getMySectionId*(self: Controller): string = return self.sectionId 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 8a975334d7..552acc947e 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 @@ -281,6 +281,9 @@ method onMessageEdited*(self: Module, message: MessageDto) = let renderedMessageText = self.controller.getRenderedText(message.parsedText) self.view.model().updateEditedMsg(message.id, renderedMessageText, message.containsContactMentions()) +method onHistoryCleared*(self: Module) = + self.view.model().clear() + method updateChatIdentifier*(self: Module) = # Delete the old ChatIdentifier message first self.view.model().removeItem(CHAT_IDENTIFIER_MESSAGE_ID) diff --git a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_view_delegate_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_view_delegate_interface.nim index 8371323a1f..a81d16ba62 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_view_delegate_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_view_delegate_interface.nim @@ -30,3 +30,6 @@ method onMessageDeleted*(self: AccessInterface, messageId: string) {.base.} = method editMessage*(self: AccessInterface, messageId: string, updatedMsg: string) {.base.} = raise newException(ValueError, "No implementation available") + +method onHistoryCleared*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/shared_models/message_model.nim b/src/app/modules/shared_models/message_model.nim index 1bdea377f0..59590163a7 100644 --- a/src/app/modules/shared_models/message_model.nim +++ b/src/app/modules/shared_models/message_model.nim @@ -350,4 +350,8 @@ QtObject: let index = self.createIndex(ind, 0, nil) self.dataChanged(index, index, @[ModelRole.MessageText.int, ModelRole.MessageContainsMentions.int, ModelRole.IsEdited.int]) - + proc clear*(self: Model) = + self.beginResetModel() + self.items = @[] + self.endResetModel() + self.countChanged() \ No newline at end of file