diff --git a/src/app/module/chat/domain/use-case/message/message-download-attachment-user-case.service.ts b/src/app/module/chat/domain/use-case/message/message-download-attachment-user-case.service.ts index 44acee0f6..df5a81c9a 100644 --- a/src/app/module/chat/domain/use-case/message/message-download-attachment-user-case.service.ts +++ b/src/app/module/chat/domain/use-case/message/message-download-attachment-user-case.service.ts @@ -46,7 +46,7 @@ export class DownloadMessageAttachmentUserCaseService { this.AttachmentLocalDataSource.insert({ $messageId: input.$messageId, id: input.id, - file: blob + file: blob, }) return dataUrl.value diff --git a/src/app/ui/chat/component/messages/messages.page.html b/src/app/ui/chat/component/messages/messages.page.html index 55457e211..6eb533d74 100644 --- a/src/app/ui/chat/component/messages/messages.page.html +++ b/src/app/ui/chat/component/messages/messages.page.html @@ -109,7 +109,7 @@ -
+
diff --git a/src/app/ui/chat/component/messages/messages.page.ts b/src/app/ui/chat/component/messages/messages.page.ts index f023dfb0d..22efc7727 100644 --- a/src/app/ui/chat/component/messages/messages.page.ts +++ b/src/app/ui/chat/component/messages/messages.page.ts @@ -855,17 +855,19 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy - async openViewDocumentModal(file: any) { + async openViewDocumentModal(msg: MessageViewModal) { + + console.log('passing', msg) let task = { serialNumber: '', taskStartDate: '', isEvent: true, workflowInstanceDataFields: { FolderID: '', - Subject: file.Assunto, - SourceSecFsID: file.ApplicationId, + Subject: msg.attachments[0].description, + SourceSecFsID: msg.attachments[0].applicationId, SourceType: 'DOC', - SourceID: file.DocId, + SourceID: msg.attachments[0].docId, DispatchNumber: '' } } @@ -874,13 +876,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy "Id": "", "ParentId": "", "Source": 1, - "ApplicationId": file.ApplicationId, + "ApplicationId": msg.attachments[0].applicationId, "CreateDate": "", "Data": null, "Description": "", "Link": null, - "SourceId": file.DocId, - "SourceName": file.Assunto, + "SourceId": msg.attachments[0].docId, + "SourceName": msg.attachments[0].description, "Stakeholders": "", } @@ -889,13 +891,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy componentProps: { trustedUrl: '', file: { - title: file.Assunto, + title: msg.attachments[0].description, url: '', title_link: '', }, Document: doc, - applicationId: file.ApplicationId, - docId: file.DocId, + applicationId: msg.attachments[0].applicationId, + docId: msg.attachments[0].docId, folderId: '', task: task }, @@ -1092,7 +1094,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy source: MessageAttachmentSource.Webtrix, fileType: MessageAttachmentFileType.Doc, applicationId: res.data.selected.ApplicationType, - docId: res.data.selected.Id, + docId: parseInt(res.data.selected.Id) , description: res.data.selected.Assunto }] @@ -1387,25 +1389,33 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy return blob; } - downloadFileFromBrowser(fileName: string, data: any): void { + downloadFileFromBrowser(fileName: string, msg: MessageViewModal): void { - const link = document.createElement("a") - link.href = `data:${data.type}';base64,${data.image_url}`; - link.download = fileName - link.click() + if(msg.attachments[0]?.blobURl) { + // Create a temporary URL for the Blob + const url = msg.attachments[0].safeFile; + + // Create an element with the download attribute + const a = document.createElement('a'); + a.href = url; + a.download = fileName; // Set the desired file name + + // Programmatically click the element to trigger the download + document.body.appendChild(a); + a.click(); + } else { + const link = document.createElement("a") + link.href = `data:${msg.attachments[0].mimeType}';base64,${msg.attachments[0].safeFile}`; + link.download = fileName + link.click() + + link.remove() + } - link.remove() } - viewDocument(file: any, url?: string) { - - if (file.type == "application/webtrix") { - this.openViewDocumentModal(file); - } - else { - let fullUrl = "https://www.tabularium.pt" + url; - this.fileService.viewDocumentByUrl(fullUrl); - } + viewDocument(msg: MessageViewModal) { + this.openViewDocumentModal(msg); } openFile(pdfString, filename, type) { @@ -1432,42 +1442,42 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy .catch(e => console.error(e)) } - async openPreview(msg) { + async openPreview(msg: MessageViewModal) { - if (msg.file.type === "application/webtrix") { - this.viewDocument(msg.file, msg.attachments.image_url) + console.log(msg) + if (msg.attachments[0].source === MessageAttachmentSource.Webtrix) { + this.viewDocument(msg) } else { - if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') { + if (!msg.attachments[0].safeFile || msg.attachments[0].safeFile === null || msg.attachments[0].safeFile === '') { // this.downloadFileMsg(msg) } else { - var str = msg.attachments[0].image_url - str = str.substring(1, ((str.length) - 1)); + var str = msg.attachments[0].safeFile if (this.platform.is('desktop') || this.platform.is('mobileweb')) { - if (msg.file.type == "application/img") { + if (msg.attachments[0].mimeType.includes('image')) { 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 + image: msg.attachments[0].safeFile, + type: msg.attachments[0].mimeType, + username: msg.attachments[0].description, + _updatedAt: msg.sentAt } }); modal.present(); } else { - this.downloadFileFromBrowser(msg.attachments[0].title, msg.attachments[0],) + this.downloadFileFromBrowser(msg.attachments[0].description, msg) } } else { - this.openFile(msg.attachments[0].image_url, msg.attachments[0].title, msg.file.type); + this.openFile(msg.attachments[0].safeFile, msg.attachments[0].description, msg.attachments[0].mimeType); // this.downloadFileFromBrowser("file", str) } diff --git a/src/app/ui/chat/modal/messages/messages.page.ts b/src/app/ui/chat/modal/messages/messages.page.ts index ff4bdcd44..d6042b55a 100644 --- a/src/app/ui/chat/modal/messages/messages.page.ts +++ b/src/app/ui/chat/modal/messages/messages.page.ts @@ -1009,7 +1009,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { source: MessageAttachmentSource.Webtrix, fileType: MessageAttachmentFileType.Doc, applicationId: res.data.selected.ApplicationType, - docId: res.data.selected.Id, + docId: parseInt(res.data.selected.Id), description: res.data.selected.Assunto }] diff --git a/workspace.code-workspace b/workspace.code-workspace index 62303319d..b456df374 100644 --- a/workspace.code-workspace +++ b/workspace.code-workspace @@ -5,6 +5,9 @@ }, { "path": "../sentry" + }, + { + "path": "../sentium" } ], "settings": {