lasta chnages

This commit is contained in:
Eudes Inácio
2022-03-03 08:21:22 +01:00
parent 99275b891b
commit 5c210928c0
15 changed files with 527 additions and 365 deletions
@@ -88,7 +88,7 @@
</div>
<div *ngIf="msg.file.type != 'application/img'">
<div class="file">
<div (click)="docIndex(i); viewDocument(msg, file.title_link)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<div (click)="docIndex(i); openPreview(msg)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<span *ngIf="msg.file.type">
<fa-icon *ngIf="msg.file.type == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon>
<fa-icon *ngIf="msg.file.type == 'application/word'" icon="file-word" class="word-icon"></fa-icon>
+53 -43
View File
@@ -40,9 +40,10 @@ 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';
import {Plugins} from '@capacitor/core';
import { Plugins } from '@capacitor/core';
import { fromByteArray } from 'base64-js';
const { Filesystem } = Plugins;
const { Filesystem } = Plugins;
const IMAGE_DIR = 'stored-images';
@@ -133,7 +134,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
this.wsChatMethodsService.openRoom(this.roomId)
setTimeout(()=>{
setTimeout(() => {
this.scrollToBottomClicked()
}, 150)
@@ -364,7 +365,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
if (msg.attachments.type == "application/pdf") {
try {
const writeSecretFile = async () => {
await Filesystem.writeFile({
@@ -375,7 +376,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
};
console.log('WRITE',writeSecretFile);
console.log('WRITE', writeSecretFile);
const readSecretFile = async () => {
const contents = await Filesystem.readFile({
@@ -383,11 +384,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
directory: Directory.Documents,
encoding: Encoding.UTF8,
});
console.log('secrets:', contents);
};
console.log('READ',readSecretFile);
console.log('READ', readSecretFile);
} catch (e) {
console.error("Unable to write file", e);
@@ -558,7 +559,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
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 { capturedImage, capturedImageTitle } = await this.fileService.loadFileData(lastphoto);
const base64 = await fetch(capturedImage);
@@ -573,8 +574,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"guid": ''
},
attachments: [{
"image_url": capturedImage,
"title": capturedImageTitle ,
"title": capturedImageTitle,
"text": "description",
"title_link_download": false,
}],
@@ -606,14 +606,14 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
});
await modal.present();
modal.onDidDismiss().then(async res=>{
modal.onDidDismiss().then(async res => {
const data = res.data;
const roomId = this.roomId
if(data.selected) {
if (data.selected) {
this.wsChatMethodsService.getDmRoom(roomId).send({
file:{
file: {
"name": res.data.selected.Assunto,
"type": "application/webtrix",
"ApplicationId": res.data.selected.ApplicationType,
@@ -636,7 +636,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
}
async addFileToChatMobile(types: typeof FileType[] ) {
async addFileToChatMobile(types: typeof FileType[]) {
const roomId = this.roomId
const file = await Camera.getPhoto({
@@ -649,7 +649,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
//const imageData = await this.fileToBase64Service.convert(file)
//console.log('ADDFILECHAT', imageData)
const response = await fetch('data:image/jpeg;base64,'+ file.base64String!);
const response = await fetch('data:image/jpeg;base64,' + file.base64String!);
const blob = await response.blob();
const formData = new FormData();
@@ -662,8 +662,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
},
temporaryData: formData,
attachments: [{
"title": file.path ,
"image_url": 'data:image/jpeg;base64,' +file.base64String,
"title": file.path,
"text": "description",
"title_link_download": false,
}]
@@ -673,7 +672,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
async addFileToChat(types: typeof FileType[] ) {
async addFileToChat(types: typeof FileType[]) {
const roomId = this.roomId
@@ -682,8 +681,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
/* const imageData = await this.fileToBase64Service.convert(file).then((filee) => {
console.log('Add file', filee)
}) */
const blob = new Blob([file],{type: file.type})
console.log('Add file', blob)
const response = await fetch(file);
const blob = await response.blob();
const blob2 = new Blob([blob])
console.log('Add file base64', file)
console.log('Add file blob', blob)
const formData = new FormData();
formData.append("blobFile", blob);
@@ -694,10 +696,9 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"guid": '',
},
attachments: [{
"title": file.name ,
"name": file.name ,
"title": file.name,
"name": file.name,
// "text": "description",
"image_url": file, // rocketchat
"title_link_download": false,
}],
temporaryData: formData
@@ -708,7 +709,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
async openChatOptions(ev?: any) {
const roomId = this.roomId
console.log('MOBILE CHAT OPTION',this.members);
console.log('MOBILE CHAT OPTION', this.members);
const popover = await this.popoverController.create({
component: ChatOptionsPopoverPage,
@@ -722,7 +723,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
translucent: true
});
await popover.present();
popover.onDidDismiss().then( async (res) => {
popover.onDidDismiss().then(async (res) => {
console.log(res['data']);
if (res['data'] == 'meeting') {
this.bookMeeting();
@@ -824,34 +825,42 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
downloadFileMsg(msg: MessageService) {
console.log('FILE TYPE', msg.file.type)
this.downloadFile = "";
if (msg.file.type == "application/img") {
this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => {
console.log('FILE TYPE 22', msg.file.guid)
var name = msg.file.guid;
//if (msg.file.type == "application/img") {
this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => {
console.log('FILE TYPE 22', msg.file.guid)
var name = msg.file.guid;
if (event.type === HttpEventType.DownloadProgress) {
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
console.log('FILE TYPE 33', msg.file.type)
} else if (event.type === HttpEventType.Response) {
if (event.type === HttpEventType.DownloadProgress) {
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
console.log('FILE TYPE 33', msg.file.type)
} else if (event.type === HttpEventType.Response) {
if (msg.file.type == "application/img") {
this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
msg.file = {
guid: msg.file.guid,
image_url: this.downloadFile,
type: msg.file.type
}
this.sqlservice.updateChatMsg(msg._id, this.downloadFile);
} else {
//console.log('TRY THIS LIBRARY ',fromByteArray(event.body));
this.downloadFile = event.body;
}
});
msg.attachments[0] = {
image_url: this.downloadFile,
name: msg.attachments[0].name,
title: msg.attachments[0].title,
title_link_download: msg.attachments[0].title_link_download,
ts: msg.attachments[0].ts
}
this.sqlservice.updateChatMsg(msg._id, this.downloadFile);
}
}
});
//}
}
async openPreview(msg) {
console.log(msg);
if (msg.attachments[0].image_url === null || msg.attachments[0].image_url === '' ) {
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
this.downloadFileMsg(msg)
} else {
@@ -860,6 +869,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
cssClass: 'modal modal-desktop',
componentProps: {
image: msg.attachments[0].image_url,
type: msg.file.type,
username: msg.u.name,
_updatedAt: msg._updatedAt
}