improve chat

This commit is contained in:
Peter Maquiran
2022-01-11 20:56:21 +01:00
parent 890048dc87
commit b8b4ba6a05
4 changed files with 44 additions and 21 deletions
+31 -5
View File
@@ -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
}
}