diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 2fc1a0aab..35e529c30 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -581,7 +581,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { const roomId = this.roomId if(data.selected) { - const loader = this.toastService.loading(); this.wsChatMethodsService.getDmRoom(roomId).send({ file:{ @@ -603,8 +602,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { }], }) - loader.remove(); - } }); } diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index b33c0f323..35c93720a 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -5,7 +5,6 @@ import { SessionStore } from 'src/app/store/session.service'; import { capitalizeTxt } from 'src/plugin/text' import { NfService } from 'src/app/services/chat/nf.service' import { WsChatService } from 'src/app/services/chat/ws-chat.service'; -import { type } from 'os'; @Injectable({ providedIn: 'root' }) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 0e0f7a6e6..2fc0eb8ad 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -93,11 +93,14 @@ export class RoomService { (ChatMessage) => { ChatMessage = ChatMessage.fields.args[0] - if(environment.chatOffline == false || this.isSenderIsNotMe(ChatMessage)) { - - ChatMessage = this.fix_updatedAt(ChatMessage) - console.log('recivemessage', ChatMessage) - + ChatMessage = this.fix_updatedAt(ChatMessage) + // console.log('recivemessage', ChatMessage) + + const messageIsFound = this.messages.find((message) => { + message._id == ChatMessage._id + }) + + if(!messageIsFound) { const message = this.prepareMessage(ChatMessage) this.lastMessage = message @@ -114,8 +117,8 @@ export class RoomService { }); this.addMessageDB(ChatMessage) - } + } ) @@ -323,10 +326,10 @@ export class RoomService { if(messages==null) messages = [] await messages.forEach( async (ChatMessage, index) => { - const wewMessage = this.prepareMessage(ChatMessage) + const wewMessage = this.prepareMessage(ChatMessage, false) - if(wewMessage.offline == true) { - wewMessage.send() + if(wewMessage.offline == false) { + this.prepareMessage(ChatMessage) } }); @@ -335,7 +338,6 @@ export class RoomService { this.scrollDown() }, 50) - }) } @@ -344,7 +346,7 @@ export class RoomService { if (this.hasLoadHistory) { return false } - await this.restoreMessageFromDB() + this.restoreMessageFromDB() await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { console.log('loadHistory', chatHistory) @@ -352,13 +354,6 @@ export class RoomService { await chatHistory.result.messages.reverse().forEach( async (message) => { this.prepareMessage(message) - - // const result = alasql(`SELECT * FROM ? WHERE _id = "${message._id}" `,[ this.messages]); - // if(result.length == 0) { - // this.prepareMessage(message) - // this.storage.set('chatmsg' + this.id, chatHistory.result.messages.concat([message])) - // } - }); }) @@ -372,11 +367,15 @@ export class RoomService { - prepareMessage(message): MessageService { + prepareMessage(message, save = true): MessageService { message = this.fix_updatedAt(message) const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService) wewMessage.setData(message) - this.messages.push(wewMessage) + + if (save) { + this.messages.push(wewMessage) + } + return wewMessage } diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index a10357427..509b61c96 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -69,7 +69,7 @@ export class WsChatMethodsService { } }) - // console.log("ROOMS" + JSON.stringify(rooms)) + // this.WsChatService.registerCallback({ // type:'Onmessage', // funx:(message) => { @@ -85,10 +85,8 @@ export class WsChatMethodsService { // }, 100) // } - // } - - // if(message.msg =='changed' && message.collection == "stream-notify-room") { - // if(message.fields.eventName.includes('deleteMessage')){ + // } else if(message.msg =='changed' && message.collection == "stream-notify-room") { + // if(message.fields.eventName.includes('deleteMessage')) { // // delete message // const DeletedMessageId = message.fields.args[0]._id; @@ -96,6 +94,8 @@ export class WsChatMethodsService { // this.sortRoomList() // }, 100) + // } else if(message.fields.eventName.includes('typing')) { + // } // } // } diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 444582c57..d3cfa0b47 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -614,7 +614,6 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { let id = params.requestId || params.key || uuidv4() this.wsCallbacks[id] = params this.n++ - console.log('n', this.n) return id }, connect:()=> { @@ -680,6 +679,8 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { onmessage: async (event: any)=> { const data = JSON.parse(event.data) + console.log('data', data) + for (const [key, value] of Object.entries(this.wsCallbacks)) { if(value.type== 'Onmessage') { const dontRepeat = await value.funx(data) diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 9124bdee1..1edc23fc2 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -276,7 +276,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } } - changeInput() { this.wsChatMethodsService.getDmRoom(this.roomId).typing() }