diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index 873f9f534..15212fee8 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -109,7 +109,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } }; - this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); + this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory({}); this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked; this.wsChatMethodsService.openRoom(this.roomId) diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index e9142db52..4879f1454 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -124,7 +124,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } }; - this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() + this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({}) this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked this.wsChatMethodsService.openRoom(this.roomId) diff --git a/src/app/services/alert.service.ts b/src/app/services/alert.service.ts index 447b18fe4..4c58508a2 100644 --- a/src/app/services/alert.service.ts +++ b/src/app/services/alert.service.ts @@ -43,7 +43,6 @@ export class AlertService { } async confirmDeleteMessage(msgId:any, room:any) { - console.log(room); const alert = await this.alertController.create({ cssClass: 'my-custom-class', @@ -60,7 +59,10 @@ export class AlertService { text: 'Apagar', handler: () => { //const loader = this.toastService.loading(); - this.wsChatMethodsService.deleteMessage(msgId); + + this.wsChatMethodsService.deleteMessage(msgId).then(()=>{ + room.deleteMessage(msgId) + }) //this.wsChatMethodsService.subscribeToRoomUpdate(room._id, room); //loader.remove(); } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index fd74754e7..bb5d044c8 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -67,6 +67,15 @@ export class RoomService { private NfService: NfService ) { this.NativeNotificationService.askForPermission() + + + this.WsChatService.registerCallback({ + type: 'reConnect', + funx: ()=>{ + this.hasLoadHistory = false + } + }) + } setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService), _updatedAt }) { @@ -181,6 +190,7 @@ export class RoomService { deleteMessage(id) { this.messages.forEach((message, index) => { if(message._id == id) { + alert('found and delete') this.messages.splice(index, 1) this.deleteMessageFromDb(id) @@ -232,8 +242,6 @@ export class RoomService { file, temporaryData } - - console.log('offlineChatMessage', offlineChatMessage) this.addMessageDB(offlineChatMessage) const message: MessageService = this.prepareMessage(offlineChatMessage) @@ -355,9 +363,9 @@ export class RoomService { } // runs onces only - async loadHistory(limit = 100) { + async loadHistory({limit = 100, forceUpdate = false }) { - if (this.hasLoadHistory) { return false } + if (this.hasLoadHistory || forceUpdate) { return false } this.restoreMessageFromDB() diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 509b61c96..7418057e8 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -210,7 +210,7 @@ export class WsChatMethodsService { this.prepareRoom(roomData); - this.getGroupRoom(id).loadHistory(); + this.getGroupRoom(id).loadHistory({}); } diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index dd84856c6..28c7faf66 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -273,7 +273,7 @@ export class WsChatService { return new Promise ((resolve, reject) => { this.ws.registerCallback({type:'Onmessage', funx:(message) =>{ - if(message.id == requestId || deepFind(message, 'result') == requestId){ + if(message.id == requestId ){ resolve(message) return true } diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts index d638e2edb..3f059690e 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -121,7 +121,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe this.getRoomInfo(); //this.scrollToBottom(); - this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); + this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory({}); // console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).messages); this.wsChatMethodsService.openRoom(this.roomId) this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked @@ -272,7 +272,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } async getRoomInfo() { - this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); + this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory({}); let room = await this.chatService.getRoomInfo(this.roomId).toPromise(); this.room = room['room']; if (this.room.name) { diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index bbe6e0297..49d05b16f 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -110,7 +110,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } ngOnChanges(changes: SimpleChanges): void { - this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() + this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({}) this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked @@ -124,7 +124,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.scrollToBottomClicked() }, 150) - } ngOnInit() {