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 a5b28d838..dd7b61f7c 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -30,7 +30,7 @@ import { File } from '@awesome-cordova-plugins/file/ngx'; import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx'; import { SessionStore } from 'src/app/store/session.service'; import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page'; - +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; @Component({ selector: 'app-group-messages', templateUrl: './group-messages.page.html', @@ -474,18 +474,18 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { if (recordData?.value?.recordDataBase64.includes('data:audio')) { this.audioRecorded = recordData?.value?.recordDataBase64; } - else if(recordData?.value?.mimeType && recordData?.value?.recordDataBase64){ + else if (recordData?.value?.mimeType && recordData?.value?.recordDataBase64) { this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`; } //Converting base64 to blob const encodedData = btoa(this.audioRecorded); const blob = this.fileService.base64toBlob(encodedData, recordData.value.mimeType) - + const formData = new FormData(); formData.append("blobFile", blob); - this.ChatSystemService.getGroupRoom(roomId).send({ + this.ChatSystemService.getDmRoom(roomId).send({ file: { "type": "application/audio", "msDuration": audioFile.value.msDuration, @@ -498,7 +498,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }], temporaryData: formData, attachmentsModelData: { - fileBase64: await this.fileService.blobToBase64(blob), + fileBase64: encodedData, } }) @@ -640,28 +640,34 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { async takePicture() { const roomId = this.roomId - const image = await this.CameraService.takePicture(); - await this.fileService.saveImage(image) - const lastphoto: any = await this.fileService.loadFiles(); - const { capturedImage, capturedImageTitle } = await this.fileService.loadFileData(lastphoto); - const base64 = await fetch(capturedImage); - const blob = await base64.blob(); + const file = await Camera.getPhoto({ + quality: 90, + // allowEditing: true, + resultType: CameraResultType.Base64, + source: CameraSource.Camera + }); + + const imageBase64 = 'data:image/jpeg;base64,' + file.base64String + const blob = this.dataURItoBlob(imageBase64) + + console.log(imageBase64) + const formData = new FormData(); formData.append("blobFile", blob); - this.ChatSystemService.getGroupRoom(roomId).send({ + this.ChatSystemService.getDmRoom(roomId).send({ file: { "type": "application/img", "guid": '' }, - temporaryData: formData, attachments: [{ - "title": capturedImageTitle, + "title": "file.jpg", "text": "description", "title_link_download": false, }], + temporaryData: formData, attachmentsModelData: { - fileBase64: await this.fileService.blobToBase64(blob), + fileBase64: imageBase64, } }) @@ -675,6 +681,51 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.addFileToChat(['.doc', '.docx', '.pdf']) } + async addImageMobile() { + this.addFileToChatMobile(['image/apng', 'image/jpeg', 'image/png']) + } + + + async addFileToChatMobile(types: typeof FileType[]) { + const roomId = this.roomId + + const file = await Camera.getPhoto({ + quality: 90, + // allowEditing: true, + resultType: CameraResultType.Base64, + source: CameraSource.Photos + }); + + //const imageData = await this.fileToBase64Service.convert(file) + // + + const imageBase64 = 'data:image/jpeg;base64,' + file.base64String + const response = await fetch(imageBase64); + const blob = await response.blob(); + + console.log(imageBase64) + + const formData = new FormData(); + formData.append("blobFile", blob); + + this.ChatSystemService.getDmRoom(roomId).send({ + file: { + "type": "application/img", + "guid": '' + }, + temporaryData: formData, + attachments: [{ + "title": file.path, + "text": "description", + "title_link_download": false, + }], + attachmentsModelData: { + fileBase64: imageBase64, + } + }) + + } + async addFileWebtrix() { const modal = await this.modalController.create({ component: SearchPage, @@ -719,6 +770,19 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } + _getBase64(file) { + return new Promise((resolve, reject)=>{ + var reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = function () { + resolve(reader.result) + }; + reader.onerror = function (error) { + console.log('Error: ', error); + }; + }) + } + async addFileToChat(types: typeof FileType[]) { const roomId = this.roomId @@ -734,6 +798,9 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }))); const blob = this.fileService.base64toBlob(encodedData, file.type) + + const fileBase64 = await this._getBase64(file) + const formData = new FormData(); formData.append('blobFile', blob); @@ -751,7 +818,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }], temporaryData: formData, attachmentsModelData: { - fileBase64: await this.fileService.blobToBase64(blob), + fileBase64: fileBase64 } }); @@ -806,7 +873,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.takePicture() } else if (res['data'] == 'add-picture') { - this.addImage() + this.addImageMobile() } else if (res['data'] == 'add-document') { @@ -1090,5 +1157,31 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.downloadFileMsg(msg) } else { } } + + + dataURItoBlob(dataURI) { + // convert base64 to raw binary data held in a string + // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this + var byteString = atob(dataURI.split(',')[1]); + + // separate out the mime component + var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0] + + // write the bytes of the string to an ArrayBuffer + var ab = new ArrayBuffer(byteString.length); + + // create a view into the buffer + var ia = new Uint8Array(ab); + + // set the bytes of the buffer to the correct values + for (var i = 0; i < byteString.length; i++) { + ia[i] = byteString.charCodeAt(i); + } + + // write the ArrayBuffer to a blob, and you're done + var blob = new Blob([ab], {type: mimeString}); + return blob; + + } } diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 315da9a67..19163d8b5 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -781,6 +781,20 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { return zoneOriginalInstance || fileReader; } + + _getBase64(file) { + return new Promise((resolve, reject)=>{ + var reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = function () { + resolve(reader.result) + }; + reader.onerror = function (error) { + console.log('Error: ', error); + }; + }) + } + async addFileToChat(types: typeof FileType[]) { const roomId = this.roomId @@ -796,11 +810,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { }))); const blob = this.fileService.base64toBlob(encodedData, file.type) + const fileBase64 = await this._getBase64(file) const formData = new FormData(); formData.append('blobFile', blob); - this.ChatSystemService.getDmRoom(roomId).send({ file: { "type": file.type, @@ -814,7 +828,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { }], temporaryData: formData, attachmentsModelData: { - fileBase64: await this.fileService.blobToBase64(blob), + fileBase64: fileBase64, } }); } else { diff --git a/version/git-version.ts b/version/git-version.ts index 689f7843b..10b4c2c08 100644 --- a/version/git-version.ts +++ b/version/git-version.ts @@ -1,12 +1,12 @@ export let versionData = { - "shortSHA": "61a2b78ee", - "SHA": "61a2b78eeca3ec5cfd5481cec2b5c5f36eb727ae", + "shortSHA": "2b0628146", + "SHA": "2b0628146b6772be4a5fc9f356f0b89acbb7278e", "branch": "developer", "lastCommitAuthor": "'Eudes InĂ¡cio'", - "lastCommitTime": "'Tue Aug 15 18:09:03 2023 +0100'", - "lastCommitMessage": "Search solved, aprove envent and remove from home the serviceworker", - "lastCommitNumber": "5161", + "lastCommitTime": "'Tue Aug 15 18:10:45 2023 +0100'", + "lastCommitMessage": "pull made", + "lastCommitNumber": "5169", "change": "", - "changeStatus": "On branch developer\nYour branch and 'origin/developer' have diverged,\nand have 4 and 7 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/pages/agenda/agenda.page.scss\n\tmodified: src/app/pages/agenda/agenda.page.ts\n\tmodified: src/app/pages/agenda/edit-event/edit-event.page.ts\n\tmodified: src/app/pages/agenda/new-event/new-event.module.ts\n\tmodified: src/app/pages/agenda/new-event/new-event.page.html\n\tmodified: src/app/pages/chat/group-messages/group-contacts/group-contacts.page.ts\n\tmodified: src/app/pages/chat/messages/contacts/contacts.page.html\n\tmodified: src/app/pages/chat/messages/contacts/contacts.page.ts\n\tmodified: src/app/pages/publications/new-publication/new-publication.page.html\n\tmodified: src/app/pages/publications/new-publication/new-publication.page.scss\n\tmodified: src/app/pages/publications/new-publication/new-publication.page.ts\n\tmodified: src/app/services/chat/chat-system.service.ts\n\tmodified: src/app/services/task.service.ts\n\tmodified: src/app/shared/chat/group-messages/group-contacts/group-contacts.page.ts\n\tmodified: src/app/shared/chat/messages/contacts/contacts.page.html\n\tmodified: src/app/shared/chat/messages/contacts/contacts.page.ts\n\tmodified: src/app/shared/popover/event-details-documents-options/event-details-documents-options.page.html\n\tmodified: src/app/shared/publication/new-publication/new-publication.page.html\n\tmodified: src/app/shared/publication/new-publication/new-publication.page.ts\n\tmodified: src/global.scss", - "changeAuthor": "eudes.inacio" + "changeStatus": "On branch developer\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/pages/chat/group-messages/group-messages.page.ts\n\tmodified: src/app/pages/chat/messages/messages.page.ts", + "changeAuthor": "peter.maquiran" } \ No newline at end of file