diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 897d610bf..4d067250b 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -39,7 +39,7 @@ export class RoomService { } receiveMessage() { - this.WsChatService.receiveLiveMessageFromRoom( + this.WsChatService.receiveMyMessageConfirmation( this.id, (ChatMessage:ChatMessage) => { @@ -51,6 +51,20 @@ export class RoomService { this.ToastService.presentToast('nova mensagem') } ) + + this.WsChatService.receiveLiveMessageFromRoom( + this.id, + (ChatMessage) => { + ChatMessage = ChatMessage.fields.args[0] + ChatMessage = this.fix_updatedAt(ChatMessage) + const message = new MessageService() + this.ToastService.presentToast('nova mensagem') + message.setData(ChatMessage) + this.massages.push(message) + this.calDateDuration(ChatMessage.result._updatedAt) + + } + ) } send(msg) { diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 845fd0d80..d1effbdce 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -27,6 +27,7 @@ export class WsChatMethodsService { (async()=>{ await this.getAllRooms(); this.subscribeToRoom() + })() } @@ -69,20 +70,20 @@ export class WsChatMethodsService { }); - console.log('this.group', this.group) this.loadingWholeList = false } subscribeToRoom() { + for (const id in this.dm) { this.WsChatService.streamRoomMessages(id).then((subscription)=>{ - // console.log('subscription', subscription) + console.log('streamRoomMessages', subscription) }) } for (const id in this.group) { this.WsChatService.streamRoomMessages(id).then((subscription)=>{ - // console.log('subscription', subscription) + console.log('streamRoomMessages', subscription) }) } } diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 33e460866..9dcad106b 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -74,13 +74,11 @@ export class WsChatService { if(message.id == requestId ) { // same request send if(message.result) { - console.log(message) if(message.result.token) { this.isLogin = true this.loginResponse = message - console.log('wsMsgQueue', this.wsMsgQueue) this.ws.wsMsgQueue() resolve(message) @@ -242,7 +240,7 @@ export class WsChatService { * @param key * @param funx */ - receiveLiveMessageFromRoom(roomId, funx: Function) { + receiveMyMessageConfirmation(roomId, funx: Function) { this.ws.registerCallback({ type:'Onmessage', @@ -261,6 +259,21 @@ export class WsChatService { } + receiveLiveMessageFromRoom(roomId, funx: Function) { + + this.ws.registerCallback({ + type:'Onmessage', + funx:(message)=>{ + if(message.msg =='changed' && message.collection == 'stream-room-messages') { + if(message.fields.args[0].rid == roomId) { + funx(message) + } + } + } + }) + } + + streamRoomMessages(roomId : string) { const requestId = uuidv4() @@ -270,7 +283,7 @@ export class WsChatService { "id": requestId, "name": "stream-room-messages", "params":[ - `${roomId}/event`, + `${roomId}`, false ] } @@ -279,7 +292,7 @@ export class WsChatService { return new Promise((resolve, reject) => { this.ws.registerCallback({type:'Onmessage', funx:(message)=>{ - if(message.msg == 'ready' || deepFind(message, 'subs.0') == requestId) { // same request send + if(message.id == requestId) { // same request send resolve(message) return true } @@ -375,7 +388,6 @@ export class WsChatService { }, onmessage:(event: any)=> { - // if(this.ws.connected == false) { return true } const data = JSON.parse(event.data) for (const [key, value] of Object.entries(this.wsCallbacks)) {