From da240623ddfd16001057539a344636e44531720f Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Wed, 9 Feb 2022 18:18:27 +0100 Subject: [PATCH] save --- src/app/services/chat/message.service.ts | 13 ++++---- src/app/services/chat/room.service.ts | 38 +++++++++++++----------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 35c93720a..1deff1038 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -37,7 +37,7 @@ export class MessageService { } setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData}:Message) { - this.customFields = customFields + this.customFields = customFields this.channels = channels || [] this.mentions = mentions || [] this.msg = msg || "" @@ -78,7 +78,7 @@ export class MessageService { const firstName = capitalizeTxt(username.split('.')[0]) const lastName = capitalizeTxt(username.split('.')[1]) return firstName + ' ' + lastName - } + } getFileFromDb() { @@ -113,14 +113,14 @@ export class MessageService { if(this.hasSendAttachment == false) { uploadSuccessfully = await this.NfService.beforeSendAttachment(this) } - + this.uploadingFile = false if(uploadSuccessfully || this.hasSendAttachment == false) { this.hasSendAttachment = true this.errorUploadingAttachment = false this.temporaryData = {} - + this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file}).then((data: any) => { console.log('send sucees', data.result) let ChatMessage = data.result @@ -133,7 +133,6 @@ export class MessageService { this.WsChatService.registerCallback({ type: 'reConnect', funx:()=> { - alert('reConnect') // this.send() return true } @@ -143,11 +142,11 @@ export class MessageService { this.errorUploadingAttachment = true } - + } } - redefinedMessage(messagem, ChatMessage) { + redefinedMessage(messagem, ChatMessage) { this.setData(ChatMessage) } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index b16975015..1b1b2bccd 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -24,7 +24,7 @@ export class RoomService { messages: MessageService[] = [] storageMessage: any[] = []; lastMessage: MessageService; - + customFields: any; id = '' t = '' @@ -72,6 +72,7 @@ export class RoomService { this.WsChatService.registerCallback({ type: 'reConnect', funx: ()=>{ + alert("reConnect") this.hasLoadHistory = false } }) @@ -106,32 +107,32 @@ export class RoomService { ChatMessage = this.fix_updatedAt(ChatMessage) // console.log('recivemessage', ChatMessage) - + const messageIsFound = this.messages.find((message) => { return message._id == ChatMessage._id }) - + if(!messageIsFound) { const message = this.prepareMessage(ChatMessage) - + this.lastMessage = message if (message.t == 'r') { this.name = message.msg } this.calDateDuration(ChatMessage._updatedAt) - + setTimeout(() => { this.scrollDown() }, 100) - + this.NativeNotificationService.sendNotificationChat({ message: message.msg, title: this.name }); - + if(this.isSenderIsNotMe(ChatMessage)) { this.addMessageDB(ChatMessage) } - + } }, 150) @@ -241,7 +242,7 @@ export class RoomService { file, temporaryData } - + this.addMessageDB(offlineChatMessage) const message: MessageService = this.prepareMessage(offlineChatMessage) @@ -255,7 +256,7 @@ export class RoomService { this.calDateDuration(message._updatedAt) this.sortRoomList() - + this.message= '' } @@ -357,29 +358,32 @@ export class RoomService { setTimeout(()=> { this.scrollDown() }, 50) - + }) } // runs onces only - async loadHistory({limit = 100, forceUpdate = false }) { + async loadHistory({limit = 50, forceUpdate = false }) { - if (this.hasLoadHistory || forceUpdate) { return false } + if (this.hasLoadHistory || forceUpdate) { + return false + } - this.restoreMessageFromDB() + await this.restoreMessageFromDB() await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { console.log('loadHistory', chatHistory) + this.messages = [] await chatHistory.result.messages.reverse().forEach( async (message) => { this.prepareMessage(message) - const wewMessage = this.prepareMessage(message, false) + /* const wewMessage = this.prepareMessage(message, false) if(wewMessage.offline == false) { this.prepareMessage(message) - } + } */ }) @@ -403,7 +407,7 @@ export class RoomService { if (save) { this.messages.push(wewMessage) } - + return wewMessage }