From 4b66eb67132db849227740c8eb6847e189f6252d Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Thu, 10 Feb 2022 21:50:15 +0100 Subject: [PATCH] improve --- src/app/services/chat/message.service.ts | 2 +- src/app/services/chat/room.service.ts | 10 +++--- .../services/chat/ws-chat-methods.service.ts | 35 ++++++++++++------- src/environments/environment.ts | 2 +- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 131ba4ca5..d84e7c530 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -143,7 +143,7 @@ export class MessageService { let ChatMessage = message.result if (environment.chatOffline) { - this.redefinedMessage(ChatMessage) + // this.redefinedMessage(ChatMessage) this.offline = false } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 91db0c881..255975f0d 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -80,6 +80,8 @@ export class RoomService { this._updatedAt = _updatedAt this.calDateDuration() + + this.restoreMessageFromDB() } @@ -94,7 +96,6 @@ export class RoomService { "stream-room-messages", (_ChatMessage) => { console.log('recivemessage', _ChatMessage) - alert('receive and send to view') let ChatMessage = _ChatMessage.fields.args[0] ChatMessage = this.fix_updatedAt(ChatMessage) @@ -270,7 +271,7 @@ export class RoomService { */ async send({file = null, attachments = null, temporaryData = {}}) { - const localReference = uuidv4() + 'peter' + const localReference = uuidv4() let offlineChatMessage = { rid: this.id, @@ -403,7 +404,7 @@ export class RoomService { if(wewMessage.offline == false) { this.prepareMessage(ChatMessage) } else { - if(environment.chatOffline) alert('create offline') + const offlineMessage = this.prepareMessage(ChatMessage) this.messagesLocalReference.push(offlineMessage.localReference) @@ -432,7 +433,6 @@ export class RoomService { return false } } - await this.restoreMessageFromDB() await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { console.log('loadHistory', chatHistory) @@ -464,7 +464,6 @@ export class RoomService { wewMessage.loadHistory = this.hasLoadHistory if(!message._id && environment.chatOffline && save) { - if(this.hasLoadHistory && environment.chatOffline) alert('create offline') this.messages.push(wewMessage) return wewMessage @@ -480,7 +479,6 @@ export class RoomService { }) if (save && !found) { - if(this.hasLoadHistory && environment.chatOffline) alert('not found') this.messages.push(wewMessage) } diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 7aef0cae3..bef7ee9c6 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -193,11 +193,6 @@ export class WsChatMethodsService { console.log('rooms', rooms) - this.dm = {} - this.group = {} - this._dm = [] - this._group = [] - await rooms.result.update.forEach( async (roomData: room) => { await this.prepareRoom(roomData); }); @@ -273,14 +268,17 @@ export class WsChatMethodsService { room = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService) - room.setData({ + + 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']) - }) + } + + room.setData(setData) room.receiveMessage() room.getAllUsers = this.getUsers @@ -290,13 +288,24 @@ export class WsChatMethodsService { let roomId = this.getRoomId(roomData) if(this.isIndividual(roomData)) { - this.dm[roomId] = room - this._dm.push(room) - this.dmCount++ + + if(!this.dm[roomId]) { + this.dm[roomId] = room + this._dm.push(room) + this.dmCount++ + } else { + this.dm[roomId].setData(setData) + } + } else { - this.group[roomId] = room - this._group.push(room) - this.groupCount++ + if(this.group[roomId]) { + this.group[roomId] = room + this._group.push(room) + this.groupCount++ + } else { + this.group[roomId].setData(setData) + } + } } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 6bf93dabc..cd809f519 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -13,7 +13,7 @@ export const environment = { domain: 'gabinetedigital.local', //gabinetedigital.local defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local defaultuserpwd: 'tabteste@006', //tabteste@006, - chatOffline: false + chatOffline: true }; /*