diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/NewMessageForm/NewMessageForm.vue | 50 | ||||
-rw-r--r-- | src/services/filesSharingServices.js | 21 |
2 files changed, 44 insertions, 27 deletions
diff --git a/src/components/NewMessageForm/NewMessageForm.vue b/src/components/NewMessageForm/NewMessageForm.vue index cee580881..5eb5ba0a5 100644 --- a/src/components/NewMessageForm/NewMessageForm.vue +++ b/src/components/NewMessageForm/NewMessageForm.vue @@ -189,7 +189,7 @@ <script> import AdvancedInput from './AdvancedInput/AdvancedInput.vue' -import { getFilePickerBuilder } from '@nextcloud/dialogs' +import { getFilePickerBuilder, showError } from '@nextcloud/dialogs' import { getCapabilities } from '@nextcloud/capabilities' import Quote from '../Quote.vue' import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' @@ -258,7 +258,7 @@ export default { isRecordingAudio: false, showSimplePollsEditor: false, showTextFileDialog: false, - textFileTitle: t('spreed', 'New text file'), + textFileTitle: t('spreed', 'New file'), } }, @@ -658,19 +658,49 @@ export default { filePath += fileTemplate.extension } - await createTextFile(filePath) - // FIXME If creation failed we should not share, as it could be an old/other file with the same name. - const response = await shareFile(filePath, this.token) - // TODO: before getting the link from the system message we need - // to wait till the message itself is received - const link = this.$store.getters.getSharedFileLink(this.token, response.data.ocs.data.file_source) - window.open(link, '_self') + let fileData + try { + const response = await createTextFile(filePath) + fileData = response.data.ocs.data + } catch (error) { + console.error('Error while creating file', error) + if (error?.response?.data?.ocs?.meta?.message) { + showError(error.response.data.ocs.meta.message) + } else { + showError(t('spreed', 'Error while creating file')) + } + return + } + + await shareFile(filePath, this.token, '', '') + + OCA.Viewer.open({ + // Viewer expects an internal absolute path starting with "/". + path: filePath, + list: [ + fileData, + ], + }) + + // FIXME Remove this hack once it is possible to set the parent + // element of the viewer. + // By default the viewer is a sibling of the fullscreen element, so + // it is not visible when in fullscreen mode. It is not possible to + // specify the parent nor to know when the viewer was actually + // opened, so for the time being it is reparented if needed shortly + // after calling it. + setTimeout(() => { + if (this.$store.getters.isFullscreen()) { + document.getElementById('content-vue').appendChild(document.getElementById('viewer')) + } + }, 1000) + this.dismissTextFileCreation() }, dismissTextFileCreation() { this.showTextFileDialog = false - this.textFileTitle = t('spreed', 'New text file') + this.textFileTitle = t('spreed', 'New file') }, // Focus and select the text within the input field diff --git a/src/services/filesSharingServices.js b/src/services/filesSharingServices.js index 213c76c50..64f28b2f9 100644 --- a/src/services/filesSharingServices.js +++ b/src/services/filesSharingServices.js @@ -30,7 +30,7 @@ import { showError } from '@nextcloud/dialogs' * @param {string} token The conversation's token * e.g. `/myfile.txt` * @param {string} referenceId An optional reference id to recognize the message later - * @param {Array} metadata the metadata json encoded array + * @param {string} metadata the metadata json encoded array */ const shareFile = async function(path, token, referenceId, metadata) { try { @@ -66,22 +66,9 @@ const getFileTemplates = async () => { * @return { object } the file object */ const createTextFile = async function(filePath) { - try { - return await axios.post( - generateOcsUrl('apps/files/api/v1/templates/create'), - { - filePath, - }) - } catch (error) { - // FIXME: errors should be handled by called instead - if (error?.response?.data?.ocs?.meta?.message) { - console.error('Error while creating file: ' + error.response.data.ocs.meta.message) - showError(error.response.data.ocs.meta.message) - } else { - console.error('Error while creating file: Unknown error') - showError(t('spreed', 'Error while creating file')) - } - } + return await axios.post(generateOcsUrl('apps/files/api/v1/templates/create'), { + filePath, + }) } export { |