mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix, open file
This commit is contained in:
@@ -333,6 +333,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.messages1[this.roomId].push(msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.messages1[this.roomId].sort((a, b) => {
|
||||
return new Date(a.sentAt).getTime() - new Date(b.sentAt).getTime()
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1471,9 +1476,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
this.openFile(msg.attachments[0].safeFile, msg.attachments[0].description, msg.attachments[0].mimeType);
|
||||
// this.downloadFileFromBrowser("file", str)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
<audio [src]="attachment.safeFile|safehtml" preload="metadata" class="flex-grow-1" controls controlsList="nodownload noplaybackrate"></audio>
|
||||
</div>
|
||||
|
||||
<div *ngIf="attachment.fileType == MessageAttachmentFileType.Doc" class="d-flex">
|
||||
<div *ngIf="attachment.fileType == MessageAttachmentFileType.Doc" class="d-flex" (click)="openPreview(message)">
|
||||
<fa-icon *ngIf="attachment.mimeType == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon>
|
||||
<fa-icon *ngIf="attachment.mimeType == 'application/word'" icon="file-word" class="word-icon">
|
||||
</fa-icon>
|
||||
|
||||
@@ -52,7 +52,9 @@ import { tap } from 'rxjs/operators';
|
||||
import { ChatPopoverPage } from '../chat-popover/chat-popover.page';
|
||||
import { ViewOncesImagePageInput, ViewOncesImagePage } from '../view-onces/view-onces.page';
|
||||
import { LastMessage } from '../../utils/lastMessage';
|
||||
|
||||
import { File } from '@awesome-cordova-plugins/file/ngx';
|
||||
import { Filesystem, Directory } from '@capacitor/filesystem';
|
||||
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
|
||||
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@@ -168,6 +170,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
private userTypingLocalRepository: UserTypingLocalRepository,
|
||||
private UserTypingRemoteRepositoryService: UserTypingRemoteRepositoryService,
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService,
|
||||
private file: File,
|
||||
private fileOpener: FileOpener,
|
||||
) {
|
||||
|
||||
|
||||
@@ -1263,59 +1267,133 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
|
||||
async openFile(pdfString, filename, type) {
|
||||
// async openFile(pdfString, filename, type) {
|
||||
|
||||
console.log('url while open ',pdfString)
|
||||
// console.log('url while open ',pdfString)
|
||||
|
||||
/* const modal = await this.modalController.create({
|
||||
component: ViewDocumentSecondOptionsPage,
|
||||
componentProps: {
|
||||
fileUrl: pdfString,
|
||||
filename: filename
|
||||
},
|
||||
cssClass: 'modal modal-desktop'
|
||||
// /* const modal = await this.modalController.create({
|
||||
// component: ViewDocumentSecondOptionsPage,
|
||||
// componentProps: {
|
||||
// fileUrl: pdfString,
|
||||
// filename: filename
|
||||
// },
|
||||
// cssClass: 'modal modal-desktop'
|
||||
// });
|
||||
// await modal.present();
|
||||
// /*
|
||||
// await modal.present(); */
|
||||
|
||||
// // var blob = new Blob([pdfString], { type: 'application/pdf' });
|
||||
|
||||
|
||||
// let pathFile = ''
|
||||
// const fileName = filename
|
||||
// if (this.platform.is('ios')) {
|
||||
// pathFile = this.file.documentsDirectory
|
||||
// } else {
|
||||
// pathFile = this.file.externalRootDirectory
|
||||
// }
|
||||
|
||||
// console.log('file data', pdfString)
|
||||
// console.log(pathFile)
|
||||
|
||||
// let removePre = this.removeTextBeforeSlash(pdfString,',')
|
||||
// console.log('file data remove ', removePre)
|
||||
|
||||
// await Filesystem.writeFile({
|
||||
// path: fileName,
|
||||
// data: removePre,
|
||||
// directory: Directory.Cache,
|
||||
// }).then((dir) => {
|
||||
// console.log('DIR ', dir)
|
||||
// this.fileOpener
|
||||
// .open(dir.uri, type)
|
||||
// .then(() => console.log())
|
||||
// .catch(e => console.error(e))
|
||||
// }).catch((error) => {
|
||||
// console.log('error writing the file', error)
|
||||
// });
|
||||
// }
|
||||
|
||||
async fetchBlobFromURL(blobUrl: string): Promise<Blob> {
|
||||
try {
|
||||
const response = await fetch(blobUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch blob: ${response.statusText}`);
|
||||
}
|
||||
return await response.blob();
|
||||
} catch (error) {
|
||||
console.error('Error fetching blob from URL:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
convertBlobToDataURL(blob: Blob): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
if (reader.result) {
|
||||
resolve(reader.result as string);
|
||||
} else {
|
||||
reject('Conversion failed');
|
||||
}
|
||||
};
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
await modal.present();
|
||||
/*
|
||||
await modal.present(); */
|
||||
}
|
||||
|
||||
// var blob = new Blob([pdfString], { type: 'application/pdf' });
|
||||
// async openFile(blobUrl:string, filename, fileType) {
|
||||
// console.log(blobUrl, filename, fileType)
|
||||
// let pathFile: string;
|
||||
|
||||
// console.log('blob blob', blob)
|
||||
// if (this.platform.is('ios')) {
|
||||
// pathFile = this.file.documentsDirectory
|
||||
// } else {
|
||||
// pathFile = this.file.externalRootDirectory
|
||||
// }
|
||||
|
||||
// this.blobToBase64(blob).then((value) => {
|
||||
// console.log(value)
|
||||
// }).catch((error) => {
|
||||
// console.log(error)
|
||||
// })
|
||||
// let a = await this.fetchBlobFromURL(blobUrl)
|
||||
|
||||
// let pathFile = ''
|
||||
// const fileName = filename
|
||||
// if (this.platform.is('ios')) {
|
||||
// pathFile = this.file.documentsDirectory
|
||||
// } else {
|
||||
// pathFile = this.file.externalRootDirectory
|
||||
// }
|
||||
// console.log({e:await this.convertBlobToDataURL(a)})
|
||||
// let removePre = this.removeTextBeforeSlash(await this.convertBlobToDataURL(a),',')
|
||||
|
||||
// console.log('file data', pdfString)
|
||||
// console.log(pathFile)
|
||||
// Filesystem.writeFile({
|
||||
// path: filename,
|
||||
// data: removePre,
|
||||
// directory: Directory.Cache,
|
||||
|
||||
// let removePre = this.removeTextBeforeSlash(pdfString,',')
|
||||
// console.log('file data remove ', removePre)
|
||||
// }).then(dir => {
|
||||
// console.log('DIR ', dir)
|
||||
// this.fileOpener
|
||||
// .open(dir.uri, fileType)
|
||||
// .then(() => console.log())
|
||||
// .catch(e => console.error(e))
|
||||
// })
|
||||
// .catch(e => console.log('Error writing file', e))
|
||||
// }
|
||||
|
||||
// await Filesystem.writeFile({
|
||||
// path: fileName,
|
||||
// data: removePre,
|
||||
// directory: Directory.Cache,
|
||||
// }).then((dir) => {
|
||||
// console.log('DIR ', dir)
|
||||
// this.fileOpener
|
||||
// .open(dir.uri, type)
|
||||
// .then(() => console.log())
|
||||
// .catch(e => console.error(e))
|
||||
// }).catch((error) => {
|
||||
// console.log('error writing the file', error)
|
||||
// });
|
||||
async openFile(blobUrl:string, filename, fileType) {
|
||||
|
||||
let pathFile = ''
|
||||
const fileName = filename
|
||||
const contentFile = await this.fetchBlobFromURL(blobUrl)
|
||||
if (this.platform.is('ios')) {
|
||||
pathFile = this.file.documentsDirectory
|
||||
} else {
|
||||
pathFile = this.file.cacheDirectory
|
||||
}
|
||||
console.log(pathFile)
|
||||
console.log(contentFile)
|
||||
this.file
|
||||
.writeFile(pathFile, fileName, contentFile, { replace: true })
|
||||
.then(success => {
|
||||
this.fileOpener
|
||||
.open(pathFile + fileName, fileType)
|
||||
.then(() => console.log('File is opened'))
|
||||
.catch(e => console.log('Error opening file', e));
|
||||
})
|
||||
.catch(e => console.log('Error writing file', e))
|
||||
}
|
||||
|
||||
removeTextBeforeSlash(inputString, controlString) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { IRoom, RoomEntitySchema } from "src/app/core/chat/entity/group";
|
||||
import { MessageAttachmentSource } from "src/app/core/chat/entity/message";
|
||||
import { isDocument } from "src/app/utils/document-mimetype";
|
||||
|
||||
export class RoomViewModel implements IRoom {
|
||||
@@ -19,12 +20,17 @@ export class RoomViewModel implements IRoom {
|
||||
Object.assign(this, model)
|
||||
this.formatarData()
|
||||
|
||||
this.check()
|
||||
}
|
||||
|
||||
check() {
|
||||
if(this.messages?.[0]?.attachments[0]?.mimeType?.startsWith('image/') ) {
|
||||
this.lastMessageImage = true
|
||||
} else if (this.messages?.[0]?.attachments[0]?.mimeType && isDocument({mimeType: this.messages?.[0]?.attachments[0]?.mimeType})) {
|
||||
this.lastMessageDocument = true
|
||||
} else if (this.messages?.[0]?.attachments[0]?.source == MessageAttachmentSource.Webtrix) {
|
||||
this.lastMessageDocument = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
formatarData() {
|
||||
|
||||
Reference in New Issue
Block a user