From 2a0744e9ae7b4ec71aa166dcedbed6cfe729115e Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 28 Jan 2022 19:01:24 +0100 Subject: [PATCH] update chat list --- src/app/pages/chat/chat.page.html | 80 +++++++++---------- src/app/services/chat/room.service.ts | 1 + .../services/chat/ws-chat-methods.service.ts | 33 +++++++- src/app/services/functions/sort.service.ts | 12 ++- 4 files changed, 81 insertions(+), 45 deletions(-) diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index dd476be02..05200b433 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -42,48 +42,48 @@
+ *ngFor="let room of wsChatMethodsService._dm" + [class.item-active]="room.id == idSelected">
- - + +
-
-
+
- {{room.value.name}} + {{room.name}}
-
{{room.value.duration}}
+
{{room.duration}}
-
+
- {{room.value.lastMessage.msg}} - A escrever ... - - + {{room.lastMessage.msg}} + A escrever ... + + -
- +
+ - - {{room.value.lastMessage.file.name || room.value.lastMessage.file.subject }} + + {{room.lastMessage.file.name || room.lastMessage.file.subject }}
- -
- + +
+ Fotografia
@@ -110,37 +110,37 @@ -
- - + +
+ (click)="openGroupMessagesPage(group.id)" class="item-content flex-grow-1 cursor-pointer">
-
- {{group.value.name.split('-').join(' ')}} +
+ {{group.name.split('-').join(' ')}}
-
{{group.value.duration}}
-
{{countDownDate(group.value.customFields.countDownDate, group.value.id)}}
+
{{group.duration}}
+
{{countDownDate(group.customFields.countDownDate, group.id)}}
-
-
{{group.value.lastMessage.u.name}}: {{group.value.lastMessage.msg}}
-
{{group.value.userThatIsTyping}} A escrever ...
+
+
{{group.lastMessage.u.name}}: {{group.lastMessage.msg}}
+
{{group.userThatIsTyping}} A escrever ...
-
- - - {{group.value.lastMessage.file.name || group.value.file.subject}} +
+ + + {{group.lastMessage.file.name || group.file.subject}}
-
-
- +
+
+ Fotografia
diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 013661877..fe700ca88 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -427,6 +427,7 @@ export class RoomService { private calDateDuration(date = null) { this.duration = showDateDuration(date || this._updatedAt); + this._updatedAt = date || this._updatedAt } diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index c1b238f3c..207c94784 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -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++ } } diff --git a/src/app/services/functions/sort.service.ts b/src/app/services/functions/sort.service.ts index dc4c4b84f..6f65ab277 100644 --- a/src/app/services/functions/sort.service.ts +++ b/src/app/services/functions/sort.service.ts @@ -26,8 +26,18 @@ export class SortService { } sortDate(array = [], path: string) { + return array.sort( (a,b)=> { - return new Date(this.ObjectService.deepFind(b, path)).getTime() - new Date(this.ObjectService.deepFind(a, path)).getTime() + + /* console.log("AAA"+new Date(this.ObjectService.deepFind(a, path))); + + console.log("BB"+new Date(this.ObjectService.deepFind(b, path))); */ + + return (new Date(this.ObjectService.deepFind(a, path)) < new Date(this.ObjectService.deepFind(b, path))) ? -1 : ((new Date(this.ObjectService.deepFind(a, path)) > new Date(this.ObjectService.deepFind(b, path))) ? 1 : 0); + + //return new Date(this.ObjectService.deepFind(b, path)).getTime() - new Date(this.ObjectService.deepFind(a, path)).getTime(); + }) + } }