Preview image on chat solved

This commit is contained in:
Eudes Inácio
2022-07-06 17:02:42 +01:00
parent 1dc0aa5c53
commit 9dde6d6fd3
4 changed files with 203 additions and 136 deletions
+37 -31
View File
@@ -34,6 +34,7 @@ import { SessionStore } from 'src/app/store/session.service';
import { HttpErrorResponse } from '@angular/common/http';
import { Howl } from 'howler';
import { runInThisContext } from 'vm';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
const IMAGE_DIR = 'stored-images';
@@ -1014,52 +1015,57 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
async openPreview(msg) {
if(msg.file.type === "application/webtrix") {
if (msg.file.type === "application/webtrix") {
this.viewDocument(msg.file, msg.attachments.image_url)
} else {
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
this.downloadFileMsg(msg)
//this.testDownlod(msg)
/* } else if (msg.file.type === "application/pdf") {
const win = window.open("", "_blank");
let html = '';
html += '<html>';
html += '<body style="margin:0!important">';
html += '<iframe width="100%" height="100%" src="' + str + '" type="application/pdf" />';
html += '</body>';
html += '</html>';
setTimeout(() => {
win.document.write(html);
}, 0); */
//this.viewDocument(msg, msg.attachments.image_url)
} else {
var str = msg.attachments[0].image_url;
str = str.substring(1, ((str.length) - 1));
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.downloadFileFromBrowser(msg.attachments[0].name, str)
} else if (this.platform.is('tablet')) {
this.openFile(str, msg.attachments[0].name, msg.file.type);
if (msg.file.type == "application/img") {
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
image: msg.attachments[0].image_url,
type: msg.file.type,
username: msg.u.name,
_updatedAt: msg._updatedAt
}
});
modal.present();
} else {
this.downloadFileFromBrowser(msg.attachments[0].name, str)
}
} else {
if (msg.file.type == "application/img") {
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
image: msg.attachments[0].image_url,
type: msg.file.type,
username: msg.u.name,
_updatedAt: msg._updatedAt
}
});
modal.present();
} else {
this.openFile(str, msg.attachments[0].name, msg.file.type);
}
}
}
}
}