update chat list

This commit is contained in:
Peter Maquiran
2022-01-28 19:01:24 +01:00
parent 151e1ea8ad
commit 2a0744e9ae
4 changed files with 81 additions and 45 deletions
@@ -19,6 +19,10 @@ export class WsChatMethodsService {
dm: {[key: string]: RoomService} = {}
group: {[key: string]: RoomService} = {}
_dm = []
_group = []
loadingWholeList = false
dmCount = 0;
@@ -45,23 +49,42 @@ export class WsChatMethodsService {
const rooms = await this.WsChatService.getRooms();
this.WsChatService.registerCallback({
type:'Onmessage',
funx:(message)=>{
if(message.msg =='changed' && message.collection == "stream-room-messages") {
if(message.fields.args[0].rid) {
setTimeout(()=>{
console.log('sort this._dm', this._dm)
this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse()
this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse()
}, 100)
}
}
if(message.msg =='changed' && message.collection == "stream-notify-room") {
if(message.fields.eventName.includes('deleteMessage')){
setTimeout(()=>{
console.log('sort this._dm', this._dm)
this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse()
this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse()
}, 100)
}
}
}
})
rooms.result.update.forEach((roomData: room) => {
this.prepareRoom(roomData);
await rooms.result.update.forEach( async (roomData: room) => {
await this.prepareRoom(roomData);
});
this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse()
this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse()
this.loadingWholeList = false
}
@@ -138,9 +161,11 @@ export class WsChatMethodsService {
console.log(room);
this.dm[roomId] = room
this._dm.push(room)
this.dmCount++
} else {
this.group[roomId] = room
this._group.push(room)
this.groupCount++
}
}