From 5fcb331f7e8542d097091f4397a35a8c9b7f0b9e Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Wed, 9 Feb 2022 15:27:10 +0100 Subject: [PATCH 01/27] save --- src/app/services/auth.service.ts | 14 +++++++------- src/app/services/chat/nf.service.ts | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 9a4e9ab49..f7cef3f8f 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -112,7 +112,7 @@ export class AuthService { //user: UserForm async loginChat() { - const expirationMinutes = 60; + const expirationMinutes = 30; let date = new Date().getTime(); let expirationDate = new Date(new Date().getTime() + expirationMinutes*60*1000); @@ -199,7 +199,7 @@ export class AuthService { } - this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => { + this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => { console.log('FILE TYPE', message.file.type) let downloadFile = ""; @@ -207,20 +207,20 @@ export class AuthService { const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise(); console.log('FILE TYPE 22', message.file.guid) - + if (event.type === HttpEventType.DownloadProgress) { //this.downloadProgess = Math.round((100 * event.loaded) / event.total); console.log('FILE TYPE 33', message.file.type) return true } else if (event.type === HttpEventType.Response) { downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - + message.file = { guid: message.file.guid, image_url: downloadFile, type: message.file.type } - + await this.storage.set(message.file.guid, downloadFile).then(() => { console.log('IMAGE SAVED') }); @@ -228,10 +228,10 @@ export class AuthService { } return false - + } }; - + }, 1) diff --git a/src/app/services/chat/nf.service.ts b/src/app/services/chat/nf.service.ts index cca0e4807..72c533cc5 100644 --- a/src/app/services/chat/nf.service.ts +++ b/src/app/services/chat/nf.service.ts @@ -7,8 +7,8 @@ import { RoomService } from './room.service'; }) export class NfService { - beforeSendAttachment = async (message: MessageService, room?: RoomService): Promise => new Promise ((resolve, reject)=> (resolve(true))) - downloadFileMsg = async (message: MessageService, room?: RoomService): Promise => new Promise ((resolve, reject)=> (resolve(true))) + beforeSendAttachment = async (message: MessageService, room?: RoomService): Promise => new Promise ((resolve, reject)=> (resolve(true))); + downloadFileMsg = async (message: MessageService, room?: RoomService): Promise => new Promise ((resolve, reject)=> (resolve(true))); constructor() { } } From 35b8eed2404e32afccb7bfc7148376951294d486 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 9 Feb 2022 15:34:25 +0100 Subject: [PATCH 02/27] merge --- src/app/pages/chat/group-messages/group-messages.page.ts | 4 ---- src/app/shared/chat/group-messages/group-messages.page.ts | 2 -- src/app/shared/chat/messages/messages.page.ts | 2 -- 3 files changed, 8 deletions(-) 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 dfe16ba9b..873f9f534 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -490,7 +490,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { const data = res.data; if(data.selected) { - const loader = this.toastService.loading(); this.wsChatMethodsService.getGroupRoom(this.roomId).send({ file:{ @@ -514,9 +513,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }] }) - - loader.remove(); - } }); } 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 402175eaa..d59adfc8e 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -596,7 +596,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe const data = res.data; if(data.selected) { - const loader = this.toastService.loading(); this.wsChatMethodsService.getGroupRoom(roomId).send({ file:{ @@ -621,7 +620,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe temporaryData: res }) - loader.remove(); } }); diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 29aca9233..bbe6e0297 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -532,7 +532,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy const roomId = this.roomId if(data.selected) { - const loader = this.toastService.loading(); this.wsChatMethodsService.getDmRoom(roomId).send({ file:{ @@ -552,7 +551,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy }], }) - loader.remove(); } }); From 86376adcb46d79c00ecadb2981d1aa39b0f58c09 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 9 Feb 2022 15:40:57 +0100 Subject: [PATCH 03/27] save --- src/app/services/chat/room.service.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 97ffd7398..5f81a1674 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -147,7 +147,9 @@ export class RoomService { addMessageDB(ChatMessage) { this.storage.get('chatmsg' + this.id).then((messages: any = []) => { - if(messages==null) messages = [] + if(!Array.isArray(messages)) { + messages = [] + } delete ChatMessage.temporaryData messages.push(ChatMessage) @@ -199,7 +201,9 @@ export class RoomService { */ private deleteMessageFromDb(id) { this.storage.get('chatmsg' + this.id).then((messages: any = []) => { - if(messages==null) messages = [] + if(!Array.isArray(messages)) { + messages = [] + } messages.forEach((message, index) => { @@ -330,7 +334,9 @@ export class RoomService { async restoreMessageFromDB() { await this.storage.get('chatmsg' + this.id).then( async (messages = []) => { - if(messages==null) messages = [] + if(!Array.isArray(messages)) { + messages = [] + } await messages.forEach( async (ChatMessage, index) => { const wewMessage = this.prepareMessage(ChatMessage, false) From 3679091e60a702490c125a680c45f2b44b8f787d Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 9 Feb 2022 15:54:57 +0100 Subject: [PATCH 04/27] improve --- src/app/services/chat/room.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 5f81a1674..fd74754e7 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -374,9 +374,9 @@ export class RoomService { this.prepareMessage(message) } - }); + }) - this.storage.set('chatmsg' + this.id, chatHistory) + this.storage.set('chatmsg' + this.id, chatHistory.result.messages) }) setTimeout(() => { From e06ddaca0497ba047442a8b506d8cfa01f800c5d Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Wed, 9 Feb 2022 16:05:06 +0100 Subject: [PATCH 05/27] save --- .../gabinete-digital/event-list/event-list.page.html | 2 +- src/app/pages/publications/publications.page.scss | 2 +- .../shared/agenda/event-list/event-list.page.html | 2 +- .../events-to-approve/events-to-approve.page.html | 2 +- .../publication/edit-action/edit-action.page.ts | 12 ++++++------ .../shared/publication/new-action/new-action.page.ts | 2 +- .../publication-detail/publication-detail.page.ts | 2 +- .../view-publications/view-publications.page.ts | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/app/pages/gabinete-digital/event-list/event-list.page.html b/src/app/pages/gabinete-digital/event-list/event-list.page.html index 2cad919fc..4cf249e2f 100644 --- a/src/app/pages/gabinete-digital/event-list/event-list.page.html +++ b/src/app/pages/gabinete-digital/event-list/event-list.page.html @@ -19,7 +19,7 @@ Calendário do MDGPR - Presidente da República + Calendário do Presidente da República diff --git a/src/app/pages/publications/publications.page.scss b/src/app/pages/publications/publications.page.scss index 84cd1fecb..931e4024f 100644 --- a/src/app/pages/publications/publications.page.scss +++ b/src/app/pages/publications/publications.page.scss @@ -233,7 +233,7 @@ ion-toolbar{ -@media only screen and (min-width: 801px) { +@media only screen and (min-width: 701px) { .content-right{ display: flex !important; width: 65%; diff --git a/src/app/shared/agenda/event-list/event-list.page.html b/src/app/shared/agenda/event-list/event-list.page.html index fb67da1f3..20f59f08d 100644 --- a/src/app/shared/agenda/event-list/event-list.page.html +++ b/src/app/shared/agenda/event-list/event-list.page.html @@ -14,7 +14,7 @@ Calendário do MDGPR - Presidente da República + Calendário do Presidente da República diff --git a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html index f18bfbe76..232ec7e6e 100644 --- a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html +++ b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html @@ -13,7 +13,7 @@ Calendário do MDGPR - Presidente da República + Calendário do Presidente da República diff --git a/src/app/shared/publication/edit-action/edit-action.page.ts b/src/app/shared/publication/edit-action/edit-action.page.ts index 0dba3d430..d3380bafc 100644 --- a/src/app/shared/publication/edit-action/edit-action.page.ts +++ b/src/app/shared/publication/edit-action/edit-action.page.ts @@ -29,7 +29,7 @@ export class EditActionPage implements OnInit { public stepSecond = 5; public dateControlStart = new FormControl(moment("DD MM YYYY hh")); public dateControlEnd = new FormControl(moment("DD MM YYYY hh")); - + folder: PublicationFolder; @Input() folderId: string; @Output() closeDesktopComponent= new EventEmitter(); @@ -39,7 +39,7 @@ export class EditActionPage implements OnInit { constructor( private publicationsService: PublicationsService, private toastService: ToastService, - ) { + ) { this.folder = new PublicationFolder(); } @@ -54,7 +54,7 @@ export class EditActionPage implements OnInit { getPublicationDetail() { this.publicationsService.GetPresidentialAction(this.folderId).subscribe( res => { this.folder = res; - + this.dateControlStart = new FormControl(moment(new Date(this.folder.DateBegin))); this.dateControlEnd = new FormControl(moment(new Date(this.folder.DateEnd))); @@ -62,7 +62,7 @@ export class EditActionPage implements OnInit { } get dateValid() { - if (window.innerWidth <= 800) { + if (window.innerWidth < 701) { return this.folder.DateBegin < this.folder.DateEnd? ['ok']: [] } else { return ['ok'] @@ -96,7 +96,7 @@ export class EditActionPage implements OnInit { ActionType: this.folder.ActionType, } console.log(body); - + const loader = this.toastService.loading() try { @@ -111,6 +111,6 @@ export class EditActionPage implements OnInit { } finally { loader.remove() } - + } } diff --git a/src/app/shared/publication/new-action/new-action.page.ts b/src/app/shared/publication/new-action/new-action.page.ts index 2fff042a3..a91343064 100644 --- a/src/app/shared/publication/new-action/new-action.page.ts +++ b/src/app/shared/publication/new-action/new-action.page.ts @@ -70,7 +70,7 @@ export class NewActionPage implements OnInit { } get dateValid() { - if (window.innerWidth >= 800) { + if (window.innerWidth > 700) { return new Date(this.folder.DateBegin).toLocaleString('pt') < new Date(this.folder.DateEnd).toLocaleString("pt")? ['ok'] : [] } else { return ['ok'] diff --git a/src/app/shared/publication/view-publications/publication-detail/publication-detail.page.ts b/src/app/shared/publication/view-publications/publication-detail/publication-detail.page.ts index 2890a9b3e..f9e8f9f19 100644 --- a/src/app/shared/publication/view-publications/publication-detail/publication-detail.page.ts +++ b/src/app/shared/publication/view-publications/publication-detail/publication-detail.page.ts @@ -108,7 +108,7 @@ export class PublicationDetailPage implements OnInit { async editPost(publicationType:any) { console.log(this.publication); - if(window.innerWidth <= 1024){ + if(window.innerWidth < 701){ const modal = await this.modalController.create({ component: NewPublicationPage, componentProps:{ diff --git a/src/app/shared/publication/view-publications/view-publications.page.ts b/src/app/shared/publication/view-publications/view-publications.page.ts index 7c132928a..5f2a5f21c 100644 --- a/src/app/shared/publication/view-publications/view-publications.page.ts +++ b/src/app/shared/publication/view-publications/view-publications.page.ts @@ -180,7 +180,7 @@ export class ViewPublicationsPage implements OnInit { async AddPublication(publicationType:any, folderId:any) { - if( window.innerWidth <= 1024) { + if( window.innerWidth < 701) { const modal = await this.modalController.create({ component: NewPublicationPage, componentProps:{ From faa30ee56ee723888789b945d0773dad31244f03 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 9 Feb 2022 17:06:12 +0100 Subject: [PATCH 06/27] improve --- .../chat/group-messages/group-messages.page.ts | 2 +- src/app/pages/chat/messages/messages.page.ts | 2 +- src/app/services/alert.service.ts | 6 ++++-- src/app/services/chat/room.service.ts | 16 ++++++++++++---- src/app/services/chat/ws-chat-methods.service.ts | 2 +- src/app/services/chat/ws-chat.service.ts | 2 +- .../chat/group-messages/group-messages.page.ts | 4 ++-- src/app/shared/chat/messages/messages.page.ts | 3 +-- 8 files changed, 23 insertions(+), 14 deletions(-) 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() { From cb039a3ebdb63fc71d4118466e07496808661bbc Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 9 Feb 2022 17:06:56 +0100 Subject: [PATCH 07/27] improve --- src/app/services/chat/ws-chat-methods.service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 7418057e8..8aa2b9ac0 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -66,6 +66,14 @@ export class WsChatMethodsService { type: 'reConnect', funx: ()=>{ this.subscribeToRoom() + + + if(this.getDmRoom(this.currentRoom)) { + this.getDmRoom(this.currentRoom).loadHistory({forceUpdate: true}) + } else if(this.getGroupRoom(this.currentRoom)) { + this.getGroupRoom(this.currentRoom).loadHistory({forceUpdate: true}) + } + } }) From dc92a085c312abf5e9ce9a9785a3319b850eda20 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Wed, 9 Feb 2022 17:07:32 +0100 Subject: [PATCH 08/27] save --- src/app/pages/gabinete-digital/event-list/event-list.page.html | 2 +- src/app/shared/agenda/event-list/event-list.page.html | 2 +- .../events-to-approve/events-to-approve.page.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/pages/gabinete-digital/event-list/event-list.page.html b/src/app/pages/gabinete-digital/event-list/event-list.page.html index 4cf249e2f..2cad919fc 100644 --- a/src/app/pages/gabinete-digital/event-list/event-list.page.html +++ b/src/app/pages/gabinete-digital/event-list/event-list.page.html @@ -19,7 +19,7 @@ Calendário do MDGPR - Calendário do Presidente da República + Presidente da República diff --git a/src/app/shared/agenda/event-list/event-list.page.html b/src/app/shared/agenda/event-list/event-list.page.html index 20f59f08d..fb67da1f3 100644 --- a/src/app/shared/agenda/event-list/event-list.page.html +++ b/src/app/shared/agenda/event-list/event-list.page.html @@ -14,7 +14,7 @@ Calendário do MDGPR - Calendário do Presidente da República + Presidente da República diff --git a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html index 232ec7e6e..f18bfbe76 100644 --- a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html +++ b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html @@ -13,7 +13,7 @@ Calendário do MDGPR - Calendário do Presidente da República + Presidente da República From 655f5edf63dbe1e19c293515ab6ae2aa390c9753 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 9 Feb 2022 17:08:40 +0100 Subject: [PATCH 09/27] improve --- src/app/services/chat/room.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index bb5d044c8..b16975015 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -190,7 +190,6 @@ 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) From f9c646c8eb90ff0296d71445b2a8c7e1945a946d Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 9 Feb 2022 17:30:05 +0100 Subject: [PATCH 10/27] improve --- src/app/services/chat/ws-chat-methods.service.ts | 1 - src/app/services/chat/ws-chat.service.ts | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 8aa2b9ac0..a6940d40f 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -67,7 +67,6 @@ export class WsChatMethodsService { funx: ()=>{ this.subscribeToRoom() - if(this.getDmRoom(this.currentRoom)) { this.getDmRoom(this.currentRoom).loadHistory({forceUpdate: true}) } else if(this.getGroupRoom(this.currentRoom)) { diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 28c7faf66..e84d4687f 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -629,7 +629,11 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { console.log('================== welcome to socket server =====================') - this.ws.wsMsgQueue() + + setTimeout(()=>{ + this.ws.wsMsgQueue() + }, 10) + if(this.wsReconnect >= 1) { for (const [key, value] of Object.entries(this.wsCallbacks)) { if(value.type== 'reConnect') { From a6823d9baedc82d8d5975693369c2b89ce719206 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 9 Feb 2022 17:30:38 +0100 Subject: [PATCH 11/27] improve --- src/app/services/chat/ws-chat.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index e84d4687f..2dc140a95 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -79,7 +79,9 @@ export class WsChatService { this.isLogin = true this.loginResponse = message - this.ws.wsMsgQueue() + setTimeout(()=>{ + this.ws.wsMsgQueue() + }, 10) resolve(message) } From da240623ddfd16001057539a344636e44531720f Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Wed, 9 Feb 2022 18:18:27 +0100 Subject: [PATCH 12/27] 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 } From 26a209502e7f6fe00a979a958dffc3b1e3e8ed97 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Thu, 10 Feb 2022 14:07:16 +0100 Subject: [PATCH 13/27] improve --- src/app/services/chat/message.service.ts | 26 +-- src/app/services/chat/room.service.ts | 165 ++++++++---------- .../services/chat/ws-chat-methods.service.ts | 52 +++--- src/app/services/chat/ws-chat.service.ts | 5 + src/environments/environment.ts | 2 +- 5 files changed, 122 insertions(+), 128 deletions(-) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 35c93720a..db5d0df49 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -5,6 +5,7 @@ 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 { environment } from 'src/environments/environment'; @Injectable({ providedIn: 'root' }) @@ -30,6 +31,7 @@ export class MessageService { sendAttempt = 0 uploadingFile = false errorUploadingAttachment = false + loadHistory = false constructor(private storage: Storage, private NfService: NfService, @@ -98,14 +100,15 @@ export class MessageService { this.sendAttempt++; if(!this.hasFile) { - console.log('simple send') this.WsChatService.send({roomId:this.rid, msg:this.msg}).then((data: any) => { - let ChatMessage = data.result - this.redefinedMessage(this, ChatMessage) - this.offline = false + if (environment.chatOffline) { + let ChatMessage = data.result + this.redefinedMessage(this, ChatMessage) + this.offline = false + } + }) } else { - console.log('complex send') this.uploadingFile = true @@ -122,10 +125,12 @@ export class MessageService { 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 - this.redefinedMessage(this, ChatMessage) - this.offline = false + if (environment.chatOffline) { + // console.log('send sucees', data.result) + let ChatMessage = data.result + this.redefinedMessage(this, ChatMessage) + this.offline = false + } }) } else if(this.WsChatService.isLogin == false) { @@ -133,8 +138,7 @@ export class MessageService { this.WsChatService.registerCallback({ type: 'reConnect', funx:()=> { - alert('reConnect') - // this.send() + this.send() return true } }) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index b16975015..11e1600c9 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -15,7 +15,7 @@ import { chatUser } from 'src/app/models/chatMethod'; import { environment } from 'src/environments/environment'; import { ChatService } from 'src/app/services/chat.service'; import { NfService } from 'src/app/services/chat/nf.service' -import alasql from 'alasql' + @Injectable({ providedIn: 'root' }) @@ -30,7 +30,7 @@ export class RoomService { t = '' name = '' _updatedAt = {} - private hasLoadHistory = false + hasLoadHistory = false duration = '' isTyping = false otherUserType = false @@ -67,15 +67,6 @@ 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 }) { @@ -99,41 +90,33 @@ export class RoomService { this.WsChatService.updateRoomEventss( this.id, "stream-room-messages", - (ChatMessage) => { + (_ChatMessage) => { - setTimeout(() => { - ChatMessage = ChatMessage.fields.args[0] + let ChatMessage = _ChatMessage.fields.args[0] - 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 - }); - + ChatMessage = this.fix_updatedAt(ChatMessage) + console.log('recivemessage', JSON.stringify(_ChatMessage)) - if(this.isSenderIsNotMe(ChatMessage)) { - this.addMessageDB(ChatMessage) - } - - } - }, 150) + const message = this.prepareMessage(ChatMessage) + this.lastMessage = message + this.calDateDuration(ChatMessage._updatedAt) + + if (message.t == 'r') { + this.name = message.msg + } + + if(this.isSenderIsNotMe(ChatMessage)) { + this.NativeNotificationService.sendNotificationChat({ + message: message.msg, + title: this.name + }); + } + + if(this.isSenderIsNotMe(ChatMessage)) { + // this.addMessageDB(ChatMessage) + } + + this.scrollDown() } ) @@ -242,20 +225,20 @@ export class RoomService { temporaryData } - this.addMessageDB(offlineChatMessage) - const message: MessageService = this.prepareMessage(offlineChatMessage) - - setTimeout(() => { - this.scrollDown() - }, 150) - - this.lastMessage = message - + const message: MessageService = this.prepareMessage(offlineChatMessage, environment.chatOffline) message.send() - - this.calDateDuration(message._updatedAt) - this.sortRoomList() + if (environment.chatOffline) { + this.addMessageDB(offlineChatMessage) + setTimeout(() => { + this.scrollDown() + }, 150) + + this.lastMessage = message + this.calDateDuration(message._updatedAt) + this.sortRoomList() + } + this.message= '' } @@ -340,46 +323,50 @@ export class RoomService { async restoreMessageFromDB() { - await this.storage.get('chatmsg' + this.id).then( async (messages = []) => { - if(!Array.isArray(messages)) { - messages = [] - } + if(environment.chatOffline) { - await messages.forEach( async (ChatMessage, index) => { - const wewMessage = this.prepareMessage(ChatMessage, false) - - if(wewMessage.offline == false) { - this.prepareMessage(ChatMessage) + await this.storage.get('chatmsg' + this.id).then( async (messages = []) => { + if(!Array.isArray(messages)) { + messages = [] } + + await messages.forEach( async (ChatMessage, index) => { + const wewMessage = this.prepareMessage(ChatMessage, false) + + if(wewMessage.offline == false) { + this.prepareMessage(ChatMessage) + } + + }); + + setTimeout(()=> { + this.scrollDown() + }, 50) + + }) - }); - - setTimeout(()=> { - this.scrollDown() - }, 50) - - }) + } } // runs onces only async loadHistory({limit = 100, forceUpdate = false }) { - if (this.hasLoadHistory || forceUpdate) { return false } + if(forceUpdate == false) { + if (this.hasLoadHistory) { + return false + } + } 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) - - if(wewMessage.offline == false) { - this.prepareMessage(message) - } + this.messages = this.sortService.sortDate(this.messages, '_updatedAt') }) @@ -399,22 +386,24 @@ export class RoomService { message = this.fix_updatedAt(message) const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService) wewMessage.setData(message) + wewMessage.loadHistory = this.hasLoadHistory + + if(!message._id && environment.chatOffline) { + this.messages.push(wewMessage) + return wewMessage + } - if (save) { + const found = this.messages.find((MessageService) => { + return MessageService._id == message._id + }) + + if (save && !found) { this.messages.push(wewMessage) } - + return wewMessage } - async returnData(res) { - - return res; - } - - - ReactToMessage() { } - private calDateDuration(date = null) { this.duration = showDateDuration(date || this._updatedAt); this._updatedAt = date || this._updatedAt diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index a6940d40f..caecf5ccc 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -19,9 +19,8 @@ import { NfService } from 'src/app/services/chat/nf.service' }) export class WsChatMethodsService { - dm = {} - group = {} - + dm: {[key: string]: RoomService} = {} + group: {[key: string]: RoomService} = {} _dm = [] _group = [] @@ -31,8 +30,7 @@ export class WsChatMethodsService { dmCount = 0; groupCount = 0; - - currentRoom = null + currentRoom: RoomService = null users: chatUser[] = [] constructor( @@ -57,20 +55,23 @@ export class WsChatMethodsService { })() - - /** - * @description when the phone is in the background for a long time it could disconnects from the socket then the socket reconnects automatically, - * when the connection is lost the subscribe is also lost, so we have to subscribe again when reconnection is establish. - */ this.WsChatService.registerCallback({ type: 'reConnect', funx: ()=>{ + /** + * @description when the phone is in the background for a long time it could disconnects from the socket then the socket reconnects automatically, + * when the connection is lost the subscribe is also lost, so we have to subscribe again when reconnection is establish. + */ this.subscribeToRoom() - if(this.getDmRoom(this.currentRoom)) { - this.getDmRoom(this.currentRoom).loadHistory({forceUpdate: true}) - } else if(this.getGroupRoom(this.currentRoom)) { - this.getGroupRoom(this.currentRoom).loadHistory({forceUpdate: true}) + this.currentRoom.loadHistory({forceUpdate: true}) + + for (const id in this.dm) { + this.dm[id].hasLoadHistory = false + } + + for (const id in this.group) { + this.group[id].hasLoadHistory = false } } @@ -117,27 +118,22 @@ export class WsChatMethodsService { this.prepareRoom(roomData); }); }) - }; + } + openRoom(roomId) { if(this.currentRoom) { - if(this.getDmRoom(this.currentRoom)) { - this.getDmRoom(this.currentRoom).roomLeave() - } else if(this.getGroupRoom(this.currentRoom)) { - this.getGroupRoom(this.currentRoom).roomLeave() - } + this.currentRoom.roomLeave() } - this.currentRoom = roomId - - if(this.currentRoom) { - if(this.getDmRoom(this.currentRoom)) { - this.getDmRoom(this.currentRoom).open() - } else if(this.getGroupRoom(this.currentRoom)) { - this.getGroupRoom(this.currentRoom).open() - } + if(this.getDmRoom(roomId)) { + this.currentRoom = this.getDmRoom(roomId) + } else if(this.getGroupRoom(roomId)) { + this.currentRoom = this.getGroupRoom(roomId) } + this.currentRoom.open() + } diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 2dc140a95..c50d480f0 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -677,6 +677,9 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { this.wsMsgQueue[requestId] = {message, requestId, loginRequired} } else { let messageStr = JSON.stringify(message) + + console.log('send', messageStr) + this.socket.send(messageStr) } return requestId @@ -685,6 +688,8 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { onmessage: async (event: any)=> { const data = JSON.parse(event.data) + console.log('onmessage', data) + for (const [key, value] of Object.entries(this.wsCallbacks)) { if(value.type== 'Onmessage') { const dontRepeat = await value.funx(data) diff --git a/src/environments/environment.ts b/src/environments/environment.ts index cd809f519..6bf93dabc 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -13,7 +13,7 @@ export const environment = { domain: 'gabinetedigital.local', //gabinetedigital.local defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local defaultuserpwd: 'tabteste@006', //tabteste@006, - chatOffline: true + chatOffline: false }; /* From df07cacbf0b292d3043f8f8e5e9ae3f9f3c2017e Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Thu, 10 Feb 2022 14:54:35 +0100 Subject: [PATCH 14/27] save --- src/app/services/chat/room.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 1b1b2bccd..6d50b2854 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -72,7 +72,6 @@ export class RoomService { this.WsChatService.registerCallback({ type: 'reConnect', funx: ()=>{ - alert("reConnect") this.hasLoadHistory = false } }) From 38b984f2ecb89e962b687627ea356ed54866dafd Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Thu, 10 Feb 2022 14:56:06 +0100 Subject: [PATCH 15/27] improve --- src/app/services/chat/message.service.ts | 26 +++--- src/app/services/chat/room.service.ts | 88 +++++++++++++------ .../services/chat/ws-chat-methods.service.ts | 55 +++++++++--- 3 files changed, 119 insertions(+), 50 deletions(-) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 34e4d4d54..9d6cc59ab 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -95,18 +95,22 @@ export class MessageService { } } - async send() { + async send(): Promise { this.sendAttempt++; if(!this.hasFile) { this.WsChatService.send({roomId:this.rid, msg:this.msg}).then((data: any) => { - if (environment.chatOffline) { - let ChatMessage = data.result + let ChatMessage = data.result + + if (environment.chatOffline) { this.redefinedMessage(this, ChatMessage) this.offline = false } + return new Promise((resolve, reject)=>{ + resolve(ChatMessage) + }) }) } else { @@ -125,21 +129,23 @@ export class MessageService { this.temporaryData = {} this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file}).then((data: any) => { - if (environment.chatOffline) { - // console.log('send sucees', data.result) - let ChatMessage = data.result + let ChatMessage = data.result + + if (environment.chatOffline) { this.redefinedMessage(this, ChatMessage) this.offline = false } + + return new Promise((resolve, reject)=>{ + resolve(ChatMessage) + }) }) } else if(this.WsChatService.isLogin == false) { - this.WsChatService.registerCallback({ type: 'reConnect', - funx:()=> { - this.send() - return true + funx: async ()=> { + return await this.send() } }) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index b19247335..35a24cb5a 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -14,7 +14,8 @@ import { SortService } from '../functions/sort.service'; import { chatUser } from 'src/app/models/chatMethod'; import { environment } from 'src/environments/environment'; import { ChatService } from 'src/app/services/chat.service'; -import { NfService } from 'src/app/services/chat/nf.service' +import { NfService } from 'src/app/services/chat/nf.service'; +import { v4 as uuidv4 } from 'uuid' @Injectable({ providedIn: 'root' @@ -164,6 +165,57 @@ export class RoomService { } + async updateMessageDB(ChatMessage, localReference) { + if (environment.chatOffline) { + this.storage.get('chatmsg' + this.id).then((messages: any = []) => { + if(!Array.isArray(messages)) { + messages = [] + } + + let index; + const find = messages.find((message, _index)=> { + if(message.localReference == ChatMessage.localReference) { + index = _index + return true + } + + return false + }) + + if(!find) { + messages[index] = ChatMessage + this.storage.set('chatmsg' + this.id, messages) + } + + }) + } + + } + + /** + * @description delete message in the DB. get all messages, delete then corresponding message and update the store + * @param id message ID + */ + private deleteMessageFromDb(id) { + this.storage.get('chatmsg' + this.id).then((messages: any = []) => { + if(!Array.isArray(messages)) { + messages = [] + } + + messages.forEach((message, index) => { + + if(message._id == id) { + messages.splice(index, 1) + } + + }) + + this.storage.set('chatmsg' + this.id, messages).then((value) => { + console.log('MSG SAVED ON STORAGE', value) + }); + }) + } + async receiveMessageDelete() { this.WsChatService.updateRoomEventss( @@ -201,46 +253,26 @@ export class RoomService { } - /** - * @description delete message in the DB. get all messages, delete then corresponding message and update the store - * @param id message ID - */ - private deleteMessageFromDb(id) { - this.storage.get('chatmsg' + this.id).then((messages: any = []) => { - if(!Array.isArray(messages)) { - messages = [] - } - - messages.forEach((message, index) => { - - if(message._id == id) { - messages.splice(index, 1) - } - - }) - - this.storage.set('chatmsg' + this.id, messages).then((value) => { - console.log('MSG SAVED ON STORAGE', value) - }); - }) - } - /** * @description sen text message */ async send({file = null, attachments = null, temporaryData = {}}) { + const localReference = uuidv4() let offlineChatMessage = { rid: this.id, msg: this.message, attachments, file, - temporaryData + temporaryData, + localReference } const message: MessageService = this.prepareMessage(offlineChatMessage, environment.chatOffline) - message.send() + message.send().then((ChatMessage) => { + this.updateMessageDB(ChatMessage, localReference) + }) if (environment.chatOffline) { this.addMessageDB(offlineChatMessage) @@ -349,6 +381,8 @@ export class RoomService { if(wewMessage.offline == false) { this.prepareMessage(ChatMessage) + } else { + } }); diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index caecf5ccc..f31adf4d3 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -13,7 +13,7 @@ import { NativeNotificationService } from 'src/app/services/native-notification. import { SortService } from '../functions/sort.service'; import { chatUser } from 'src/app/models/chatMethod'; import { NfService } from 'src/app/services/chat/nf.service' - +import { ChangeProfileService } from '../change-profile.service'; @Injectable({ providedIn: 'root' }) @@ -42,18 +42,10 @@ export class WsChatMethodsService { private sortService: SortService, private ChatService: ChatService, private NfService: NfService, + private changeProfileService: ChangeProfileService, ) { - (async()=>{ - await this.restoreRooms() - await this.getAllRooms(); - this.subscribeToRoom() - - - // - await this.getUser() - this.getUserStatus() - - })() + + this.loadChat() this.WsChatService.registerCallback({ type: 'reConnect', @@ -64,7 +56,9 @@ export class WsChatMethodsService { */ this.subscribeToRoom() - this.currentRoom.loadHistory({forceUpdate: true}) + if(this.currentRoom) { + this.currentRoom.loadHistory({forceUpdate: true}) + } for (const id in this.dm) { this.dm[id].hasLoadHistory = false @@ -77,6 +71,11 @@ export class WsChatMethodsService { } }) + this.changeProfileService.registerCallback(()=>{ + this.clearChat() + this.ReLoadChat() + }) + // this.WsChatService.registerCallback({ // type:'Onmessage', @@ -112,6 +111,36 @@ export class WsChatMethodsService { } + private loadChat() { + this.ReLoadChat() + } + + async ReLoadChat() { + await this.restoreRooms() + await this.getAllRooms(); + this.subscribeToRoom() + + + // + await this.getUser() + this.getUserStatus() + } + + clearChat() { + this.dm = {} + this.group = {} + this._dm = [] + this._group = [] + + this.loadingWholeList = false + + this.dmCount = 0; + this.groupCount = 0; + + this.currentRoom = null + this.users = [] + } + getRoomFromDb() { this.storage.get('Rooms').then((rooms) => { rooms.result.update.forEach((roomData: room) => { From 19194a56cc28a9c5ac9f94127716ca7a59d51b46 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Thu, 10 Feb 2022 15:01:50 +0100 Subject: [PATCH 16/27] improve --- src/app/services/chat/ws-chat-methods.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index f31adf4d3..7aef0cae3 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -74,6 +74,7 @@ export class WsChatMethodsService { this.changeProfileService.registerCallback(()=>{ this.clearChat() this.ReLoadChat() + this.storage.remove('Rooms'); }) From be0bd474560dce831c0834307178a752bd8ac0ca Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Thu, 10 Feb 2022 15:23:37 +0100 Subject: [PATCH 17/27] improve --- src/app/services/chat/room.service.ts | 49 +++++++++++++++------------ src/environments/environment.ts | 2 +- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index a3908258b..6ed13e20e 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -174,15 +174,17 @@ export class RoomService { let index; const find = messages.find((message, _index)=> { - if(message.localReference == ChatMessage.localReference) { - index = _index - return true + if(message.localReference) { + if(message.localReference == ChatMessage.localReference) { + index = _index + return true + } } return false }) - if(!find) { + if(find) { messages[index] = ChatMessage this.storage.set('chatmsg' + this.id, messages) } @@ -197,23 +199,25 @@ export class RoomService { * @param id message ID */ private deleteMessageFromDb(id) { - this.storage.get('chatmsg' + this.id).then((messages: any = []) => { - if(!Array.isArray(messages)) { - messages = [] - } - - messages.forEach((message, index) => { - - if(message._id == id) { - messages.splice(index, 1) + if (environment.chatOffline) { + this.storage.get('chatmsg' + this.id).then((messages: any = []) => { + if(!Array.isArray(messages)) { + messages = [] } - + + messages.forEach((message, index) => { + + if(message._id == id) { + messages.splice(index, 1) + } + + }) + + this.storage.set('chatmsg' + this.id, messages).then((value) => { + console.log('MSG SAVED ON STORAGE', value) + }); }) - - this.storage.set('chatmsg' + this.id, messages).then((value) => { - console.log('MSG SAVED ON STORAGE', value) - }); - }) + } } async receiveMessageDelete() { @@ -384,7 +388,10 @@ export class RoomService { if(wewMessage.offline == false) { this.prepareMessage(ChatMessage) } else { - + const offlineMessage = this.prepareMessage(ChatMessage) + offlineMessage.send().then(()=>{ + this.updateMessageDB(ChatMessage, ChatMessage.localReference) + }) } }); @@ -461,11 +468,9 @@ export class RoomService { private fix_updatedAt(message) { if (message.result) { - //console.log('FIX UPDATE ', message.result) message.result._updatedAt = message.result._updatedAt['$date'] } else if(message._updatedAt) { if(message._updatedAt.hasOwnProperty('$date')) { - // console.log('FIX UPDATE 11', message) message._updatedAt = message._updatedAt['$date'] } } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 6bf93dabc..cd809f519 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -13,7 +13,7 @@ export const environment = { domain: 'gabinetedigital.local', //gabinetedigital.local defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local defaultuserpwd: 'tabteste@006', //tabteste@006, - chatOffline: false + chatOffline: true }; /* From 0cc6c1a84f948e974a7b2dfd783d1856f00a832a Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Thu, 10 Feb 2022 15:27:13 +0100 Subject: [PATCH 18/27] improve --- src/app/services/chat/room.service.ts | 5 ++++- src/app/services/chat/ws-chat.service.ts | 4 ---- src/environments/environment.ts | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 6ed13e20e..a4cc1e8f3 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -114,7 +114,10 @@ export class RoomService { } this.addMessageDB(ChatMessage) - this.scrollDown() + + setTimeout(()=>{ + this.scrollDown() + }, 50) } ) diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index c50d480f0..ddf514cf1 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -678,8 +678,6 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { } else { let messageStr = JSON.stringify(message) - console.log('send', messageStr) - this.socket.send(messageStr) } return requestId @@ -688,8 +686,6 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { onmessage: async (event: any)=> { const data = JSON.parse(event.data) - console.log('onmessage', data) - for (const [key, value] of Object.entries(this.wsCallbacks)) { if(value.type== 'Onmessage') { const dontRepeat = await value.funx(data) diff --git a/src/environments/environment.ts b/src/environments/environment.ts index cd809f519..6bf93dabc 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -13,7 +13,7 @@ export const environment = { domain: 'gabinetedigital.local', //gabinetedigital.local defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local defaultuserpwd: 'tabteste@006', //tabteste@006, - chatOffline: true + chatOffline: false }; /* From 0e5cb537976e666fbd4cee6a1eb149e72740b0e0 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Thu, 10 Feb 2022 15:33:34 +0100 Subject: [PATCH 19/27] save --- src/app/pages/gabinete-digital/event-list/event-list.page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/pages/gabinete-digital/event-list/event-list.page.html b/src/app/pages/gabinete-digital/event-list/event-list.page.html index 2cad919fc..63d07d0d0 100644 --- a/src/app/pages/gabinete-digital/event-list/event-list.page.html +++ b/src/app/pages/gabinete-digital/event-list/event-list.page.html @@ -16,7 +16,7 @@ - Calendário do MDGPR + Calendário MDGPR Presidente da República From 808ad8c19f738191c44be90e1d3800f7bb29c929 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Thu, 10 Feb 2022 15:50:11 +0100 Subject: [PATCH 20/27] fix date --- .../pages/chat/group-messages/group-messages.page.html | 6 +++--- src/app/pages/chat/messages/messages.page.html | 6 +++--- src/app/services/chat/message.service.ts | 8 ++++++++ src/app/services/chat/room.service.ts | 4 ++-- .../shared/chat/group-messages/group-messages.page.html | 6 +++--- src/app/shared/chat/messages/messages.page.html | 6 +++--- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/app/pages/chat/group-messages/group-messages.page.html b/src/app/pages/chat/group-messages/group-messages.page.html index 07b81b08a..dc522f73c 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -60,7 +60,7 @@
{{msg.u.name ?? ""}} - {{showDateDuration(msg._updatedAt)}} + {{msg.duration}}
{{msg.msg}} @@ -75,7 +75,7 @@
{{msg.u.name ?? ""}} - {{showDateDuration(msg._updatedAt)}} + {{msg.duration}}
{{msg.msg}} @@ -96,7 +96,7 @@
{{msg.u.name ?? ""}} - {{showDateDuration(msg._updatedAt)}} + {{msg.duration}}
diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 8b0b8ccfc..cf8e17568 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -53,7 +53,7 @@
{{msg.u.name}} - {{showDateDuration(msg._updatedAt)}} + {{msg.duration}}
{{msg.msg}} @@ -64,7 +64,7 @@