From bf89e468416cca7863800d7aa06efec843d39156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 8 Aug 2023 15:40:10 +0100 Subject: [PATCH] Improve tinymce autosave and notification web click solved --- src/app/home/home.page.ts | 5 -- .../gabinete-digital.page.html | 2 +- src/app/services/chat/room.service.ts | 6 +-- .../services/native-notification.service.ts | 19 ++++--- src/app/services/notifications.service.ts | 53 +++++++++++++------ src/app/tiny-mce/tiny-mce.page.html | 3 +- src/app/tiny-mce/tiny-mce.page.ts | 48 +++++++++-------- src/firebase-messaging-sw.js | 14 ++++- src/main.ts | 10 ++++ version/git-version.ts | 12 ++--- 10 files changed, 109 insertions(+), 63 deletions(-) diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 046881b4e..6df14dbf7 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -18,7 +18,6 @@ import { ActiveTabService } from 'src/app/services/active-tab.service'; import { Device } from '@capacitor/device'; import { RouteService } from 'src/app/services/route.service'; import { NetworkServiceService, ConnectionStatus } from 'src/app/services/network-service.service'; -import { NativeNotificationService } from 'src/app/services/native-notification.service'; import { UserSession } from '../models/user.model'; import { PermissionList } from '../models/permission/permissionList'; @@ -85,7 +84,6 @@ export class HomePage implements OnInit { private eventservice: EventsService, private processservice: ProcessesService, public RouteService: RouteService, - private NativeNotificationService: NativeNotificationService, private RochetChatConnectorService: RochetChatConnectorService, private NetworkServiceService: NetworkServiceService, public eventService: EventsService, @@ -96,9 +94,6 @@ export class HomePage implements OnInit { this.user = SessionStore.user; } - this.NativeNotificationService.askForPermission(); - this.NativeNotificationService.foregroundNotification(); - this.router.events.subscribe((val) => { document.querySelectorAll('ion-modal').forEach((e: any) => e.remove()) document.querySelectorAll('popover-viewport').forEach((e: any) => e.remove()) diff --git a/src/app/pages/gabinete-digital/gabinete-digital.page.html b/src/app/pages/gabinete-digital/gabinete-digital.page.html index be5e26a73..d7f2d6d58 100644 --- a/src/app/pages/gabinete-digital/gabinete-digital.page.html +++ b/src/app/pages/gabinete-digital/gabinete-digital.page.html @@ -713,7 +713,7 @@ Pendentes
{{ TaskService.pendentesstore.newList.length}} correspondências novas - {{ + {{ TaskService.pendentesstore.newList.length}} correspondência nova

Meus diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 7398111a8..e3a0859b8 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -102,7 +102,7 @@ export class RoomService { private ViewedMessageService: ViewedMessageService, private notificationService: NotificationsService ) { - this.NativeNotificationService.askForPermission() + /* this.NativeNotificationService.askForPermission() */ this.RochetChatConnectorService.getUserStatus((d) => { @@ -337,10 +337,10 @@ export class RoomService { } if(this.isSenderIsNotMe(ChatMessage)) { - this.NativeNotificationService.sendNotificationChat({ + /* this.NativeNotificationService.sendNotificationChat({ message: message.msg, title: this.name - }); + }); */ } if(this.hasLoadHistory == true) { diff --git a/src/app/services/native-notification.service.ts b/src/app/services/native-notification.service.ts index e2359e9d4..e4f5335e5 100644 --- a/src/app/services/native-notification.service.ts +++ b/src/app/services/native-notification.service.ts @@ -15,26 +15,33 @@ export class NativeNotificationService { askForPermission() { - LocalNotifications.requestPermissions() + /* LocalNotifications.requestPermissions() LocalNotifications.checkPermissions().then((data)=>{ // }).catch((data)=>{ // - }) + }) */ } foregroundNotification() { - LocalNotifications.addListener('localNotificationReceived', (notification) => { + /* LocalNotifications.addListener('localNotificationReceived', (notification) => { - }) + }) */ + } + + backgroundNotification() { + /* LocalNotifications.addListener('localNotificationActionPerformed', (action) => { + console.log('Local notification action performed (background):', action); + // Implemente a lógica para lidar com a ação da notificação em segundo plano + }); */ } sendNotificationChat({title = 'User', icon = '', message = 'hello'}) { - LocalNotifications.schedule({ + /* LocalNotifications.schedule({ notifications:[ { title : title, @@ -42,7 +49,7 @@ export class NativeNotificationService { id : new Date().getTime() } ] - }); + }); */ } diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts index 23eb8bf2b..c673e9ce7 100644 --- a/src/app/services/notifications.service.ts +++ b/src/app/services/notifications.service.ts @@ -188,25 +188,44 @@ export class NotificationsService { } onReciveBackground() { - if (!this.isPushNotificationsAvailable) { - return false - } - PushNotifications.addListener('pushNotificationActionPerformed', - (notification: ActionPerformed) => { - this.active = true - console.log('NOtification Listener Backgroud', notification) - /* this.DataArray.push(notification.notification) - - this.storageService.store("Notifications", this.DataArray) - this.eventtrigger.publishSomeData({ - notification: "recive" - }) */ - this.notificatinsRoutes(notification) - // this.runNotificationCallback(notification) + if(this.platform.is('mobile')) { + if (!this.isPushNotificationsAvailable) { + return false } - ); + + PushNotifications.addListener('pushNotificationActionPerformed', + (notification: ActionPerformed) => { + this.active = true + console.log('NOtification Listener Backgroud', notification) + /* this.DataArray.push(notification.notification) + + this.storageService.store("Notifications", this.DataArray) + this.eventtrigger.publishSomeData({ + notification: "recive" + }) */ + this.notificatinsRoutes(notification) + // this.runNotificationCallback(notification) + } + ); + } else { + navigator.serviceWorker.onmessage = (event) => { + console.log('Mensagem recebida do Service Worker:', event.data.data); + let object = { + notification: event.data + } + + this.notificatinsRoutes(object) + // Implemente a lógica para lidar com a mensagem recebida do Service Worker + if (event.data.notificationClicked) { + console.log('Notificação push do Firebase clicada em segundo plano!'); + // Implemente ações adicionais conforme necessário + } + }; + } + } + ChatSendMessageNotification(userID, title, bodymsg, roomId) { const geturl = environment.apiURL + `notifications/sendbyUsername`; @@ -250,7 +269,7 @@ export class NotificationsService { notificatinsRoutes = (notification) => { - +console.log('BACK BACK',notification) if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) { diff --git a/src/app/tiny-mce/tiny-mce.page.html b/src/app/tiny-mce/tiny-mce.page.html index 11b8ee213..340e10835 100644 --- a/src/app/tiny-mce/tiny-mce.page.html +++ b/src/app/tiny-mce/tiny-mce.page.html @@ -26,7 +26,7 @@ language: 'pt_PT', height: 600, menubar: false, - autosave_interval:30, + autosave_interval:'3s', plugins: [ 'advlist autolink autosave lists link image charmap print preview anchor', 'searchreplace visualblocks code fullscreen', @@ -40,4 +40,5 @@ initialValue='{{content}}' [(ngModel)]="content" (onSaveContent)="somefunction()" + (ngModelChange)="onEditorContentChange()" > \ No newline at end of file diff --git a/src/app/tiny-mce/tiny-mce.page.ts b/src/app/tiny-mce/tiny-mce.page.ts index bc2042f4f..7f81ce975 100644 --- a/src/app/tiny-mce/tiny-mce.page.ts +++ b/src/app/tiny-mce/tiny-mce.page.ts @@ -19,7 +19,7 @@ export class TinyMCEPage implements OnDestroy { editorContent: ""; value: ""; private intervalId: any; - private intervalTime: number = 30000; + private intervalTime: number = 3000; loadingTiny = true @@ -37,7 +37,7 @@ export class TinyMCEPage implements OnDestroy { this.waitForTiny(); - this.saveDraft(); + /* this.saveDraft(); */ } waitForTiny() { @@ -59,37 +59,39 @@ export class TinyMCEPage implements OnDestroy { ngOnDestroy() { // Certifique-se de limpar o intervalo quando o componente é destruído - if (this.intervalId) { - clearInterval(this.intervalId); - } + window['tinyupdate']() } close() { this.modalController.dismiss() } + onEditorContentChange() { + console.log('Autosave successful! Content saved to local storage1.'); + this.saveDraft() + } + saveDraft() { - this.intervalId = setInterval(() => { - // Lógica que deseja executar em intervalos regulares - console.log('Intervalo de 30 segundos...'); - console.log(document) - let objectDraft = { - "status": false, - "description": this.Document.Assunto, - "content": this.content, - "path": this.Document.path, - "ownerId": this.Document.ownerId - } - this.processService.SaveDraftByID(this.Document.DocId, objectDraft).subscribe((res) => { - window['tinyupdate']() - }, (error) => { - this.erroHandler.httpStatusHandle(error) - }) - }, this.intervalTime); + // Lógica que deseja executar em intervalos regulares + console.log('Intervalo de 3 segundos...'); + console.log(document) + let objectDraft = { + "status": false, + "description": this.Document.Assunto, + "content": this.content, + "path": this.Document.path, + "ownerId": this.Document.ownerId + } + this.processService.SaveDraftByID(this.Document.DocId, objectDraft).subscribe((res) => { + console.log('Saved tinymce') + + }, (error) => { + this.erroHandler.httpStatusHandle(error) + }) } somefunction() { - + console.log('Saved tinymce') } async openOptions() { diff --git a/src/firebase-messaging-sw.js b/src/firebase-messaging-sw.js index fdd82b78c..bb0d71d6f 100644 --- a/src/firebase-messaging-sw.js +++ b/src/firebase-messaging-sw.js @@ -19,7 +19,7 @@ firebase.initializeApp(firebaseConfig); const messaging = firebase.messaging(); messaging.onBackgroundMessage(function(payload) { - console.log('Received background message ', payload); + console.log('Received background message 22 ', payload); const notificationTitle = payload.notification.title; const notificationOptions = { @@ -57,4 +57,16 @@ self.addEventListener('message', function(event){ self.userID = data.uid; self.userToken = data.token; +}); + +self.addEventListener('notificationclick', function(event) { + console.log("Push Clicked ", event); + // Enviar uma mensagem para o cliente (componente) + self.clients.matchAll().then((clients) => { + if (clients && clients.length) { + clients.forEach((client) => { + client.postMessage({ notificationClicked: true }); + }); + } + }); }); \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 65a9052ea..7fa3e2dbc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,6 +31,16 @@ if (environment.production) { SentrySibling.init ); */ +if ('serviceWorker' in navigator && environment.production) { + navigator.serviceWorker.register('firebase-messaging-sw.js') + .then(registration => { + console.log('Service Worker registrado com sucesso:', registration); + }) + .catch(error => { + console.error('Erro ao registrar o Service Worker:', error); + }); +} + platformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.log(err)); diff --git a/version/git-version.ts b/version/git-version.ts index c5d30851b..bc67c6f7a 100644 --- a/version/git-version.ts +++ b/version/git-version.ts @@ -1,12 +1,12 @@ export let versionData = { - "shortSHA": "a05918788", - "SHA": "a0591878852492c56134ff984c8ce56a75329b28", + "shortSHA": "5cf48c1b2", + "SHA": "5cf48c1b2f7e695ac200b429c2a107b7caab4eac", "branch": "developer", "lastCommitAuthor": "'Eudes Inácio'", - "lastCommitTime": "'Thu Aug 3 13:04:58 2023 +0100'", - "lastCommitMessage": "duplication of notification solved", - "lastCommitNumber": "5134", + "lastCommitTime": "'Fri Aug 4 10:13:06 2023 +0100'", + "lastCommitMessage": "pull made", + "lastCommitNumber": "5137", "change": "", - "changeStatus": "On branch developer\nYour branch and 'origin/developer' have diverged,\nand have 9 and 2 different commits each, respectively.\n (use \"git pull\" to merge the remote branch into yours)\n\nAll conflicts fixed but you are still merging.\n (use \"git commit\" to conclude merge)\n\nChanges to be committed:\n\tmodified: src/app/home/home.page.html\n\tmodified: src/app/pages/gabinete-digital/gabinete-digital.page.html\n\tmodified: src/app/pages/login/login.page.html\n\tmodified: src/app/pages/search/search.page.ts\n\tmodified: src/app/shared/gabinete-digital/despachos/despachos.page.html", + "changeStatus": "On branch developer\nYour branch is up to date with 'origin/developer'.\n\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/home/home.page.ts\n\tmodified: src/app/pages/gabinete-digital/gabinete-digital.page.html\n\tmodified: src/app/services/chat/room.service.ts\n\tmodified: src/app/services/native-notification.service.ts\n\tmodified: src/app/services/notifications.service.ts\n\tmodified: src/app/tiny-mce/tiny-mce.page.html\n\tmodified: src/app/tiny-mce/tiny-mce.page.ts\n\tmodified: src/firebase-messaging-sw.js\n\tmodified: src/main.ts", "changeAuthor": "eudes.inacio" } \ No newline at end of file