chore(messages): introduce `bulkReplacePubKeysWithDisplayNames`
iterates: #10886
This commit is contained in:
parent
0169901fa2
commit
b82b4825c1
|
@ -242,9 +242,6 @@ proc getContactDetails*(self: Controller, contactId: string): ContactDetails =
|
||||||
proc getCurrentFleet*(self: Controller): string =
|
proc getCurrentFleet*(self: Controller): string =
|
||||||
return self.nodeConfigurationService.getFleetAsString()
|
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 =
|
proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText], communityChats: seq[ChatDto]): string =
|
||||||
return self.messageService.getRenderedText(parsedTextArray, communityChats)
|
return self.messageService.getRenderedText(parsedTextArray, communityChats)
|
||||||
|
|
||||||
|
|
|
@ -273,9 +273,6 @@ proc getNumOfPinnedMessages*(self: Controller): int =
|
||||||
proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText], communityChats: seq[ChatDto]): string =
|
proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText], communityChats: seq[ChatDto]): string =
|
||||||
return self.messageService.getRenderedText(parsedTextArray, communityChats)
|
return self.messageService.getRenderedText(parsedTextArray, communityChats)
|
||||||
|
|
||||||
proc replacePubKeysWithDisplayNames*(self: Controller, message: string): string =
|
|
||||||
return self.messageService.replacePubKeysWithDisplayNames(message)
|
|
||||||
|
|
||||||
proc deleteMessage*(self: Controller, messageId: string) =
|
proc deleteMessage*(self: Controller, messageId: string) =
|
||||||
self.messageService.deleteMessage(messageId)
|
self.messageService.deleteMessage(messageId)
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
|
||||||
sender.dto.added,
|
sender.dto.added,
|
||||||
message.outgoingStatus,
|
message.outgoingStatus,
|
||||||
renderedMessageText,
|
renderedMessageText,
|
||||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
message.text,
|
||||||
message.parsedText,
|
message.parsedText,
|
||||||
message.image,
|
message.image,
|
||||||
message.containsContactMentions(),
|
message.containsContactMentions(),
|
||||||
|
@ -411,7 +411,7 @@ method messagesAdded*(self: Module, messages: seq[MessageDto]) =
|
||||||
sender.dto.added,
|
sender.dto.added,
|
||||||
message.outgoingStatus,
|
message.outgoingStatus,
|
||||||
renderedMessageText,
|
renderedMessageText,
|
||||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
message.text,
|
||||||
message.parsedText,
|
message.parsedText,
|
||||||
message.image,
|
message.image,
|
||||||
message.containsContactMentions(),
|
message.containsContactMentions(),
|
||||||
|
@ -615,7 +615,7 @@ method onMessageEdited*(self: Module, message: MessageDto) =
|
||||||
self.view.model().updateEditedMsg(
|
self.view.model().updateEditedMsg(
|
||||||
message.id,
|
message.id,
|
||||||
self.controller.getRenderedText(message.parsedText, communityChats),
|
self.controller.getRenderedText(message.parsedText, communityChats),
|
||||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
message.text,
|
||||||
message.parsedText,
|
message.parsedText,
|
||||||
message.contentType,
|
message.contentType,
|
||||||
message.mentioned,
|
message.mentioned,
|
||||||
|
|
|
@ -183,7 +183,7 @@ proc buildPinnedMessageItem(self: Module, message: MessageDto, actionInitiatedBy
|
||||||
contactDetails.dto.added,
|
contactDetails.dto.added,
|
||||||
message.outgoingStatus,
|
message.outgoingStatus,
|
||||||
self.controller.getRenderedText(message.parsedText, communityChats),
|
self.controller.getRenderedText(message.parsedText, communityChats),
|
||||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
message.text,
|
||||||
message.parsedText,
|
message.parsedText,
|
||||||
message.image,
|
message.image,
|
||||||
message.containsContactMentions(),
|
message.containsContactMentions(),
|
||||||
|
|
|
@ -141,6 +141,8 @@ QtObject:
|
||||||
pinnedMsgCursor: Table[string, MessageCursor]
|
pinnedMsgCursor: Table[string, MessageCursor]
|
||||||
numOfPinnedMessagesPerChat: Table[string, int] # [chat_id, num_of_pinned_messages]
|
numOfPinnedMessagesPerChat: Table[string, int] # [chat_id, num_of_pinned_messages]
|
||||||
|
|
||||||
|
proc bulkReplacePubKeysWithDisplayNames(self: Service, messages: var seq[MessageDto])
|
||||||
|
|
||||||
proc delete*(self: Service) =
|
proc delete*(self: Service) =
|
||||||
self.QObject.delete
|
self.QObject.delete
|
||||||
|
|
||||||
|
@ -264,6 +266,8 @@ QtObject:
|
||||||
# if (not chats[0].active):
|
# if (not chats[0].active):
|
||||||
# return
|
# return
|
||||||
|
|
||||||
|
self.bulkReplacePubKeysWithDisplayNames(messages)
|
||||||
|
|
||||||
for i in 0 ..< chats.len:
|
for i in 0 ..< chats.len:
|
||||||
let chatId = chats[i].id
|
let chatId = chats[i].id
|
||||||
|
|
||||||
|
@ -473,6 +477,8 @@ QtObject:
|
||||||
if(responseObj.getProp("messages", messagesArr)):
|
if(responseObj.getProp("messages", messagesArr)):
|
||||||
messages = map(messagesArr.getElems(), proc(x: JsonNode): MessageDto = x.toMessageDto())
|
messages = map(messagesArr.getElems(), proc(x: JsonNode): MessageDto = x.toMessageDto())
|
||||||
|
|
||||||
|
self.bulkReplacePubKeysWithDisplayNames(messages)
|
||||||
|
|
||||||
# handling reactions
|
# handling reactions
|
||||||
var reactionsArr: JsonNode
|
var reactionsArr: JsonNode
|
||||||
var reactions: seq[ReactionDto]
|
var reactions: seq[ReactionDto]
|
||||||
|
@ -865,6 +871,11 @@ proc replacePubKeysWithDisplayNames*(self: Service, message: string): string =
|
||||||
let allKnownContacts = self.contactService.getContactsByGroup(ContactsGroup.AllKnownContacts)
|
let allKnownContacts = self.contactService.getContactsByGroup(ContactsGroup.AllKnownContacts)
|
||||||
return message_common.replacePubKeysWithDisplayNames(allKnownContacts, message)
|
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) =
|
proc editMessage*(self: Service, messageId: string, contentType: int, msg: string) =
|
||||||
try:
|
try:
|
||||||
let allKnownContacts = self.contactService.getContactsByGroup(ContactsGroup.AllKnownContacts)
|
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"
|
error "error: ", procName="editMessage", errDesription = "message is not edited"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.bulkReplacePubKeysWithDisplayNames(messages)
|
||||||
|
|
||||||
let data = MessageEditedArgs(chatId: messages[0].chatId, message: messages[0])
|
let data = MessageEditedArgs(chatId: messages[0].chatId, message: messages[0])
|
||||||
self.events.emit(SIGNAL_MESSAGE_EDITED, data)
|
self.events.emit(SIGNAL_MESSAGE_EDITED, data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue