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
+1 -1
View File
@@ -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())
}
+1 -1
View File
@@ -67,7 +67,7 @@
</span>
</ion-label>
</div>
<!-- <div class="item-date" [class.item-date-active]="dm._id == idSelected">{{showDateDuration(dm._updatedAt)}}</div> -->
<div class="item-date" [class.item-date-active]="room.value.id == idSelected">{{room.value.duration}}</div>
</div>
<div *ngIf="room.value.lastMessage" class="item-description" [class.item-description-active]="room.value.id == idSelected">
<ion-label *ngIf="room.value.lastMessage">{{room.value.lastMessage.msg}}</ion-label>
+11 -14
View File
@@ -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++
}
+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
}
}