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()
})
})
}
+9 -6
View File
@@ -4,7 +4,6 @@ import { MessageLocalDataSourceService } from 'src/app/module/chat/data/reposito
import { whatsappDate } from '../../shared/utils/whatappdate';
import { XBallon } from '../utils/messageBallon';
import { Observable, Subscription } from 'rxjs';
import { RoomTable } from 'src/app/infra/database/dexie/instance/chat/schema/room';
import { RoomLocalRepository } from 'src/app/module/chat/data/repository/room/room-local-repository.service'
import { RoomViewModel } from './model/room';
import { IDBoolean } from 'src/app/infra/database/dexie/type';
@@ -16,7 +15,6 @@ import { Observable as DexieObservable } from 'Dexie';
import { tap } from 'rxjs/operators';
import { MemberTable } from 'src/app/infra/database/dexie/instance/chat/schema/members';
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
import { TypingTable } from 'src/app/infra/database/dexie/instance/chat/schema/typing';
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service'
import { UserTypingLocalRepository } from 'src/app/module/chat/data/repository/typing/user-typing-local-data-source.service';
import { Result } from 'neverthrow';
@@ -369,9 +367,16 @@ export class RoomStore {
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)
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)
}
if(!found) {
const msg = new MessageViewModal(message as any)
Object.assign(msg, message)
@@ -379,9 +384,7 @@ export class RoomStore {
}
}
this.messages1[this.room.$id].sort((a, b) => {
return new Date(a.sentAt).getTime() - new Date(b.sentAt).getTime()
})
})
}