mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
fix message order on reconect
This commit is contained in:
@@ -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()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user