From c357966d2eaf09294ee727a7362840236a2fe70f Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Sat, 17 Dec 2022 12:34:56 +0100 Subject: [PATCH] fix chat eror --- src/app/services/chat/chat-system.service.ts | 8 +++++--- src/app/services/chat/message.service.ts | 17 ++++++++++++++--- src/app/services/chat/room.service.ts | 13 +++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/app/services/chat/chat-system.service.ts b/src/app/services/chat/chat-system.service.ts index d1d9716d0..17f212e13 100644 --- a/src/app/services/chat/chat-system.service.ts +++ b/src/app/services/chat/chat-system.service.ts @@ -95,10 +95,12 @@ export class ChatSystemService { } loadChat() { - this.ReLoadChat() + if(SessionStore.user.ChatData) { + this.ReLoadChat() + } } - async ReLoadChat() { + private async ReLoadChat() { await this.chatService.refreshtoken(); await this.restoreUsers(); @@ -400,7 +402,7 @@ export class ChatSystemService { if (setData.name != 'Rocket Cat') { // create room if(!this.roomExist(roomId)) { - let room:RoomService = new RoomService(this.RochetChatConnectorService, new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this) + let room:RoomService = new RoomService(this.RochetChatConnectorService, new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this) room.setData(setData) room.receiveMessage() room.getAllUsers = this.getUsers diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 299f98e87..56e5606d3 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -12,7 +12,7 @@ import { AESEncrypt } from '../aesencrypt.service' import { HttpEventType } from '@angular/common/http'; import { AttachmentsService } from 'src/app/services/attachments.service'; import { NetworkServiceService , ConnectionStatus} from 'src/app/services/network-service.service'; - +import { ChatSystemService } from './chat-system.service'; @Injectable({ providedIn: 'root' }) @@ -67,7 +67,8 @@ export class MessageService { private ChatMethodsService: ChatMethodsService, private AESEncrypt: AESEncrypt, private AttachmentsService: AttachmentsService, - private NetworkServiceService: NetworkServiceService) { + private NetworkServiceService: NetworkServiceService, + private ChatSystemService: ChatSystemService) { } setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, from }:Message) { @@ -119,6 +120,17 @@ export class MessageService { } } + if(!this.u.name && this.u.username) { + const user = this.ChatSystemService.users.find((u)=> u.username == this.u.username) + if(user) { + this.u.name = user.name + } else if( this.u.username == SessionStore.user.UserName) { + this.u.name = SessionStore.user.FullName + } else { + // console.log(user.username, SessionStore.user.UserName) + } + } + this.calDateDuration() } @@ -203,7 +215,6 @@ export class MessageService { // console.log('online send') this.RochetChatConnectorService.send(params).then( (ChatMessage: any) => { - console.log('response') ChatMessage = ChatMessage.message.result this.messageSend = true diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 12c98a042..826b29e0a 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -184,7 +184,7 @@ export class RoomService { } } - setData({membersExcludeMe, members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), _updatedAt }) { + setData({membersExcludeMe, members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this.ChatSystemService), _updatedAt }) { this.customFields = customFields this.id = id this.name = name @@ -710,10 +710,11 @@ export class RoomService { } else { const offlineMessage = await this.prepareMessageCreateIfNotExist({message:ChatMessage}) - offlineMessage.from = 'Offline' - offlineMessage.loadHistory = this.hasLoadHistory if(offlineMessage) { + offlineMessage.from = 'Offline' + offlineMessage.loadHistory = this.hasLoadHistory + this.messagesLocalReference.push(offlineMessage.localReference) offlineMessage?.decryptMessage() @@ -827,7 +828,7 @@ export class RoomService { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) + const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this.ChatSystemService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -884,7 +885,7 @@ export class RoomService { async prepareCreate({message, save = true}): Promise { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) + const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this.ChatSystemService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -922,7 +923,7 @@ export class RoomService { simplePrepareMessage(message) { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) + const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this.ChatSystemService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory