diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 6923637fd..5bdaacd0f 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -13,9 +13,6 @@ - - - { document.querySelectorAll('ion-modal').forEach((e: any) => e.remove()) @@ -124,14 +128,12 @@ export class HomePage implements OnInit { } - /* navigator.serviceWorker.ready.then((registration) => { - console.log('yes please') - registration.active.postMessage( - "Test message sent immediately after creation", - ); - }); */ - - + /* navigator.serviceWorker.ready.then((registration) => { + console.log('yes please') + registration.active.postMessage( + "Test message sent immediately after creation", + ); + }); */ } @@ -149,7 +151,7 @@ export class HomePage implements OnInit { notification: event.data } - + // 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!'); @@ -220,18 +222,34 @@ export class HomePage implements OnInit { - (()=>{ + (() => { document.addEventListener('click', (e: any) => { const closest = e.target.closest(".mat-datepicker-content"); - if(closest) { + if (closest) { e.preventDefault() - document.activeElement['blur'](); + document.activeElement['blur'](); } - - }) + + }) })() }, 1000) + + /* if (!this.platform.is('desktop')) { + App.addListener('appStateChange', ({ isActive }) => { + if (isActive) { + // The app is in the foreground. + console.log('App is in the foreground'); + this.RochetChatConnectorService.connect() + this.reloadComponent(true) + } else { + // The app is in the background. + console.log('App is in the background'); + // You can perform actions specific to the background state here. + } + }); + } */ + } clearTabButtonSelection() { @@ -322,4 +340,16 @@ export class HomePage implements OnInit { // this.sqliteservice.deleteAllTables(); } + + reloadComponent(self:boolean,urlToNavigateTo ?:string){ + //skipLocationChange:true means dont update the url to / when navigating + console.log("Current route I am on:",this.router.url); + const url=self ? this.router.url :urlToNavigateTo; + this.router.navigateByUrl('/',{skipLocationChange:true}).then(()=>{ + this.router.navigate([`/${url}`]).then(()=>{ + console.log(`After navigation I am on:${this.router.url}`) + }) + }) + } + } \ No newline at end of file diff --git a/src/app/modals/profile/edit-profile/edit-profile.page.ts b/src/app/modals/profile/edit-profile/edit-profile.page.ts index 1678ad8a1..4be349ad0 100644 --- a/src/app/modals/profile/edit-profile/edit-profile.page.ts +++ b/src/app/modals/profile/edit-profile/edit-profile.page.ts @@ -23,7 +23,7 @@ export class EditProfilePage implements OnInit { SessionStore = SessionStore production = environment.production environment = environment - capturedImage = ''; + capturedImage: any; capturedImageTitle = ''; profilePicture = ""; @@ -39,7 +39,8 @@ export class EditProfilePage implements OnInit { ) { } ngOnInit() { - this.getProfilpictureFromStorage() + + this.getProfilpictureFromStorage(); } getProfilpictureFromStorage() { this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => { @@ -49,15 +50,15 @@ export class EditProfilePage implements OnInit { this.profilePicture = ""; }) } - getProfilpicture(guid) { +/* getProfilpicture(guid) { console.log('Get picture ', guid.path) - this.attachmentService.downloadFile(guid.path).subscribe(async (picture: any) => { - + this.attachmentService.getUserProfilePhoto().subscribe(async (picture: any) => { - let downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(picture.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - console.log('Get picture ', downloadFile) - this.storageService.store(this.SessionStore.user.RoleID.toString()+"guid", guid.path) - this.storageService.store(this.SessionStore.user.RoleID.toString(), downloadFile).then((value) => { + console.log('Get picture ', picture) + this.storageService.store(this.SessionStore.user.RoleID.toString() + "guid", guid.path) + this.storageService.store(this.SessionStore.user.RoleID.toString(), picture).then((value) => { + this.profilePicture = picture + this.SessionStore.user.UserPhoto = picture; console.log('picture saved') @@ -69,7 +70,7 @@ export class EditProfilePage implements OnInit { console.log('Error get profile picture: ', error) })) - } + } */ close() { this.modalController.dismiss(); @@ -177,20 +178,27 @@ export class EditProfilePage implements OnInit { source: CameraSource.Camera }); - this.capturedImageTitle = SessionStore.user.Profile; - this.capturedImage = 'data:image/jpeg;base64,' + capturedImage.base64String; + this.capturedImage = capturedImage.base64String; + var object = JSON.stringify({ + "ImageBase64": this.capturedImage + } + ) + console.log('ATTACHME ', object) - const blob = this.dataURItoBlob(this.capturedImage) - - const formData = new FormData(); - formData.append("blobFile", blob); - - this.attachmentService.uploadFile(formData).subscribe((guid) => { + this.attachmentService.addUserProfilePhoto(object).subscribe((guid) => { console.log('GUID ', guid) console.log(this.SessionStore.user.RoleID.toString()) - this.getProfilpicture(guid); + this.storageService.store(this.SessionStore.user.RoleID.toString(), this.capturedImage).then((value) => { + this.profilePicture = 'data:image/jpeg;base64,' +this.capturedImage; + + + console.log('picture saved') + }).catch((error) => { + console.log('picture not saved') + }); + /* this.getProfilpicture(guid); */ }, ((error) => { - console.log('Erro Upload profile picture ',error) + console.log('Erro Upload profile picture ', error) })) } diff --git a/src/app/modals/profile/profile.page.ts b/src/app/modals/profile/profile.page.ts index 57c054b13..763331b96 100644 --- a/src/app/modals/profile/profile.page.ts +++ b/src/app/modals/profile/profile.page.ts @@ -85,14 +85,16 @@ export class ProfilePage implements OnInit { ngOnInit() { this.getNotificationData(); - this.getProfilpicture(); + + + this.getProfilpicture(); } getProfilpicture() { this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => { console.log(picture) - this.profilePicture = picture + this.profilePicture = 'data:image/jpeg;base64,' +picture }).catch((error ) => { this.profilePicture = ""; }) diff --git a/src/app/models/user.model.ts b/src/app/models/user.model.ts index 8a6664b29..f6c29e42d 100644 --- a/src/app/models/user.model.ts +++ b/src/app/models/user.model.ts @@ -96,4 +96,5 @@ export class UserSession { Inactivity: boolean UrlBeforeInactivity: string; UserPermissions: any; + UserPhoto: string; } \ No newline at end of file diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 8196ac1e0..4c65e91eb 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -5,6 +5,7 @@ import { ViewChild, ViewContainerRef, Output, + NgZone, } from '@angular/core'; import { ModalController, Platform } from '@ionic/angular'; import { AuthService } from 'src/app/services/auth.service'; @@ -28,8 +29,13 @@ import { StorageService } from 'src/app/services/storage.service'; import { SessionStore } from 'src/app/store/session.service'; import { ChatDebuggingPage } from 'src/app/shared/popover/chat-debugging/chat-debugging.page'; import { EventTrigger } from 'src/app/services/eventTrigger.service'; +import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'; +import { Plugins } from '@capacitor/core'; + +const { App } = Plugins; + @Component({ selector: 'app-chat', templateUrl: './chat.page.html', @@ -115,7 +121,9 @@ export class ChatPage implements OnInit { private storageservice: StorageService, public ChatSystemService: ChatSystemService, private activatedRoute: ActivatedRoute, - private eventTriger: EventTrigger + private eventTriger: EventTrigger, + private RochetChatConnectorService: RochetChatConnectorService, + private zone: NgZone ) { this.headers = new HttpHeaders(); @@ -140,6 +148,7 @@ export class ChatPage implements OnInit { ngOnInit() { + console.log("Loading TestComponent") this.segment = "Contactos"; this.authService.userData$.subscribe((res: any) => { @@ -164,6 +173,22 @@ export class ChatPage implements OnInit { }); this.routeCheck() + + + if (!this.platform.is('desktop')) { + App.addListener('appStateChange', ({ isActive }) => { + if (isActive) { + // The app is in the foreground. + console.log('App is in the foreground'); + this.RochetChatConnectorService.connect() + this.reloadComponent(true) + } else { + // The app is in the background. + console.log('App is in the background'); + // You can perform actions specific to the background state here. + } + }); + } } routeCheck() { @@ -409,6 +434,7 @@ export class ChatPage implements OnInit { onSegmentChange() { this.ChatSystemService.getAllRooms(); + this.ChatSystemService._dm } doRefresh(event) { @@ -830,5 +856,18 @@ export class ChatPage implements OnInit { await modal.present(); } + reloadComponent(self:boolean,urlToNavigateTo ?:string){ + //skipLocationChange:true means dont update the url to / when navigating + console.log("Current route I am on:",this.router.url); + const url=self ? this.router.url :urlToNavigateTo; + this.zone.run(() =>this.router.navigateByUrl('/',{skipLocationChange:true}).then(()=>{ + this.zone.run(() => this.router.navigate([`/${url}`]).then(()=>{ + console.log(`After navigation I am on:${this.router.url}`) + })) + })) + } + + + } diff --git a/src/app/services/attachments.service.ts b/src/app/services/attachments.service.ts index a0671c00d..afeabee75 100644 --- a/src/app/services/attachments.service.ts +++ b/src/app/services/attachments.service.ts @@ -18,9 +18,9 @@ export class AttachmentsService { headers: HttpHeaders; constructor( - private http: HttpClient, - private platform: Platform, - private file: File, + private http: HttpClient, + private platform: Platform, + private file: File, private changeProfileService: ChangeProfileService) { this.changeProfileService.registerCallback(() => { @@ -36,9 +36,9 @@ export class AttachmentsService { this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey); } - uploadFile(formData:any) { + uploadFile(formData: any) { + - //const geturl = environment.apiURL + 'Tasks/DelegateTask'; const geturl = environment.apiURL + 'ObjectServer/UploadFiles'; @@ -50,7 +50,7 @@ export class AttachmentsService { return this.http.post(`${geturl}`, formData, options); } - getFile(guid:any) { + getFile(guid: any) { const geturl = environment.apiURL + 'lakefs/StreamFile'; let params = new HttpParams(); @@ -66,9 +66,9 @@ export class AttachmentsService { return this.http.get(`${geturl}`, options); } - downloadFile(guid:any) { + downloadFile(guid: any) { - let downloadUrl = environment.apiURL +'objectserver/streamfiles?path='+guid; + let downloadUrl = environment.apiURL + 'objectserver/streamfiles?path=' + guid; var name = new Date().getTime(); return this.http.get(downloadUrl, { responseType: "arraybuffer", @@ -77,30 +77,30 @@ export class AttachmentsService { } - downloadFileAndStore(guid:any) { + downloadFileAndStore(guid: any) { var name = new Date().getTime(); const downloadPath = ( this.platform.is('android') - ) ? this.file.externalDataDirectory : this.file.documentsDirectory; - - - let vm = this; - - /** HttpClient - @angular/common/http */ - this.http.get( - environment.apiURL +'objectserver/streamfiles?path='+guid, + ) ? this.file.externalDataDirectory : this.file.documentsDirectory; + + + let vm = this; + + /** HttpClient - @angular/common/http */ + this.http.get( + environment.apiURL + 'objectserver/streamfiles?path=' + guid, { - responseType: 'arraybuffer', + responseType: 'arraybuffer', } - ).subscribe((fileBlob: Uint8Array) => { + ).subscribe((fileBlob: Uint8Array) => { /** File - @ionic-native/file/ngx */ - vm.file.writeFile(downloadPath, "YourFileName.pdf", fileBlob, {replace: true}); - - - }); - } - - getAttachmentsBySerial(serialNumber: string): Observable{ + vm.file.writeFile(downloadPath, "YourFileName.pdf", fileBlob, { replace: true }); + + + }); + } + + getAttachmentsBySerial(serialNumber: string): Observable { let geturl = environment.apiURL + 'attachments/GetAttachments'; let params = new HttpParams(); @@ -110,7 +110,7 @@ export class AttachmentsService { headers: this.headers, params: params }; - + return this.http.get(`${geturl}`, options); } @@ -150,7 +150,7 @@ export class AttachmentsService { let options = { headers: this.headers, } - return this.http.post(`${geturl}`, body, options); + return this.http.post(`${geturl}`, body, options); } deleteEventAttachmentById(attachmentId) { @@ -166,7 +166,7 @@ export class AttachmentsService { params: params } - return this.http.delete(`${geturl}`, options); + return this.http.delete(`${geturl}`, options); } AddAttachment(body: any) { @@ -175,7 +175,29 @@ export class AttachmentsService { let options = { headers: this.headers, } - return this.http.post(`${geturl}`, body, options); + return this.http.post(`${geturl}`, body, options); + } + + addUserProfilePhoto(formData: any) { + const geturl = environment.apiURL + 'UserAuthentication/AddPhoto'; + + this.headers = this.headers.set('content-type', "application/json"); + this.headers = this.headers.set('accept', "application/json"); + let options = { + headers: this.headers + }; + + return this.http.post(`${geturl}`, formData, options); + } + + getUserProfilePhoto() { + const geturl = environment.apiURL + 'UserAuthentication/GetPhoto'; + + let options = { + headers: this.headers + }; + + return this.http.get(`${geturl}`, options); } } diff --git a/src/app/services/chat/rochet-chat-connector.service.ts b/src/app/services/chat/rochet-chat-connector.service.ts index 4f6b49ccd..3c94ee3f0 100644 --- a/src/app/services/chat/rochet-chat-connector.service.ts +++ b/src/app/services/chat/rochet-chat-connector.service.ts @@ -18,12 +18,23 @@ export class RochetChatConnectorService { constructor(private backgroundservice: BackgroundService,) { } + reConnect() { + console.log('Connect1 ',this.ws.connected) + if(!this.ws.connected) { + this.ws.connect() + console.log('Connect2 ',this.ws.connected) + } + } + connect() { + console.log('Check conetion 11') // dont connect if is already connected if(this.ws.connected == true) { + console.log('Check conetion 22') return false } + console.log('Check conetion 33') this.ws.connect(); const message = { diff --git a/src/app/shared/header/header.page.ts b/src/app/shared/header/header.page.ts index 232862f80..7b7682e1b 100644 --- a/src/app/shared/header/header.page.ts +++ b/src/app/shared/header/header.page.ts @@ -75,17 +75,20 @@ export class HeaderPage implements OnInit { } - async ngOnInit() { + ngOnInit() { this.hideSearch(); - /* this.notificationLengthData(); */ - this.getProfilpicture(); + + this.getProfilpicture(); } + ng + + getProfilpicture() { this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => { console.log(picture) - this.profilePicture = picture + this.profilePicture = 'data:image/jpeg;base64,' +picture }).catch((error ) => { this.profilePicture = ""; }) diff --git a/src/firebase-messaging-sw.js b/src/firebase-messaging-sw.js index d2564841f..c750c7a94 100644 --- a/src/firebase-messaging-sw.js +++ b/src/firebase-messaging-sw.js @@ -59,7 +59,7 @@ self.addEventListener('message', function(event){ }); -self.addEventListener('notificationclick', function(event) { +/* self.addEventListener('notificationclick', function(event) { console.log("Push Clicked ", event); // Enviar uma mensagem para o cliente (componente) self.clients.matchAll().then((clients) => { @@ -70,4 +70,4 @@ self.addEventListener('notificationclick', function(event) { }); } }); -}); \ No newline at end of file +}); */ \ No newline at end of file