mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-13 07:06:58 +00:00
fix(Chat): ensure message context menu preserve mentions in copied messages
Because the context menu relied on `unparsedTex` it was unable to preserve the pubkey<->displayName conversion when copying messages to the clipboard. This commit fixes it by introducing a new `replacePubKeysWithMentions` utility which is used when message items are initialized, resulting in `unparsedText` to keep th`@`mentions around. Closes #9168
This commit is contained in:
parent
54e91e0ba7
commit
ae4d59de9a
@ -106,6 +106,9 @@ proc acceptActivityCenterNotifications*(self: Controller, notificationIds: seq[s
|
||||
proc dismissActivityCenterNotifications*(self: Controller, notificationIds: seq[string]): string =
|
||||
return self.activityCenterService.dismissActivityCenterNotifications(notificationIds)
|
||||
|
||||
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)
|
||||
|
||||
@ -127,4 +130,4 @@ proc getMessageById*(self: Controller, chatId, messageId: string): MessageDto =
|
||||
let (message, _, err) = self.messageService.getDetailsForMessage(chatId, messageId)
|
||||
if(err.len > 0):
|
||||
return MessageDto()
|
||||
return message
|
||||
return message
|
||||
|
@ -95,7 +95,7 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: Ch
|
||||
contactDetails.details.added,
|
||||
message.outgoingStatus,
|
||||
self.controller.getRenderedText(message.parsedText, communityChats),
|
||||
message.text,
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.image,
|
||||
message.containsContactMentions(),
|
||||
message.seen,
|
||||
|
@ -238,6 +238,9 @@ 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)
|
||||
|
||||
|
@ -257,6 +257,9 @@ 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 getMessageDetails*(self: Controller, messageId: string):
|
||||
tuple[message: MessageDto, reactions: seq[ReactionDto], error: string] =
|
||||
return self.messageService.getDetailsForMessage(self.chatId, messageId)
|
||||
|
@ -237,7 +237,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
|
||||
sender.details.added,
|
||||
message.outgoingStatus,
|
||||
renderedMessageText,
|
||||
message.text,
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.image,
|
||||
message.containsContactMentions(),
|
||||
message.seen,
|
||||
@ -358,7 +358,7 @@ method messagesAdded*(self: Module, messages: seq[MessageDto]) =
|
||||
sender.details.added,
|
||||
message.outgoingStatus,
|
||||
renderedMessageText,
|
||||
message.text,
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.image,
|
||||
message.containsContactMentions(),
|
||||
message.seen,
|
||||
@ -556,7 +556,7 @@ method onMessageEdited*(self: Module, message: MessageDto) =
|
||||
self.view.model().updateEditedMsg(
|
||||
message.id,
|
||||
self.controller.getRenderedText(message.parsedText, communityChats),
|
||||
message.text,
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.contentType,
|
||||
message.containsContactMentions(),
|
||||
message.links,
|
||||
|
@ -184,7 +184,7 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy:
|
||||
contactDetails.details.added,
|
||||
message.outgoingStatus,
|
||||
self.controller.getRenderedText(message.parsedText, communityChats),
|
||||
message.text,
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.image,
|
||||
message.containsContactMentions(),
|
||||
message.seen,
|
||||
|
@ -316,4 +316,4 @@ QtObject:
|
||||
self.loadingHistoryMessagesInProgressChanged()
|
||||
|
||||
proc downloadMessages*(self: View, chatId: string, filePath: string) {.slot.} =
|
||||
self.delegate.downloadMessages(chatId, filePath)
|
||||
self.delegate.downloadMessages(chatId, filePath)
|
||||
|
@ -2,6 +2,22 @@ import sequtils, strutils, sugar, re
|
||||
import ../service/contacts/dto/contacts
|
||||
from conversion import SystemTagMapping
|
||||
|
||||
|
||||
proc replacePubKeysWithDisplayNames*(allKnownContacts: seq[ContactsDto], message: string): string =
|
||||
let pubKeyPattern = re(r"(@0x[a-f0-9]+)", flags = {reStudy, reIgnoreCase})
|
||||
let pubKeys = findAll(message, pubKeyPattern)
|
||||
var updatedMessage = message
|
||||
|
||||
for pair in SystemTagMapping:
|
||||
updatedMessage = updatedMessage.replaceWord(pair[1], pair[0])
|
||||
|
||||
for pk in pubKeys:
|
||||
let listOfMatched = allKnownContacts.filter(x => "@" & x.id == pk)
|
||||
if(listOfMatched.len > 0):
|
||||
updatedMessage = updatedMessage.replaceWord(pk, "@" & listOfMatched[0].userDefaultDisplayName())
|
||||
|
||||
return updatedMessage
|
||||
|
||||
proc replaceMentionsWithPubKeys*(allKnownContacts: seq[ContactsDto], message: string): string =
|
||||
let aliasPattern = re(r"(@[A-z][a-z]+ [A-z][a-z]* [A-z][a-z]*)", flags = {reStudy, reIgnoreCase})
|
||||
let ensPattern = re(r"(@\w+((\.stateofus)?\.eth))", flags = {reStudy, reIgnoreCase})
|
||||
|
@ -775,6 +775,10 @@ proc deleteMessage*(self: Service, messageId: string) =
|
||||
except Exception as e:
|
||||
error "error: ", procName="deleteMessage", errName = e.name, errDesription = e.msg
|
||||
|
||||
proc replacePubKeysWithDisplayNames*(self: Service, message: string): string =
|
||||
let allKnownContacts = self.contactService.getContactsByGroup(ContactsGroup.AllKnownContacts)
|
||||
return message_common.replacePubKeysWithDisplayNames(allKnownContacts, message)
|
||||
|
||||
proc editMessage*(self: Service, messageId: string, contentType: int, msg: string) =
|
||||
try:
|
||||
let allKnownContacts = self.contactService.getContactsByGroup(ContactsGroup.AllKnownContacts)
|
||||
|
Loading…
x
Reference in New Issue
Block a user