From b82b4825c14308d50a85c807c2ebde90d014e094 Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Wed, 7 Jun 2023 15:48:37 +0200 Subject: [PATCH] chore(messages): introduce `bulkReplacePubKeysWithDisplayNames` iterates: #10886 --- .../main/chat_section/chat_content/controller.nim | 3 --- .../chat_content/messages/controller.nim | 3 --- .../chat_section/chat_content/messages/module.nim | 6 +++--- .../main/chat_section/chat_content/module.nim | 2 +- src/app_service/service/message/service.nim | 13 +++++++++++++ 5 files changed, 17 insertions(+), 10 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 2e6685d489..0f8de2fba8 100644 --- a/src/app/modules/main/chat_section/chat_content/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/controller.nim @@ -242,9 +242,6 @@ proc getContactDetails*(self: Controller, contactId: string): ContactDetails = proc getCurrentFleet*(self: Controller): string = return self.nodeConfigurationService.getFleetAsString() -proc replacePubKeysWithDisplayNames*(self: Controller, message: string): string = - return self.messageService.replacePubKeysWithDisplayNames(message) - proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText], communityChats: seq[ChatDto]): string = return self.messageService.getRenderedText(parsedTextArray, communityChats) 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 1ab1bd6476..084a6ccb0c 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 @@ -273,9 +273,6 @@ proc getNumOfPinnedMessages*(self: Controller): int = proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText], communityChats: seq[ChatDto]): string = return self.messageService.getRenderedText(parsedTextArray, communityChats) -proc replacePubKeysWithDisplayNames*(self: Controller, message: string): string = - return self.messageService.replacePubKeysWithDisplayNames(message) - proc deleteMessage*(self: Controller, messageId: string) = self.messageService.deleteMessage(messageId) 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 3d214b8524..c3ef6d99e8 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 @@ -277,7 +277,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se sender.dto.added, message.outgoingStatus, renderedMessageText, - self.controller.replacePubKeysWithDisplayNames(message.text), + message.text, message.parsedText, message.image, message.containsContactMentions(), @@ -411,7 +411,7 @@ method messagesAdded*(self: Module, messages: seq[MessageDto]) = sender.dto.added, message.outgoingStatus, renderedMessageText, - self.controller.replacePubKeysWithDisplayNames(message.text), + message.text, message.parsedText, message.image, message.containsContactMentions(), @@ -615,7 +615,7 @@ method onMessageEdited*(self: Module, message: MessageDto) = self.view.model().updateEditedMsg( message.id, self.controller.getRenderedText(message.parsedText, communityChats), - self.controller.replacePubKeysWithDisplayNames(message.text), + message.text, message.parsedText, message.contentType, message.mentioned, 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 bc5bb39e27..dedd7095a9 100644 --- a/src/app/modules/main/chat_section/chat_content/module.nim +++ b/src/app/modules/main/chat_section/chat_content/module.nim @@ -183,7 +183,7 @@ proc buildPinnedMessageItem(self: Module, message: MessageDto, actionInitiatedBy contactDetails.dto.added, message.outgoingStatus, self.controller.getRenderedText(message.parsedText, communityChats), - self.controller.replacePubKeysWithDisplayNames(message.text), + message.text, message.parsedText, message.image, message.containsContactMentions(), diff --git a/src/app_service/service/message/service.nim b/src/app_service/service/message/service.nim index bb99bd85c5..fc67495c88 100644 --- a/src/app_service/service/message/service.nim +++ b/src/app_service/service/message/service.nim @@ -141,6 +141,8 @@ QtObject: pinnedMsgCursor: Table[string, MessageCursor] numOfPinnedMessagesPerChat: Table[string, int] # [chat_id, num_of_pinned_messages] + proc bulkReplacePubKeysWithDisplayNames(self: Service, messages: var seq[MessageDto]) + proc delete*(self: Service) = self.QObject.delete @@ -264,6 +266,8 @@ QtObject: # if (not chats[0].active): # return + self.bulkReplacePubKeysWithDisplayNames(messages) + for i in 0 ..< chats.len: let chatId = chats[i].id @@ -473,6 +477,8 @@ QtObject: if(responseObj.getProp("messages", messagesArr)): messages = map(messagesArr.getElems(), proc(x: JsonNode): MessageDto = x.toMessageDto()) + self.bulkReplacePubKeysWithDisplayNames(messages) + # handling reactions var reactionsArr: JsonNode var reactions: seq[ReactionDto] @@ -865,6 +871,11 @@ proc replacePubKeysWithDisplayNames*(self: Service, message: string): string = let allKnownContacts = self.contactService.getContactsByGroup(ContactsGroup.AllKnownContacts) return message_common.replacePubKeysWithDisplayNames(allKnownContacts, message) +proc bulkReplacePubKeysWithDisplayNames(self: Service, messages: var seq[MessageDto]) = + let allKnownContacts = self.contactService.getContactsByGroup(ContactsGroup.AllKnownContacts) + for i in 0..