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 52def20c47..9efd83a680 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 @@ -62,8 +62,7 @@ proc init*(self: Controller) = var args = MessagesArgs(e) if(self.chatId != args.chatId): return - for message in args.messages: - self.delegate.messageAdded(message) + self.delegate.messagesAdded(args.messages) self.events.on(SIGNAL_SENDING_SUCCESS) do(e:Args): let args = MessageSendingSuccess(e) diff --git a/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim index 515c984ddf..25b8961930 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim @@ -44,7 +44,7 @@ method onPinMessage*(self: AccessInterface, messageId: string, actionInitiatedBy method onUnpinMessage*(self: AccessInterface, messageId: string) {.base.} = raise newException(ValueError, "No implementation available") -method messageAdded*(self: AccessInterface, message: MessageDto) {.base.} = +method messagesAdded*(self: AccessInterface, messages: seq[MessageDto]) {.base.} = raise newException(ValueError, "No implementation available") method onSendingMessageSuccess*(self: AccessInterface, message: MessageDto) {.base.} = 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 a3a88e3a3b..5c32bdf4bb 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 @@ -289,79 +289,84 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se self.view.initialMessagesAreLoaded() -method messageAdded*(self: Module, message: MessageDto) = - let sender = self.controller.getContactDetails(message.`from`) +method messagesAdded*(self: Module, messages: seq[MessageDto]) = + var items: seq[Item] - let renderedMessageText = self.controller.getRenderedText(message.parsedText) + for message in messages: + let sender = self.controller.getContactDetails(message.`from`) - var transactionContract = message.transactionParameters.contract - var transactionValue = message.transactionParameters.value - var isCurrentUser = sender.isCurrentUser - if message.contentType.ContentType == ContentType.Transaction: - (transactionContract, transactionValue) = self.controller.getTransactionDetails(message) - if message.transactionParameters.fromAddress != "": - isCurrentUser = self.currentUserWalletContainsAddress(message.transactionParameters.fromAddress) - # remove a message which has replace parameters filled - let index = self.view.model().findIndexForMessageId(message.replace) - if(index != -1): - self.view.model().removeItem(message.replace) + let renderedMessageText = self.controller.getRenderedText(message.parsedText) - # https://github.com/status-im/status-desktop/issues/7632 will introduce deleteFroMe feature. - # Now we just skip deleted messages - if message.deleted or message.deletedForMe: - return + var transactionContract = message.transactionParameters.contract + var transactionValue = message.transactionParameters.value + var isCurrentUser = sender.isCurrentUser + if message.contentType.ContentType == ContentType.Transaction: + (transactionContract, transactionValue) = self.controller.getTransactionDetails(message) + if message.transactionParameters.fromAddress != "": + isCurrentUser = self.currentUserWalletContainsAddress(message.transactionParameters.fromAddress) + # remove a message which has replace parameters filled + let index = self.view.model().findIndexForMessageId(message.replace) + if(index != -1): + self.view.model().removeItem(message.replace) - var item = initItem( - message.id, - message.communityId, - message.responseTo, - message.`from`, - sender.defaultDisplayName, - sender.optionalName, - sender.icon, - (isCurrentUser and message.contentType.ContentType != ContentType.DiscordMessage), - sender.details.added, - message.outgoingStatus, - renderedMessageText, - message.text, - message.image, - message.containsContactMentions(), - message.seen, - timestamp = message.whisperTimestamp, - clock = message.clock, - message.contentType.ContentType, - message.messageType, - message.contactRequestState, - sticker = message.sticker.url, - message.sticker.pack, - message.links, - newTransactionParametersItem(message.transactionParameters.id, - message.transactionParameters.fromAddress, - message.transactionParameters.address, - transactionContract, - transactionValue, - message.transactionParameters.transactionHash, - message.transactionParameters.commandState, - message.transactionParameters.signature), - message.mentionedUsersPks, - sender.details.trustStatus, - sender.details.ensVerified, - message.discordMessage, - resendError = "", - message.mentioned, - message.quotedMessage.`from`, - message.quotedMessage.text, - self.controller.getRenderedText(message.quotedMessage.parsedText), - message.quotedMessage.contentType, - message.quotedMessage.deleted, - ) + # https://github.com/status-im/status-desktop/issues/7632 will introduce deleteFroMe feature. + # Now we just skip deleted messages + if message.deleted or message.deletedForMe: + return - self.view.model().insertItemBasedOnClock(item) + var item = initItem( + message.id, + message.communityId, + message.responseTo, + message.`from`, + sender.defaultDisplayName, + sender.optionalName, + sender.icon, + (isCurrentUser and message.contentType.ContentType != ContentType.DiscordMessage), + sender.details.added, + message.outgoingStatus, + renderedMessageText, + message.text, + message.image, + message.containsContactMentions(), + message.seen, + timestamp = message.whisperTimestamp, + clock = message.clock, + message.contentType.ContentType, + message.messageType, + message.contactRequestState, + sticker = message.sticker.url, + message.sticker.pack, + message.links, + newTransactionParametersItem(message.transactionParameters.id, + message.transactionParameters.fromAddress, + message.transactionParameters.address, + transactionContract, + transactionValue, + message.transactionParameters.transactionHash, + message.transactionParameters.commandState, + message.transactionParameters.signature), + message.mentionedUsersPks, + sender.details.trustStatus, + sender.details.ensVerified, + message.discordMessage, + resendError = "", + message.mentioned, + message.quotedMessage.`from`, + message.quotedMessage.text, + self.controller.getRenderedText(message.quotedMessage.parsedText), + message.quotedMessage.contentType, + message.quotedMessage.deleted, + ) + + items.add(item) + + self.view.model().insertItemsBasedOnClock(items) method removeNewMessagesMarker*(self: Module) method onSendingMessageSuccess*(self: Module, message: MessageDto) = - self.messageAdded(message) + self.messagesAdded(@[message]) self.view.emitSendingMessageSuccessSignal() self.removeNewMessagesMarker()