diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index f80ffec0d..98673fe9c 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -122,6 +122,8 @@ export class RoomService { setTimeout(()=>{ this.scrollDown() }, 50) + //Sort list of messages from recent to old + this.sortRoomList() } diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 8e2768753..7bf65778a 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -199,6 +199,7 @@ export class WsChatMethodsService { * @description sort room list by last message date */ sortRoomList =() => { + this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse() this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse() } @@ -252,6 +253,16 @@ export class WsChatMethodsService { }) } + private fix_updatedAt(message) { + if (message.result) { + message.result._updatedAt = message.result._updatedAt['$date'] + } else if(message._updatedAt) { + if(message._updatedAt.hasOwnProperty('$date')) { + message._updatedAt = message._updatedAt['$date'] + } + } + return message + } /** * @description create a representation of an room in these instance this.dm, this.group ... @@ -263,13 +274,16 @@ export class WsChatMethodsService { /** * @description data used to define or create room */ + + + roomData = this.fix_updatedAt(roomData) const setData = { customFields: roomData.customFields, id: this.getRoomId(roomData), name: this.getRoomName(roomData), t: roomData.t, lastMessage: this.getRoomLastMessage(roomData), - _updatedAt: new Date(roomData._updatedAt['$date']) + _updatedAt: roomData._updatedAt } let roomId = this.getRoomId(roomData) @@ -282,7 +296,7 @@ export class WsChatMethodsService { room.getAllUsers = this.getUsers room.receiveMessageDelete(); room.sortRoomList = this.sortRoomList - + // create individual room if(this.isIndividual(roomData)) { @@ -398,9 +412,9 @@ export class WsChatMethodsService { } hidingRoom(id?) { - + return this.WsChatService.hidingRoom(id).then(()=>{ - // this.hideRoom(id) + // this.hideRoom(id) }) }