fix message order on reconect

This commit is contained in:
Peter Maquiran
2024-10-10 11:08:32 +01:00
parent 9c65bee69c
commit cbe535899f
5 changed files with 29 additions and 18 deletions
@@ -369,19 +369,24 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.messageOnReconnectSubject?.unsubscribe()
this.messageOnReconnectSubject = this.chatServiceService.listenToMessageLoadHistory({roomId: this.room.id}).subscribe((messages) => {
for(const message of messages.data) {
for(const message of messages.data.reverse()) {
const found = this.messages1[this.room.$id].find((e) => e.id == message.id)
if(!found) {
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.room.$id].push(Ballon)
}
const msg = new MessageViewModal(message as any)
Object.assign(msg, message)
this.messages1[this.room.$id].push(msg)
}
}
this.messages1[this.room.$id].sort((a, b) => {
return new Date(a.sentAt).getTime() - new Date(b.sentAt).getTime()
})
})
}