diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index 2e9c0a0648..1215f58128 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -858,6 +858,7 @@ public function saveAttachment(int $id, ); } + $lastFile = null; foreach ($attachments as $attachment) { $fileName = $attachment->getName() ?? $this->l10n->t('Embedded message %s', [ $attachment->getId(), @@ -874,8 +875,17 @@ public function saveAttachment(int $id, $newFile = $this->userFolder->newFile($fullPath); $newFile->putContent($attachment->getContent()); + $lastFile = $newFile; } - return new JSONResponse(); + + if ($lastFile === null) { + return new JSONResponse(['fileId' => null, 'path' => null]); + } + + return new JSONResponse([ + 'fileId' => $lastFile->getId(), + 'path' => $targetPath, + ]); } /** diff --git a/src/components/MessageAttachment.vue b/src/components/MessageAttachment.vue index 8fb911bdcd..7c1b3583c0 100644 --- a/src/components/MessageAttachment.vue +++ b/src/components/MessageAttachment.vue @@ -85,7 +85,9 @@ import { showError, showSuccess } from '@nextcloud/dialogs' import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js' import { formatFileSize } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' +import { generateUrl } from '@nextcloud/router' import { NcActionButton as ActionButton, NcActions as Actions, NcLoadingIcon as IconLoading } from '@nextcloud/vue' +import escapeHtml from 'escape-html' import IconArrow from 'vue-material-design-icons/ArrowLeft.vue' import IconSave from 'vue-material-design-icons/FolderOutline.vue' import IconAdd from 'vue-material-design-icons/Plus.vue' @@ -231,9 +233,20 @@ export default { const id = this.$route.params.threadId try { - await saveAttachmentToFiles(id, this.id, path) + const saved = await saveAttachmentToFiles(id, this.id, path) Logger.info('saved') - showSuccess(t('mail', 'Attachment saved to Files')) + + const fileLocationUrl = generateUrl('/apps/files/files/{fileId}?dir={dir}&openfile=true', { + fileId: saved?.fileId, + dir: saved?.path, + }) + + const savedText = t('mail', 'Attachment saved to Files') + const goToFilesText = t('mail', 'Go to Files') + + showSuccess(`

${escapeHtml(savedText)}

${escapeHtml(goToFilesText)}

`, { + isHTML: true, + }) } catch (e) { Logger.error('not saved', { error: e }) showError(t('mail', 'Attachment could not be saved')) diff --git a/src/service/AttachmentService.js b/src/service/AttachmentService.js index a09cc36617..9c69890f8d 100644 --- a/src/service/AttachmentService.js +++ b/src/service/AttachmentService.js @@ -15,9 +15,11 @@ export async function saveAttachmentToFiles(id, attachmentId, directory) { }, ) - return await Axios.post(url, { + const res = await Axios.post(url, { targetPath: directory, }) + + return res.data } export async function saveAttachmentsToFiles(id, directory) { diff --git a/tests/Unit/Controller/MessagesControllerTest.php b/tests/Unit/Controller/MessagesControllerTest.php index 5651124b18..c0d24d84b5 100644 --- a/tests/Unit/Controller/MessagesControllerTest.php +++ b/tests/Unit/Controller/MessagesControllerTest.php @@ -398,7 +398,10 @@ public function testSaveSingleAttachment() { ->method('getContent') ->will($this->returnValue('abcdefg')); - $expected = new JSONResponse(); + $expected = new JSONResponse([ + 'fileId' => $file->getId(), + 'path' => $targetPath, + ]); $response = $this->controller->saveAttachment( $id, $attachmentId,