diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 9fe3739e2..1d8ddfbea 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -38,6 +38,7 @@ import { FileType } from 'src/app/models/fileType'; import { SearchPage } from 'src/app/pages/search/search.page'; import { Storage } from '@ionic/storage'; import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; const IMAGE_DIR = 'stored-images'; @@ -552,6 +553,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { }) } + + async addImageMobile() { + this.addFileToChatMobile(['image/apng', 'image/jpeg', 'image/png']) + } async addImage() { this.addFileToChat(['image/apng', 'image/jpeg', 'image/png']) @@ -605,6 +610,42 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { }); } + async addFileToChatMobile(types: typeof FileType[] ) { + const roomId = this.roomId + + const file = await Camera.getPhoto({ + quality: 90, + // allowEditing: true, + resultType: CameraResultType.Base64, + source: CameraSource.Photos + }); + console.log('ADDFILECHAT', file) + //const imageData = await this.fileToBase64Service.convert(file) + //console.log('ADDFILECHAT', imageData) + + const response = await fetch(file.base64String!); + const blob = await response.blob(); + + const formData = new FormData(); + formData.append("blobFile", blob); + + this.wsChatMethodsService.getDmRoom(roomId).send({ + file: { + "type": "application/img", + "guid": '', + "image_url": 'data:image/jpeg;base64,' +file.base64String + }, + temporaryData: formData, + attachments: [{ + "title": file.path , + "image_url": 'data:image/jpeg;base64,' +file.base64String, + "text": "description", + "title_link_download": false, + }] + }) + + } + async addFileToChat(types: typeof FileType[] ) { @@ -660,7 +701,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.takePicture() } else if (res['data'] == 'add-picture') { - this.addImage() + this.addImageMobile() } else if (res['data'] == 'add-document') { this.addFile()