chore(messages): introduce `bulkReplacePubKeysWithDisplayNames`

iterates: #10886
This commit is contained in:
Patryk Osmaczko 2023-06-07 15:48:37 +02:00 committed by osmaczko
parent 0169901fa2
commit b82b4825c1
5 changed files with 17 additions and 10 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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,

View File

@ -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(),

View File

@ -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..<messages.len:
messages[i].text = message_common.replacePubKeysWithDisplayNames(allKnownContacts, messages[i].text)
proc editMessage*(self: Service, messageId: string, contentType: int, msg: string) =
try:
let allKnownContacts = self.contactService.getContactsByGroup(ContactsGroup.AllKnownContacts)
@ -885,6 +896,8 @@ proc editMessage*(self: Service, messageId: string, contentType: int, msg: strin
error "error: ", procName="editMessage", errDesription = "message is not edited"
return
self.bulkReplacePubKeysWithDisplayNames(messages)
let data = MessageEditedArgs(chatId: messages[0].chatId, message: messages[0])
self.events.emit(SIGNAL_MESSAGE_EDITED, data)