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 385b64a06..56ffae756 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -118,6 +118,9 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.getChatMembers(); this.getRoomMessageDB(this.roomId); + this.wsChatMethodsService.getUserOfRoom(this.roomId).then((value) => { + console.log('MEMBER', value) + }) } setStatus(status:string){ diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 6558fc4f5..63e80320f 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -123,9 +123,12 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { ngOnInit() { //this.load(); this.setStatus('online'); - + this.wsChatMethodsService.getUserOfRoom(this.roomId).then((value) => { + console.log('MEMBER', value) + }) //this.loadFiles(); VoiceRecorder.requestAudioRecordingPermission(); + this.getChatMembers(); Filesystem.mkdir({ path: IMAGE_DIR, directory: Directory.Data, @@ -541,8 +544,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { //this.loadPicture(); } else if (res['data'] == 'add-picture') { - this.fileService.addPictureToChatMobile(roomId); - //this.loadPicture(); + //this.fileService.addPictureToChat(roomId); + this.fileService.loadPicture(this.roomId); } else if (res['data'] == 'add-document') { this.fileService.addDocumentToChat(this.roomId); diff --git a/src/app/pages/publications/new-publication/new-publication.page.ts b/src/app/pages/publications/new-publication/new-publication.page.ts index 479be1a7c..1c66f87bf 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -172,20 +172,23 @@ export class NewPublicationPage implements OnInit { this.capturedImageTitle = new Date().getTime() + '.jpeg'; } */ - laodPicture() { - const input = this.fileLoaderService.createInput({ - accept: ['image/apng', 'image/jpeg', 'image/png'] - }) + async laodPicture() { + + const capturedImage = await Camera.getPhoto({ + quality: 90, + // allowEditing: true, + resultType: CameraResultType.Uri, + source: CameraSource.Photos + }); - input.onchange = async () => { - const file = this.fileLoaderService.getFirstFile(input) + const response = await fetch(capturedImage.webPath!); + const blob = await response.blob(); - const imageData = await this.fileToBase64Service.convert(file) - this.capturedImage = imageData; - this.capturedImageTitle = file.name + this.convertBlobToBase64Worker.postMessage(blob); + this.convertBlobToBase64Worker.onmessage = async (oEvent)=> { + this.capturedImage = oEvent.data - console.log(this.capturedImage) - }; + } } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index f26ca9f5e..6c844238f 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -131,7 +131,7 @@ export class AuthService { localStorage.setItem('userChat', JSON.stringify(responseChat)); this.storageService.store(AuthConnstants.AUTH, responseChat); - this.autologout(10000); + /* this.autologout(10000); */ return true; diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts index f864b398f..f7c684859 100644 --- a/src/app/services/functions/file.service.ts +++ b/src/app/services/functions/file.service.ts @@ -41,6 +41,7 @@ export class FileService { headers: HttpHeaders; downloadProgess = 0; downloadFilename: any; + convertBlobToBase64Worker; constructor( private fileLoaderService: FileLoaderService, @@ -146,27 +147,64 @@ export class FileService { reader.readAsDataURL(blob); }); - async loadPicture() { - const input = this.fileLoaderService.createInput({ - accept: ['image/apng', 'image/jpeg', 'image/png', '.pdf'] - }) + async loadPicture(roomid) { + const capturedImage = await Camera.getPhoto({ + quality: 90, + // allowEditing: true, + resultType: CameraResultType.Uri, + source: CameraSource.Photos + }); - input.onchange = async () => { - const file = this.fileLoaderService.getFirstFile(input) + const response = await fetch(capturedImage.webPath!); + const blob = await response.blob(); + const formData = new FormData(); + formData.append("blobFile", blob); + console.log('ALL IMAGE', formData) + let guid: any = await this.uploadFile(formData).toPromise() + console.log(guid.path); - console.log(file); - const imageData = await this.fileToBase64Service.convert(file) - this.capturedImage = imageData; - this.capturedImageTitle = file.name; + this.downloadFile(guid.path).subscribe(async (event) => { - let data = { - image:this.capturedImage, - name: this.capturedImageTitle - } + if (event.type === HttpEventType.DownloadProgress) { + //this.downloadProgess = Math.round((100 * event.loaded) / event.total); + //console.log('FILE TYPE 33', msg.file.type) + } else if (event.type === HttpEventType.Response) { + var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); + console.log('add picture to chat',fileImage); + await this.storage.set(guid.path, fileImage).then(() => { + console.log('add picture to chat IMAGE SAVED') + let body = { + "message": + { + "rid": roomid, + "msg": "", + "attachments": [{ + "title": this.capturedImageTitle, + "title_link_download": false, + "image_url": fileImage, + }], + "file":{ + "type": "application/img", + "guid": guid.path, + "image_url": fileImage + } + } + } + console.log('BODY TAKE PICTURE CHAT', body) + const loader = this.toastService.loading(); + this.chatService.sendMessage(body).subscribe(res=> { + console.log(res); + loader.remove(); + },(error) => { + loader.remove(); + this.toastService.badRequest("Não foi possível adicionar a fotografia!"); + }); - return data; - }; + }); + } + + }); } //new method1 @@ -336,7 +374,7 @@ export class FileService { quality: 50, // allowEditing: true, resultType: CameraResultType.Uri, - source: CameraSource.Camera + source: CameraSource.Photos }); diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index f799c6d64..f61e12a17 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -114,6 +114,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy ngOnInit() { this.scrollToBottom(); this.setStatus('online'); + this.getChatMembers(); } diff --git a/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html b/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html index fb5cc2d04..96b7c7ae8 100644 --- a/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html +++ b/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html @@ -8,7 +8,7 @@
- +