diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts
index c39f473f3..656e38716 100644
--- a/src/app/home/home.page.ts
+++ b/src/app/home/home.page.ts
@@ -94,7 +94,7 @@ export class HomePage implements OnInit {
private sqliteservice: SqliteService,
private RouteService: RouteService,
private RocketChatClientService: RocketChatClientService) {
- window['jj'] = ()=>{
+ window['jj'] = ()=> {
//send message // roomId // Message
this.RocketChatClientService.send('fsMwcNdufWvdnChj7ya9nF9cX2HizxxWAM', 'Mensagem enviada programaticamente.'+ new Date().toISOString())
}
diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html
index 09b092845..141e2871c 100644
--- a/src/app/pages/chat/chat.page.html
+++ b/src/app/pages/chat/chat.page.html
@@ -67,7 +67,7 @@
-
+
{{room.value.duration}}
{{room.value.lastMessage.msg}}
diff --git a/src/app/services/chat/chat.service.ts b/src/app/services/chat/chat.service.ts
index b8e1e92c4..501c26195 100644
--- a/src/app/services/chat/chat.service.ts
+++ b/src/app/services/chat/chat.service.ts
@@ -36,26 +36,23 @@ export class ChatService {
rooms.result.update.forEach((roomData:any) => {
let room:RoomService;
+
+ room = new RoomService(this.RocketChatClientService, new MessageService())
+ room.setData({
+ id: this.getRoomId(roomData),
+ name: this.getChatName(roomData),
+ lastMessage: this.getRoomLastMessage(roomData),
+ _updatedAt: roomData._updatedAt['$date']
+ })
+
+ room.receiveMessage()
let roomId = roomData.lastMessage.rid
+
if(this.isIndividual(roomData)) {
- room = new RoomService(this.RocketChatClientService, new MessageService())
- room.setData({
- id: this.getRoomId(roomData),
- name: this.getChatName(roomData),
- lastMessage: this.getRoomLastMessage(roomData)
- })
- room.receiveMessage()
this.individual[roomId] = room
this.individualCount++
} else {
- room = new RoomService(this.RocketChatClientService, new MessageService())
- room.setData({
- id: this.getRoomId(roomData),
- name: this.getChatName(roomData),
- lastMessage: this.getRoomLastMessage(roomData)
- })
- room.receiveMessage()
this.group[roomId] = room
this.groupCount++
}
diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts
index d0af942f4..ef85e84a0 100644
--- a/src/app/services/chat/room.service.ts
+++ b/src/app/services/chat/room.service.ts
@@ -2,6 +2,9 @@ import { Injectable } from '@angular/core'
import { RocketChatClientService } from 'src/app/services/socket/rocket-chat-client.service';
import { MessageService } from 'src/app/services/chat/message.service'
import { ChatUserService } from 'src/app/services/chat/chat-user.service'
+import { TimeService } from 'src/app/services/functions/time.service';
+import { ChatService } from '../chat.service';
+import { showDateDuration } from 'src/plugin/showDateDuration'
@Injectable({
providedIn: 'root'
})
@@ -13,20 +16,24 @@ export class RoomService {
chatUser: ChatUserService[] = []
id = ''
name = ''
+ _updatedAt = {}
private hasLoadHistory = false
+ duration = ''
+
constructor(
public RocketChatClientService: RocketChatClientService,
- private MessageService: MessageService
- ) {
-
- }
+ private MessageService: MessageService,
+ ) {}
- setData({id, name, lastMessage}) {
+ setData({id, name, lastMessage, _updatedAt}) {
this.id = id
this.name = name
this.lastMessage = lastMessage
+ this._updatedAt = _updatedAt
+
+ this.calDateDuration()
}
receiveMessage() {
@@ -34,9 +41,12 @@ export class RoomService {
this.id,
this.constructor.name+this.id,
(Chatmessage) => {
+
+ Chatmessage = this.fix_updatedAt(Chatmessage)
const message = new MessageService()
message.setData(Chatmessage.result)
this.massages.push(message)
+ this.calDateDuration(Chatmessage.result._updatedAt)
}
)
}
@@ -54,6 +64,8 @@ export class RoomService {
console.log('loadHistory', message)
message.result.messages.reverse().forEach(element => {
+ console.log('element', element)
+ element = this.fix_updatedAt(element)
const message = new MessageService()
message.setData(element)
this.massages.push(message)
@@ -68,4 +80,18 @@ export class RoomService {
deleteMessage(msgId) {}
ReactToMessage() {}
+ private calDateDuration(date = null) {
+ this.duration = showDateDuration(date || this._updatedAt);
+ }
+
+
+ private fix_updatedAt(message) {
+ if(message.result) {
+ message.result._updatedAt = message.result._updatedAt['$date']
+ } else{
+ message._updatedAt = message._updatedAt['$date']
+ }
+ return message
+ }
+
}