feat(chat): add messages in bulk instead one by one

iterates: #3067
This commit is contained in:
Patryk Osmaczko 2023-01-13 12:26:56 +01:00 committed by osmaczko
parent a21bebcacc
commit b26565e653
3 changed files with 71 additions and 67 deletions

View File

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

View File

@ -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.} =

View File

@ -289,7 +289,10 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
self.view.initialMessagesAreLoaded()
method messageAdded*(self: Module, message: MessageDto) =
method messagesAdded*(self: Module, messages: seq[MessageDto]) =
var items: seq[Item]
for message in messages:
let sender = self.controller.getContactDetails(message.`from`)
let renderedMessageText = self.controller.getRenderedText(message.parsedText)
@ -356,12 +359,14 @@ method messageAdded*(self: Module, message: MessageDto) =
message.quotedMessage.deleted,
)
self.view.model().insertItemBasedOnClock(item)
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()