mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
allow to send files to chat
This commit is contained in:
@@ -162,7 +162,7 @@
|
||||
<ion-fab-button title="Adicionar Documento" (click)="addFile()" color="light">
|
||||
<ion-icon name="document"></ion-icon>
|
||||
</ion-fab-button>
|
||||
<ion-fab-button title="Anexar Fotografia" (click)="addImage()" color="light">
|
||||
<ion-fab-button title="Anexar Fotografia" (click)="pickPicture()" color="light">
|
||||
<ion-icon name="image"></ion-icon>
|
||||
</ion-fab-button>
|
||||
<ion-fab-button title="Tirar Fotografia" (click)="takePictureMobile()" color="light">
|
||||
|
||||
@@ -48,7 +48,10 @@ import { MemberTable } from 'src/app/module/chat/infra/database/dexie/schema/mem
|
||||
import { TypingTable } from 'src/app/module/chat/infra/database/dexie/schema/typing';
|
||||
import { MessageAttachmentFileType, MessageAttachmentSource } from 'src/app/module/chat/data/dto/message/messageOutputDTO';
|
||||
import { JSFileToBase64 } from 'src/app/utils/ToBase64';
|
||||
|
||||
import { CameraService } from 'src/app/infra/camera/camera.service'
|
||||
import { compressImageBase64 } from '../../../utils/imageCompressore';
|
||||
import { FilePickerWebService } from 'src/app/infra/file-picker/web/file-picker-web.service'
|
||||
import { allowedDocExtension } from 'src/app/utils/allowedDocExtension';
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@Component({
|
||||
@@ -158,6 +161,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
private messageRepositoryService: MessageRepositoryService,
|
||||
private userTypingServiceRepository: UserTypingServiceRepository,
|
||||
private chatServiceService: ChatServiceService,
|
||||
private CameraService: CameraService,
|
||||
private FilePickerWebService: FilePickerWebService
|
||||
) {
|
||||
// update
|
||||
this.checkAudioPermission()
|
||||
@@ -679,17 +684,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
await modal.present();
|
||||
}
|
||||
|
||||
openSendMessageOptions(ev?: any) {
|
||||
if (window.innerWidth < 701) {
|
||||
|
||||
this.openChatOptions(ev);
|
||||
}
|
||||
else {
|
||||
|
||||
this._openChatOptions();
|
||||
}
|
||||
}
|
||||
|
||||
async openChatOptions(ev: any) {
|
||||
const popover = await this.popoverController.create({
|
||||
component: ChatOptionsPopoverPage,
|
||||
@@ -798,57 +792,50 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
async takePictureMobile() {
|
||||
|
||||
const picture = await this.CameraService.takePicture({
|
||||
cameraResultType: CameraResultType.DataUrl,
|
||||
quality: 90
|
||||
})
|
||||
|
||||
const roomId = this.roomId
|
||||
if(picture.isOk()) {
|
||||
const file = picture.value
|
||||
|
||||
const file = await Camera.getPhoto({
|
||||
quality: 90,
|
||||
// allowEditing: true,
|
||||
resultType: CameraResultType.Base64,
|
||||
source: CameraSource.Camera
|
||||
});
|
||||
console.log('Selected: ', file)
|
||||
var base64 = 'data:image/jpeg;base64,' + file.base64String
|
||||
const compressedImage = await this.compressImageBase64(
|
||||
base64,
|
||||
800, // maxWidth
|
||||
800, // maxHeight
|
||||
0.9 // quality
|
||||
).then((picture) => {
|
||||
const compressedImage = await compressImageBase64(
|
||||
file.dataUrl,
|
||||
800, // maxWidth
|
||||
800, // maxHeight
|
||||
0.9 // quality
|
||||
)
|
||||
|
||||
base64 = picture
|
||||
});
|
||||
if(compressedImage.isOk()) {
|
||||
|
||||
const message = new MessageEntity();
|
||||
message.roomId = this.roomId
|
||||
|
||||
const blob = this.dataURItoBlob(base64)
|
||||
message.sender = {
|
||||
userPhoto: '',
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
message.attachments = [{
|
||||
file: compressedImage.value,
|
||||
fileName: "foto",
|
||||
source: MessageAttachmentSource.Device,
|
||||
fileType: MessageAttachmentFileType.Image
|
||||
}]
|
||||
|
||||
// this.ChatSystemService.getDmRoom(roomId).send({
|
||||
// file: {
|
||||
// "type": "application/img",
|
||||
// "guid": '',
|
||||
// },
|
||||
// temporaryData: formData,
|
||||
// attachments: [{
|
||||
// "title": file.path,
|
||||
// // "image_url": "",
|
||||
// //"image_url": 'data:image/jpeg;base64,' + file.base64String,
|
||||
// "text": "description",
|
||||
// "title_link_download": false,
|
||||
// }],
|
||||
// attachmentsModelData: {
|
||||
// fileBase64: base64,
|
||||
// }
|
||||
// })
|
||||
this.chatServiceService.sendMessage(message)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async takePicture() {
|
||||
|
||||
const roomId = this.roomId
|
||||
|
||||
const file = await Camera.getPhoto({
|
||||
quality: 90,
|
||||
// allowEditing: true,
|
||||
@@ -885,10 +872,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
}
|
||||
|
||||
async addImage() {
|
||||
this.addFileToChatMobile(['image/apng', 'image/jpeg', 'image/png'])
|
||||
}
|
||||
|
||||
async addFile() {
|
||||
this.addFileToChat(['.doc', '.docx', '.pdf'], MessageAttachmentFileType.Doc)
|
||||
}
|
||||
@@ -907,29 +890,32 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
modal.onDidDismiss().then(async res => {
|
||||
|
||||
const data = res.data;
|
||||
const roomId = this.roomId
|
||||
|
||||
if (data.selected) {
|
||||
|
||||
// this.ChatSystemService.getDmRoom(roomId).send({
|
||||
// file: {
|
||||
// "name": res.data.selected.Assunto,
|
||||
// "type": "application/webtrix",
|
||||
// "ApplicationId": res.data.selected.ApplicationType,
|
||||
// "DocId": res.data.selected.Id,
|
||||
// "Assunto": res.data.selected.Assunto,
|
||||
// },
|
||||
// temporaryData: res,
|
||||
// attachments: [{
|
||||
// "title": res.data.selected.Assunto,
|
||||
// "description": res.data.selected.DocTypeDesc,
|
||||
// "title_link_download": true,
|
||||
// "type": "webtrix",
|
||||
// "text": res.data.selected.DocTypeDesc,
|
||||
// "thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
|
||||
// }],
|
||||
// })
|
||||
// "title": res.data.selected.Assunto,
|
||||
// "description": res.data.selected.DocTypeDesc,
|
||||
|
||||
const message = new MessageEntity();
|
||||
message.message = this.textField
|
||||
message.roomId = this.roomId
|
||||
|
||||
message.sender = {
|
||||
userPhoto: '',
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId
|
||||
}
|
||||
message.attachments = [{
|
||||
fileName: res.data.selected.Assunto,
|
||||
source: MessageAttachmentSource.Webtrix,
|
||||
fileType: MessageAttachmentFileType.Doc,
|
||||
applicationId: res.data.selected.ApplicationType,
|
||||
docId: res.data.selected.Id,
|
||||
}]
|
||||
|
||||
this.chatServiceService.sendMessage(message)
|
||||
this.textField = ''
|
||||
|
||||
}
|
||||
});
|
||||
@@ -937,58 +923,48 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
await modal.present();
|
||||
}
|
||||
|
||||
async addFileToChatMobile(types: typeof FileType[]) {
|
||||
const roomId = this.roomId
|
||||
async pickPicture() {
|
||||
|
||||
const file = await Camera.getPhoto({
|
||||
quality: 90,
|
||||
// allowEditing: true,
|
||||
resultType: CameraResultType.Base64,
|
||||
source: CameraSource.Photos
|
||||
});
|
||||
const file = await this.FilePickerWebService.getPicture({
|
||||
cameraResultType: CameraResultType.Base64
|
||||
})
|
||||
|
||||
//const imageData = await this.fileToBase64Service.convert(file)
|
||||
//
|
||||
console.log('Selected: ', file)
|
||||
var base64 = 'data:image/jpeg;base64,' + file.base64String
|
||||
if (file.format == "jpeg" || file.format == "png" || file.format == "gif") {
|
||||
if(file.isOk()) {
|
||||
|
||||
const compressedImage = await this.compressImageBase64(
|
||||
base64,
|
||||
800, // maxWidth
|
||||
800, // maxHeight
|
||||
0.9 // quality
|
||||
).then((picture) => {
|
||||
var base64 = 'data:image/jpeg;base64,' + file.value.base64String
|
||||
if (file.value.format == "jpeg" || file.value.format == "png" || file.value.format == "gif") {
|
||||
|
||||
base64 = picture
|
||||
});
|
||||
const compressedImage = await compressImageBase64(
|
||||
base64,
|
||||
800, // maxWidth
|
||||
800, // maxHeight
|
||||
0.9 // quality
|
||||
)
|
||||
|
||||
const response = await fetch(base64);
|
||||
const blob = await response.blob();
|
||||
if(compressedImage.isOk()) {
|
||||
|
||||
console.log(base64)
|
||||
const message = new MessageEntity();
|
||||
message.roomId = this.roomId
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
message.sender = {
|
||||
userPhoto: '',
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId
|
||||
}
|
||||
|
||||
// this.ChatSystemService.getDmRoom(roomId).send({
|
||||
// file: {
|
||||
// "type": "application/img",
|
||||
// "guid": ''
|
||||
// },
|
||||
// temporaryData: formData,
|
||||
// attachments: [{
|
||||
// "title": file.path,
|
||||
// //"image_url": 'data:image/jpeg;base64,' + file.base64String,
|
||||
// "text": "description",
|
||||
// "title_link_download": false,
|
||||
// }],
|
||||
// attachmentsModelData: {
|
||||
// fileBase64: base64,
|
||||
// }
|
||||
// })
|
||||
message.attachments = [{
|
||||
file: compressedImage.value,
|
||||
fileName: "foto",
|
||||
source: MessageAttachmentSource.Device,
|
||||
fileType: MessageAttachmentFileType.Image
|
||||
}]
|
||||
|
||||
this.chatServiceService.sendMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1003,20 +979,16 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
async addFileToChat(types: typeof FileType[], attachmentFileType:MessageAttachmentFileType) {
|
||||
|
||||
const file = await this.fileService.getFileFromDevice(types);
|
||||
const file = await this.FilePickerWebService.getFileFromDevice(types);
|
||||
if(file.isOk()) {
|
||||
|
||||
if (file.type == 'application/pdf' || file.type == 'application/doc' || file.type == 'application/docx' ||
|
||||
file.type == 'application/xls' || file.type == 'application/xlsx' || file.type == 'application/ppt' ||
|
||||
file.type == 'application/pptx' || file.type == 'application/txt') {
|
||||
const fileExtension = await allowedDocExtension(file.value.type)
|
||||
|
||||
console.log('FILE rigth?', file)
|
||||
if(fileExtension.isOk()) {
|
||||
|
||||
const fileName = file.name
|
||||
console.log('FILE rigth?', file)
|
||||
|
||||
const FilenameValidation = this.FileValidatorService.fileNameValidation(fileName)
|
||||
|
||||
if (FilenameValidation.isOk) {
|
||||
let fileBase64 = await JSFileToBase64(file);
|
||||
let fileBase64 = await JSFileToBase64(file.value);
|
||||
|
||||
if(fileBase64.isOk()) {
|
||||
|
||||
@@ -1032,7 +1004,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
message.attachments = [{
|
||||
file: fileBase64.value,
|
||||
fileName: file.name,
|
||||
fileName: file.value.name,
|
||||
source: MessageAttachmentSource.Device,
|
||||
fileType: MessageAttachmentFileType.Doc
|
||||
}]
|
||||
@@ -1043,9 +1015,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
} else {
|
||||
this.toastService._badRequest("Ficheiro inválido")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_getBase64(file) {
|
||||
@@ -1151,7 +1121,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
else if (res['data'] == 'add-picture') {
|
||||
|
||||
this.addImage()
|
||||
this.pickPicture()
|
||||
|
||||
}
|
||||
else if (res['data'] == 'add-document') {
|
||||
@@ -1371,7 +1341,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
async compressImageBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const image = new (window as any).Image();
|
||||
const image = new Image();
|
||||
image.src = base64String;
|
||||
|
||||
image.onload = async () => {
|
||||
|
||||
Reference in New Issue
Block a user