From c825fb2d3c654f90054b48f29c2c4e576daa15da Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 14 Mar 2023 09:50:40 +0100 Subject: [PATCH 1/2] fix chat camera --- src/app/pages/chat/messages/messages.page.ts | 47 +++++++++++++++---- .../pages/publications/publications.page.ts | 2 + .../view-publications.page.ts | 1 + version/git-version.ts | 12 ++--- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 6c5565ef6..3cabeb414 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -108,6 +108,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { audioPermissionStatus: 'granted' | 'denied' | 'prompt' | null = null sessionStore = SessionStore + convertBlobToBase64Worker; + constructor( public popoverController: PopoverController, private modalController: ModalController, @@ -130,6 +132,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { private notificationService: NotificationsService, private router: Router ) { + this.convertBlobToBase64Worker = new Worker(new URL('./convertBlobToBase64.worker.js', import.meta.url)); + this.loggedUser = SessionStore.user.ChatData['data']; this.roomId = this.navParams.get('roomId'); @@ -648,18 +652,20 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { 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 file = await Camera.getPhoto({ + quality: 90, + // allowEditing: true, + resultType: CameraResultType.Base64, + source: CameraSource.Camera + }); + const blob = this.dataURItoBlob('data:image/jpeg;base64,' + file.base64String) + console.log('data:image/jpeg;base64,' + file.base64String) - const base64 = await fetch(capturedImage); - const blob = await base64.blob(); const formData = new FormData(); formData.append("blobFile", blob); - console.log(capturedImage); + // console.log('capturedImage', capturedImage); this.ChatSystemService.getDmRoom(roomId).send({ file: { @@ -667,13 +673,38 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { "guid": '' }, attachments: [{ - "title": capturedImageTitle, + "title": "file.jpg", "text": "description", "title_link_download": false, }], temporaryData: formData }) + } + + 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; + } async addImageMobile() { diff --git a/src/app/pages/publications/publications.page.ts b/src/app/pages/publications/publications.page.ts index 8ce820f8e..e6ebcf1a5 100644 --- a/src/app/pages/publications/publications.page.ts +++ b/src/app/pages/publications/publications.page.ts @@ -151,6 +151,8 @@ export class PublicationsPage implements OnInit { this.publicationsEventFolderList = folders.filter((e)=>e.ActionType == 'Evento') this.publicationsTravelFolderList = folders.filter((e)=>e.ActionType != 'Evento') + // ActionModel.create(folders) + await this.storage.set('actionsEvents', this.publicationsEventFolderList); await this.storage.set('actionsViagens', this.publicationsTravelFolderList); diff --git a/src/app/shared/publication/view-publications/view-publications.page.ts b/src/app/shared/publication/view-publications/view-publications.page.ts index aad1bc377..27be22bb0 100644 --- a/src/app/shared/publication/view-publications/view-publications.page.ts +++ b/src/app/shared/publication/view-publications/view-publications.page.ts @@ -167,6 +167,7 @@ export class ViewPublicationsPage implements OnInit { const found = this.publicationIsPresent(publicationId, folderId) if(!found) { this.publicationList[folderId].push(publicationDetails) + // PublicationModel.create(publicationDetails) } else { this.publicationList[folderId][findIndex] = publicationDetails } diff --git a/version/git-version.ts b/version/git-version.ts index 05772e481..e0182056c 100644 --- a/version/git-version.ts +++ b/version/git-version.ts @@ -1,12 +1,12 @@ export let versionData = { - "shortSHA": "57b4f0880", - "SHA": "57b4f0880084a1ab1005660d19cb603fa7b279ad", + "shortSHA": "2b4b87997", + "SHA": "2b4b879970ce902dee81bc6046d08b6e5fe29bc8", "branch": "no_bug_movemente", "lastCommitAuthor": "'Peter Maquiran'", - "lastCommitTime": "'Fri Mar 10 15:10:37 2023 +0100'", - "lastCommitMessage": "improve publication", - "lastCommitNumber": "4867", + "lastCommitTime": "'Fri Mar 10 15:46:37 2023 +0100'", + "lastCommitMessage": "remove duplication from publication", + "lastCommitNumber": "4868", "change": "", - "changeStatus": "On branch no_bug_movemente\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/pages/publications/publications.page.ts", + "changeStatus": "On branch no_bug_movemente\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/pages/chat/messages/messages.page.ts\n\tmodified: src/app/pages/publications/publications.page.ts\n\tmodified: src/app/shared/publication/view-publications/view-publications.page.ts", "changeAuthor": "peter.maquiran" } \ No newline at end of file From ced8320dd2f685af479beddc331a6bce503efc5a Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 14 Mar 2023 09:56:48 +0100 Subject: [PATCH 2/2] fix take picture --- src/app/pages/chat/messages/messages.page.ts | 4 ---- version/git-version.ts | 12 ++++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 3cabeb414..f04104503 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -108,8 +108,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { audioPermissionStatus: 'granted' | 'denied' | 'prompt' | null = null sessionStore = SessionStore - convertBlobToBase64Worker; - constructor( public popoverController: PopoverController, private modalController: ModalController, @@ -132,8 +130,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { private notificationService: NotificationsService, private router: Router ) { - this.convertBlobToBase64Worker = new Worker(new URL('./convertBlobToBase64.worker.js', import.meta.url)); - this.loggedUser = SessionStore.user.ChatData['data']; this.roomId = this.navParams.get('roomId'); diff --git a/version/git-version.ts b/version/git-version.ts index e0182056c..d1a55dbc8 100644 --- a/version/git-version.ts +++ b/version/git-version.ts @@ -1,12 +1,12 @@ export let versionData = { - "shortSHA": "2b4b87997", - "SHA": "2b4b879970ce902dee81bc6046d08b6e5fe29bc8", + "shortSHA": "c825fb2d3", + "SHA": "c825fb2d3c654f90054b48f29c2c4e576daa15da", "branch": "no_bug_movemente", "lastCommitAuthor": "'Peter Maquiran'", - "lastCommitTime": "'Fri Mar 10 15:46:37 2023 +0100'", - "lastCommitMessage": "remove duplication from publication", - "lastCommitNumber": "4868", + "lastCommitTime": "'Tue Mar 14 09:50:40 2023 +0100'", + "lastCommitMessage": "fix chat camera", + "lastCommitNumber": "4869", "change": "", - "changeStatus": "On branch no_bug_movemente\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/pages/chat/messages/messages.page.ts\n\tmodified: src/app/pages/publications/publications.page.ts\n\tmodified: src/app/shared/publication/view-publications/view-publications.page.ts", + "changeStatus": "On branch no_bug_movemente\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/pages/chat/messages/messages.page.ts", "changeAuthor": "peter.maquiran" } \ No newline at end of file