mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
bug on tablet chat add image
This commit is contained in:
@@ -32,6 +32,7 @@ import { FileType } from 'src/app/models/fileType';
|
|||||||
import { SearchPage } from 'src/app/pages/search/search.page';
|
import { SearchPage } from 'src/app/pages/search/search.page';
|
||||||
import { ProcessesService } from 'src/app/services/processes.service';
|
import { ProcessesService } from 'src/app/services/processes.service';
|
||||||
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
|
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
|
||||||
|
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
|
||||||
|
|
||||||
const IMAGE_DIR = 'stored-images';
|
const IMAGE_DIR = 'stored-images';
|
||||||
@Component({
|
@Component({
|
||||||
@@ -442,6 +443,41 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async takePictureMobile() {
|
||||||
|
const roomId = this.roomId
|
||||||
|
|
||||||
|
const file = await Camera.getPhoto({
|
||||||
|
quality: 90,
|
||||||
|
// allowEditing: true,
|
||||||
|
resultType: CameraResultType.Base64,
|
||||||
|
source: CameraSource.Camera
|
||||||
|
});
|
||||||
|
console.log('ADDFILECHAT', file)
|
||||||
|
//const imageData = await this.fileToBase64Service.convert(file)
|
||||||
|
//console.log('ADDFILECHAT', imageData)
|
||||||
|
|
||||||
|
const response = await fetch('data:image/jpeg;base64,'+ 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 takePicture() {
|
async takePicture() {
|
||||||
const roomId = this.roomId
|
const roomId = this.roomId
|
||||||
@@ -451,6 +487,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
const lastphoto: any = await this.fileService.loadFiles();
|
const lastphoto: any = await this.fileService.loadFiles();
|
||||||
const { capturedImage, capturedImageTitle} = await this.fileService.loadFileData(lastphoto);
|
const { capturedImage, capturedImageTitle} = await this.fileService.loadFileData(lastphoto);
|
||||||
const base64 = await fetch(capturedImage);
|
const base64 = await fetch(capturedImage);
|
||||||
|
console.log('imsge take picture', image)
|
||||||
const blob = await base64.blob();
|
const blob = await base64.blob();
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("blobFile", blob);
|
formData.append("blobFile", blob);
|
||||||
@@ -475,7 +512,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
}
|
}
|
||||||
|
|
||||||
async addImage() {
|
async addImage() {
|
||||||
this.addFileToChat(['image/apng', 'image/jpeg', 'image/png'])
|
this.addFileToChatMobile(['image/apng', 'image/jpeg', 'image/png'])
|
||||||
}
|
}
|
||||||
|
|
||||||
async addFile() {
|
async addFile() {
|
||||||
@@ -524,12 +561,50 @@ export class MessagesPage implements OnInit, OnChanges, 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('data:image/jpeg;base64,'+ 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[] ) {
|
async addFileToChat(types: typeof FileType[] ) {
|
||||||
|
|
||||||
const roomId = this.roomId
|
const roomId = this.roomId
|
||||||
|
|
||||||
const file: any = await this.fileService.getFileFromDevice(types);
|
const file: any = await this.fileService.getFileFromDevice(types);
|
||||||
|
console.log('Add image', file)
|
||||||
const imageData = await this.fileToBase64Service.convert(file)
|
const imageData = await this.fileToBase64Service.convert(file)
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@@ -620,7 +695,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
}
|
}
|
||||||
else if (res['data'] == 'take-picture') {
|
else if (res['data'] == 'take-picture') {
|
||||||
|
|
||||||
this.takePicture()
|
this.takePictureMobile()
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (res['data'] == 'add-picture') {
|
else if (res['data'] == 'add-picture') {
|
||||||
|
|||||||
Reference in New Issue
Block a user