refactor: add parsedText to message_item to parse msg on mention change
This commit is contained in:
parent
0ebc81594a
commit
2d2929872e
|
@ -145,12 +145,6 @@ proc getOneToOneChatNameAndImage*(self: Controller, chatId: string):
|
|||
tuple[name: string, image: string, largeImage: string] =
|
||||
return self.chatService.getOneToOneChatNameAndImage(chatId)
|
||||
|
||||
proc getMessageById*(self: Controller, chatId, messageId: string): MessageDto =
|
||||
let (message, err) = self.messageService.fetchMessageByMessageId(chatId, messageId)
|
||||
if(err.len > 0):
|
||||
return MessageDto()
|
||||
return message
|
||||
|
||||
proc setActiveNotificationGroup*(self: Controller, group: ActivityCenterGroup) =
|
||||
self.activityCenterService.setActiveNotificationGroup(group)
|
||||
self.activityCenterService.resetCursor()
|
||||
|
|
|
@ -105,6 +105,7 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: Ch
|
|||
message.outgoingStatus,
|
||||
self.controller.getRenderedText(message.parsedText, communityChats),
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.parsedText,
|
||||
message.image,
|
||||
message.containsContactMentions(),
|
||||
message.seen,
|
||||
|
|
|
@ -261,10 +261,6 @@ proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText], commun
|
|||
proc replacePubKeysWithDisplayNames*(self: Controller, message: string): string =
|
||||
return self.messageService.replacePubKeysWithDisplayNames(message)
|
||||
|
||||
proc getMessageById*(self: Controller, messageId: string):
|
||||
tuple[message: MessageDto, error: string] =
|
||||
return self.messageService.fetchMessageByMessageId(self.chatId, messageId)
|
||||
|
||||
proc deleteMessage*(self: Controller, messageId: string) =
|
||||
self.messageService.deleteMessage(messageId)
|
||||
|
||||
|
|
|
@ -144,9 +144,6 @@ method didIJoinedChat*(self: AccessInterface): bool {.base.} =
|
|||
method getMessages*(self: AccessInterface): seq[message_item.Item] =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getMessageById*(self: AccessInterface, messageId: string): message_item.Item {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onMailserverSynced*(self: AccessInterface, syncedFrom: int64) =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ proc createFetchMoreMessagesItem(self: Module): Item =
|
|||
outgoingStatus = "",
|
||||
text = "",
|
||||
unparsedText = "",
|
||||
parsedText = @[],
|
||||
image = "",
|
||||
messageContainsMentions = false,
|
||||
seen = true,
|
||||
|
@ -146,6 +147,7 @@ proc createChatIdentifierItem(self: Module): Item =
|
|||
outgoingStatus = "",
|
||||
text = "",
|
||||
unparsedText = "",
|
||||
parsedText = @[],
|
||||
image = "",
|
||||
messageContainsMentions = false,
|
||||
seen = true,
|
||||
|
@ -248,6 +250,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
|
|||
message.outgoingStatus,
|
||||
renderedMessageText,
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.parsedText,
|
||||
message.image,
|
||||
message.containsContactMentions(),
|
||||
message.seen,
|
||||
|
@ -371,6 +374,7 @@ method messagesAdded*(self: Module, messages: seq[MessageDto]) =
|
|||
message.outgoingStatus,
|
||||
renderedMessageText,
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.parsedText,
|
||||
message.image,
|
||||
message.containsContactMentions(),
|
||||
message.seen,
|
||||
|
@ -544,12 +548,9 @@ method updateContactDetails*(self: Module, contactId: string) =
|
|||
item.quotedMessageAuthorAvatar = updatedContact.icon
|
||||
|
||||
if item.messageContainsMentions and item.mentionedUsersPks.anyIt(it == contactId):
|
||||
let (message, err) = self.controller.getMessageById(item.id)
|
||||
if err == "":
|
||||
let chatDetails = self.controller.getChatDetails()
|
||||
let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats
|
||||
item.messageText = self.controller.getRenderedText(message.parsedText, communityChats)
|
||||
item.messageContainsMentions = message.containsContactMentions()
|
||||
let chatDetails = self.controller.getChatDetails()
|
||||
let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats
|
||||
item.messageText = self.controller.getRenderedText(item.parsedText, communityChats)
|
||||
|
||||
method deleteMessage*(self: Module, messageId: string) =
|
||||
self.controller.deleteMessage(messageId)
|
||||
|
@ -573,6 +574,7 @@ method onMessageEdited*(self: Module, message: MessageDto) =
|
|||
message.id,
|
||||
self.controller.getRenderedText(message.parsedText, communityChats),
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.parsedText,
|
||||
message.contentType,
|
||||
message.containsContactMentions(),
|
||||
message.links,
|
||||
|
|
|
@ -187,6 +187,7 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy:
|
|||
message.outgoingStatus,
|
||||
self.controller.getRenderedText(message.parsedText, communityChats),
|
||||
self.controller.replacePubKeysWithDisplayNames(message.text),
|
||||
message.parsedText,
|
||||
message.image,
|
||||
message.containsContactMentions(),
|
||||
message.seen,
|
||||
|
@ -345,12 +346,9 @@ method onContactDetailsUpdated*(self: Module, contactId: string) =
|
|||
item.quotedMessageAuthorAvatar = updatedContact.icon
|
||||
|
||||
if item.messageContainsMentions and item.mentionedUsersPks.anyIt(it == contactId):
|
||||
let (message, err) = self.controller.getMessageById(item.id)
|
||||
if err == "":
|
||||
let chatDetails = self.controller.getChatDetails()
|
||||
let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats
|
||||
item.messageText = self.controller.getRenderedText(message.parsedText, communityChats)
|
||||
item.messageContainsMentions = message.containsContactMentions()
|
||||
let chatDetails = self.controller.getChatDetails()
|
||||
let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats
|
||||
item.messageText = self.controller.getRenderedText(item.parsedText, communityChats)
|
||||
|
||||
if(self.controller.getMyChatId() == contactId):
|
||||
self.view.updateChatDetailsNameAndIcon(updatedContact.defaultDisplayName, updatedContact.icon)
|
||||
|
|
|
@ -22,6 +22,8 @@ type
|
|||
outgoingStatus: string
|
||||
messageText: string
|
||||
unparsedText: string
|
||||
# Saving the parsed text property because we need it to getRenderedText when mentions change
|
||||
parsedText: seq[ParsedText]
|
||||
messageImage: string
|
||||
messageContainsMentions: bool
|
||||
sticker: string
|
||||
|
@ -68,7 +70,8 @@ proc initItem*(
|
|||
senderIsAdded: bool,
|
||||
outgoingStatus,
|
||||
text,
|
||||
unparsedText,
|
||||
unparsedText: string,
|
||||
parsedText: seq[ParsedText],
|
||||
image: string,
|
||||
messageContainsMentions,
|
||||
seen: bool,
|
||||
|
@ -110,6 +113,7 @@ proc initItem*(
|
|||
result.outgoingStatus = outgoingStatus
|
||||
result.messageText = text
|
||||
result.unparsedText = unparsedText
|
||||
result.parsedText = parsedText
|
||||
result.messageImage = image
|
||||
result.messageContainsMentions = messageContainsMentions
|
||||
result.timestamp = timestamp
|
||||
|
@ -184,6 +188,7 @@ proc initNewMessagesMarkerItem*(clock, timestamp: int64): Item =
|
|||
outgoingStatus = "",
|
||||
text = "",
|
||||
unparsedText = "",
|
||||
parsedText = @[],
|
||||
image = "",
|
||||
messageContainsMentions = false,
|
||||
seen = true,
|
||||
|
@ -226,6 +231,7 @@ proc `$`*(self: Item): string =
|
|||
resendError:{$self.resendError},
|
||||
messageText:{self.messageText},
|
||||
unparsedText:{self.unparsedText},
|
||||
parsedText:{$self.parsedText},
|
||||
messageContainsMentions:{self.messageContainsMentions},
|
||||
timestamp:{$self.timestamp},
|
||||
contentType:{$self.contentType.int},
|
||||
|
@ -324,6 +330,12 @@ proc unparsedText*(self: Item): string {.inline.} =
|
|||
proc `unparsedText=`*(self: Item, value: string) {.inline.} =
|
||||
self.unparsedText = value
|
||||
|
||||
proc parsedText*(self: Item): seq[ParsedText] {.inline.} =
|
||||
self.parsedText
|
||||
|
||||
proc `parsedText=`*(self: Item, value: seq[ParsedText]) {.inline.} =
|
||||
self.parsedText = value
|
||||
|
||||
proc messageImage*(self: Item): string {.inline.} =
|
||||
self.messageImage
|
||||
|
||||
|
|
|
@ -588,6 +588,7 @@ QtObject:
|
|||
messageId: string,
|
||||
updatedMsg: string,
|
||||
updatedRawMsg: string,
|
||||
updatedParsedText: seq[ParsedText],
|
||||
contentType: int,
|
||||
messageContainsMentions: bool,
|
||||
links: seq[string],
|
||||
|
@ -602,6 +603,7 @@ QtObject:
|
|||
self.items[ind].isEdited = true
|
||||
self.items[ind].links = links
|
||||
self.items[ind].mentionedUsersPks = mentionedUsersPks
|
||||
self.items[ind].parsedText = updatedParsedText
|
||||
|
||||
let index = self.createIndex(ind, 0, nil)
|
||||
self.dataChanged(index, index, @[
|
||||
|
|
|
@ -23,6 +23,7 @@ proc createTestMessageItem(id: string, clock: int64): Item =
|
|||
outgoingStatus = "",
|
||||
text = "",
|
||||
unparsedText = "",
|
||||
parsedText = @[],
|
||||
image = "",
|
||||
messageContainsMentions = false,
|
||||
seen = true,
|
||||
|
|
Loading…
Reference in New Issue