From 2449c8840eba437adf88aff03ddbd3484c908dd3 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Wed, 22 Jun 2022 09:43:30 +0200 Subject: [PATCH] chores(@chat): bring back download messages fixes #6163 --- .../main/chat_section/chat_content/controller.nim | 14 +++++++++++++- .../chat_section/chat_content/io_interface.nim | 3 +++ .../chat_content/messages/io_interface.nim | 4 ++++ .../chat_section/chat_content/messages/module.nim | 3 +++ .../chat_section/chat_content/messages/view.nim | 2 +- .../main/chat_section/chat_content/module.nim | 4 ++++ .../main/chat_section/chat_content/view.nim | 3 +++ src/app/modules/main/chat_section/io_interface.nim | 3 +++ src/app/modules/main/chat_section/module.nim | 7 +++++++ src/app/modules/main/chat_section/view.nim | 3 +++ src/app/modules/shared_models/message_model.nim | 2 +- ui/app/AppLayouts/Chat/views/ChatContentView.qml | 6 +++++- .../AppLayouts/Chat/views/CommunityColumnView.qml | 2 +- .../AppLayouts/Chat/views/ContactsColumnView.qml | 2 +- 14 files changed, 52 insertions(+), 6 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 98a89bed90..00c75de0c8 100644 --- a/src/app/modules/main/chat_section/chat_content/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/controller.nim @@ -1,5 +1,6 @@ import Tables - +import NimQml +import json import io_interface import ../../../../../app_service/service/settings/service as settings_service @@ -12,6 +13,7 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou import ../../../../core/signals/types import ../../../../core/eventemitter +import ../../../shared_models/message_item type @@ -196,3 +198,13 @@ proc getTransactionDetails*(self: Controller, message: MessageDto): (string,stri proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] = return self.messageService.getWalletAccounts() + +proc downloadMessages*(self: Controller, messages: seq[message_item.Item], filePath: string) = + let data = newJArray() + for message in messages: + data.elems.add(%*{ + "id": message.id(), "text": message.messageText(), "timestamp": message.timestamp(), + "sender": message.senderDisplayName() + }) + + writeFile(url_toLocalFile(filePath), $data) 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 9be72d16a0..95295abdbc 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 @@ -108,3 +108,6 @@ method getCurrentFleet*(self: AccessInterface): string {.base.} = method amIChatAdmin*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") + +method downloadMessages*(self: AccessInterface, filePath: string) = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim index 2e208d4582..7d1bd4f58c 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim @@ -1,6 +1,7 @@ import NimQml import ../../../../../../app_service/service/message/dto/[message, reaction, pinned_message] +import ../../../../shared_models/message_item type AccessInterface* {.pure inheritable.} = ref object of RootObj @@ -123,3 +124,6 @@ method leaveChat*(self: AccessInterface) {.base.} = method didIJoinedChat*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") + +method getMessages*(self: AccessInterface): seq[message_item.Item] = + raise newException(ValueError, "No implementation available") \ No newline at end of file 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 3911c10e1c..13b8f9db56 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 @@ -486,3 +486,6 @@ method onChatMemberUpdated*(self: Module, publicKey: string, admin: bool, joined return self.view.model().refreshItemWithId(CHAT_IDENTIFIER_MESSAGE_ID) + +method getMessages*(self: Module): seq[message_item.Item] = + return self.view.model().items 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 8226bc60d5..5350b49f93 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 @@ -162,4 +162,4 @@ QtObject: proc refreshAMessageUserRespondedTo(self: View, msgId: string) {.signal.} proc emitRefreshAMessageUserRespondedToSignal*(self: View, msgId: string) = - self.refreshAMessageUserRespondedTo(msgId) + self.refreshAMessageUserRespondedTo(msgId) \ No newline at end of file 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 b2d50b6230..fef1f53ee4 100644 --- a/src/app/modules/main/chat_section/chat_content/module.nim +++ b/src/app/modules/main/chat_section/chat_content/module.nim @@ -331,3 +331,7 @@ method onChatEdited*(self: Module, chatDto: ChatDto) = method onChatRenamed*(self: Module, newName: string) = self.view.updateChatDetailsName(newName) self.messagesModule.updateChatIdentifier() + +method downloadMessages*(self: Module, filePath: string) = + let messages = self.messagesModule.getMessages() + self.controller.downloadMessages(messages, filePath) diff --git a/src/app/modules/main/chat_section/chat_content/view.nim b/src/app/modules/main/chat_section/chat_content/view.nim index 520bae8796..0a2636c34a 100644 --- a/src/app/modules/main/chat_section/chat_content/view.nim +++ b/src/app/modules/main/chat_section/chat_content/view.nim @@ -122,3 +122,6 @@ QtObject: proc updateChatDetailsName*(self: View, name: string) = self.chatDetails.setName(name) self.chatDetailsChanged() + + proc downloadMessages*(self: View, filePath: string) {.slot.} = + self.delegate.downloadMessages(filePath) \ No newline at end of file diff --git a/src/app/modules/main/chat_section/io_interface.nim b/src/app/modules/main/chat_section/io_interface.nim index f05f9edb38..8f70ef1ac4 100644 --- a/src/app/modules/main/chat_section/io_interface.nim +++ b/src/app/modules/main/chat_section/io_interface.nim @@ -284,3 +284,6 @@ method reorderCommunityChat*(self: AccessInterface, categoryId: string, chatId: method onMeMentionedInEditedMessage*(self: AccessInterface, chatId: string, editedMessage : MessageDto) {.base.} = raise newException(ValueError, "No implementation available") + +method downloadMessages*(self: AccessInterface, chatId: string, filePath: string) = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index f3af5cb1c9..f0ceebf65b 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -807,3 +807,10 @@ method addChatIfDontExist*(self: Module, return self.addNewChat(chat, belongsToCommunity, events, settingsService, contactService, chatService, communityService, messageService, gifService, mailserversService, setChatAsActive) + +method downloadMessages*(self: Module, chatId: string, filePath: string) = + if(not self.chatContentModules.contains(chatId)): + error "unexisting chat key: ", chatId, methodName="downloadMessages" + return + + self.chatContentModules[chatId].downloadMessages(filePath) diff --git a/src/app/modules/main/chat_section/view.nim b/src/app/modules/main/chat_section/view.nim index 8afaef832a..7d5b48282f 100644 --- a/src/app/modules/main/chat_section/view.nim +++ b/src/app/modules/main/chat_section/view.nim @@ -293,3 +293,6 @@ QtObject: return self.loadingHistoryMessagesInProgress = value self.loadingHistoryMessagesInProgressChanged() + + proc downloadMessages*(self: View, chatId: string, filePath: string) {.slot.} = + self.delegate.downloadMessages(chatId, filePath) \ 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 87183f0071..d483b5e107 100644 --- a/src/app/modules/shared_models/message_model.nim +++ b/src/app/modules/shared_models/message_model.nim @@ -38,7 +38,7 @@ type QtObject: type Model* = ref object of QAbstractListModel - items: seq[Item] + items*: seq[Item] allKeys: seq[int] proc delete(self: Model) = diff --git a/ui/app/AppLayouts/Chat/views/ChatContentView.qml b/ui/app/AppLayouts/Chat/views/ChatContentView.qml index 698bc67295..3173f03147 100644 --- a/ui/app/AppLayouts/Chat/views/ChatContentView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatContentView.qml @@ -256,7 +256,11 @@ ColumnLayout { onDeleteCommunityChat: root.rootStore.removeCommunityChat(chatId) onDownloadMessages: { - // Not Refactored Yet + if(!chatContentModule) { + console.debug("error on leave chat from context menu - chat content module is not set") + return + } + chatContentModule.downloadMessages(file) } onDisplayProfilePopup: { diff --git a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml index 31d8da97fe..d0aa96172c 100644 --- a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml @@ -327,7 +327,7 @@ Item { onDeleteCommunityChat: root.store.removeCommunityChat(chatId) onDownloadMessages: { - // Not Refactored Yet + root.communitySectionModule.downloadMessages(chatId, file) } onDisplayProfilePopup: { diff --git a/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml b/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml index b98e891e23..fe24a1064a 100644 --- a/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml @@ -232,7 +232,7 @@ Item { } onDownloadMessages: { - // Not Refactored Yet + root.chatSectionModule.downloadMessages(chatId, file) } onDisplayProfilePopup: {