From da416f45ae584e6d51139824a9c2874d603c5d48 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Mon, 24 Jan 2022 14:57:05 +0100 Subject: [PATCH 1/5] save --- src/app/services/chat/ws-chat.service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 838209d56..052a8c78e 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -277,8 +277,6 @@ export class WsChatService { streamNotifyLogged() { - alert('HERE') - const requestId = uuidv4() const message = { From f85d55cae78aa090f7cbfd489cd524e7ea1e19f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 25 Jan 2022 14:36:31 +0100 Subject: [PATCH 2/5] send image display done --- src/app/services/functions/file.service.ts | 108 ++++++++++++--------- 1 file changed, 61 insertions(+), 47 deletions(-) diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts index cc7576c52..0d80e6506 100644 --- a/src/app/services/functions/file.service.ts +++ b/src/app/services/functions/file.service.ts @@ -13,7 +13,7 @@ import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera import { Filesystem, Directory } from '@capacitor/filesystem'; import { environment } from 'src/environments/environment'; import { HttpClient, HttpEventType, HttpHeaders, HttpParams } from '@angular/common/http'; - +import { Storage } from '@ionic/storage'; const IMAGE_DIR = 'stored-images'; @@ -53,6 +53,7 @@ export class FileService { private platform: Platform, private loadingCtrl: LoadingController, private http: HttpClient, + private storage: Storage ) { this.headers = new HttpHeaders(); } @@ -354,70 +355,83 @@ export class FileService { //loader.remove(); }); */ } + addPictureToChat(roomId) { - addPictureToChat(roomId) { + console.log('add picture to chat') - console.log('add picture to chat') - - const input = this.fileLoaderService.createInput({ - accept: ['image/apng', 'image/jpeg', 'image/png'] - }) + const input = this.fileLoaderService.createInput({ + accept: ['image/apng', 'image/jpeg', 'image/png'] + }) - setInterval(()=>{ - console.log(input.value) - }, 550) + setInterval(() => { + console.log(input.value) + }, 550) - input.onchange = async () => { + input.onchange = async () => { - //alert('Onchange AQUI') + //alert('Onchange AQUI') - const file = this.fileLoaderService.getFirstFile(input) + const file = this.fileLoaderService.getFirstFile(input) - console.log(file); + console.log(file); - const formData = new FormData(); - formData.append("blobFile", file); - let guid: any = await this.uploadFile(formData).toPromise() - console.log('add picture to chat',guid.path); + const formData = new FormData(); + formData.append("blobFile", file); + let guid: any = await this.uploadFile(formData).toPromise() + console.log('add picture to chat', guid.path); + this.downloadFile(guid.path).subscribe(async (event) => { - /* const imageData = await this.fileToBase64Service.convert(file) - this.capturedImage = imageData; */ - this.capturedImageTitle = file.name; + 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, fileImage).then(() => { + console.log('add picture to chat IMAGE SAVED') - let body = { - "message": - { - "rid": roomId, - "msg": "", - "attachments": [{ - //"title": this.capturedImageTitle , - //"text": "description", - "title_link_download": false, - //"image_url": this.capturedImage, - }], - "file":{ - "type": "application/img", - "guid": guid.path, - "image_url": "" + let body = { + "message": + { + "rid": roomId, + "msg": "", + "attachments": [{ + //"title": this.capturedImageTitle , + //"text": "description", + "title_link_download": false, + //"image_url": this.capturedImage, + }], + "file": { + "type": "application/img", + "guid": guid.path, + "image_url": fileImage + } + } } - } + + console.log('SELECT PICTURE GALLERY', body) + console.log(this.capturedImage) + + this.chatService.sendMessage(body).subscribe(res => { + + console.log('Msg after send image', res); + }, (error) => { + console.log('Msg after send image error', error); + }); + }); } - console.log('SELECT PICTURE GALLERY', body) - console.log(this.capturedImage) + }); - this.chatService.sendMessage(body).subscribe(res=> { + /* const imageData = await this.fileToBase64Service.convert(file) + this.capturedImage = imageData; */ - console.log('Msg after send image',res); - },(error) => { - console.log('Msg after send image error',error); - }); - //console.log(this.capturedImage) - }; - } + //console.log(this.capturedImage) + }; +} addDocumentToChat(roomId:string) { const input = this.fileLoaderService.createInput({ From 7325a76718cda6b4669d0a68e3d9e3a6b1a210d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 25 Jan 2022 16:50:58 +0100 Subject: [PATCH 3/5] publication --- .../view-publications/view-publications.page.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/pages/publications/view-publications/view-publications.page.ts b/src/app/pages/publications/view-publications/view-publications.page.ts index d95ba7411..f81eb7b19 100644 --- a/src/app/pages/publications/view-publications/view-publications.page.ts +++ b/src/app/pages/publications/view-publications/view-publications.page.ts @@ -144,16 +144,16 @@ export class ViewPublicationsPage implements OnInit { console.log('publications ids', res) this.publicationList = new Array(); - for(let i of res) { + /* for(let i of res) { this.publications.GetPublicationById(i).subscribe(ress => { console.log('publications by ids', ress) let item: Publication = this.publicationPipe.itemList(ress) console.log('publications by ids 2', item) this.publicationList.push(item); }) - } + } */ - /* res.forEach(element => { + res.forEach(element => { console.log('publications elements', element) this.publications.GetPublicationById(element).subscribe(ress => { console.log('publications by ids', ress) @@ -162,7 +162,7 @@ export class ViewPublicationsPage implements OnInit { this.publicationList.push(ress); }) - }); */ + }); this.sqliteservice.updateactions(this.folderId, JSON.stringify(this.publicationList)); From 0b9efc3bf696bc7ce50a61850d5e52ced76f1777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Thu, 27 Jan 2022 15:53:20 +0100 Subject: [PATCH 4/5] Image from camera web working fine --- src/app/services/functions/file.service.ts | 82 ++++++++++++++-------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts index 0d80e6506..2f3313ab2 100644 --- a/src/app/services/functions/file.service.ts +++ b/src/app/services/functions/file.service.ts @@ -254,43 +254,64 @@ export class FileService { this.capturedImage = this.images[0].data this.capturedImageTitle = new Date().getTime() + '.jpeg'; + const base64 = await fetch(this.capturedImage); + const blob = await base64.blob(); const formData = new FormData(); - formData.append("blobFile", this.capturedImage); - let guid: any = await this.uploadFile(this.capturedImage).toPromise() + formData.append("blobFile", blob); + console.log('ALL IMAGE', formData) + let guid: any = await this.uploadFile(formData).toPromise() console.log(guid.path); - let body = { - "message": - { - "rid": roomid, - "msg": "", - "attachments": [{ - "title": this.capturedImageTitle, - "title_link_download": false, - "image_url": this.capturedImage, - }], - "file":{ - "type": "application/img", - "guid": guid.path, - "image_url": "" + + this.downloadFile(guid.path).subscribe(async (event) => { + + 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!"); + }); + + }); } - } - } - 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!"); - }); + + }); } async addCameraPictureToChat(roomId){ + console.log('add camera to picture') + const image = await Camera.getPhoto({ quality: 50, allowEditing: false, @@ -300,6 +321,8 @@ export class FileService { if (image) { await this.saveImage(image,roomId) + } else { + console.log('Error saving image') } //this.capturedImage = this.capturedImage; @@ -375,12 +398,13 @@ export class FileService { const file = this.fileLoaderService.getFirstFile(input) - console.log(file); + console.log('first file',file); const formData = new FormData(); formData.append("blobFile", file); let guid: any = await this.uploadFile(formData).toPromise() + console.log('ADD IMAGE FORM DATA', formData) console.log('add picture to chat', guid.path); this.downloadFile(guid.path).subscribe(async (event) => { @@ -390,7 +414,7 @@ export class FileService { } 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, fileImage).then(() => { + await this.storage.set(guid.path, fileImage).then(() => { console.log('add picture to chat IMAGE SAVED') let body = { From 9c4ebaaa694b4486a727e7f2525224aab9b2b905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Thu, 27 Jan 2022 16:42:27 +0100 Subject: [PATCH 5/5] change value on sahre chat message page from msg.url to msg.file.url --- src/app/shared/chat/messages/messages.page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index c8c6f57c6..831d0060c 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -74,7 +74,7 @@
- image + image