diff --git a/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue b/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue index 825427c5b65..940b16f2412 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue +++ b/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue @@ -376,7 +376,7 @@ export default { const availableHandlers = OCA.Viewer.availableHandlers for (let i = 0; i < availableHandlers.length; i++) { - if (availableHandlers[i]?.mimes?.includes(this.mimetype)) { + if (availableHandlers[i]?.mimes?.includes && availableHandlers[i].mimes.includes(this.mimetype)) { return true } } diff --git a/src/components/NewMessageForm/NewMessageForm.vue b/src/components/NewMessageForm/NewMessageForm.vue index 28937d529d8..66abdf1c167 100644 --- a/src/components/NewMessageForm/NewMessageForm.vue +++ b/src/components/NewMessageForm/NewMessageForm.vue @@ -43,27 +43,41 @@ :disabled="disabled" :aria-label="t('spreed', 'Share files to the conversation')" :aria-haspopup="true"> - + + + + - {{ t('spreed', 'Upload new files') }} + + + + {{ t('spreed', 'Upload from device') }} - {{ t('spreed', 'Share from Files') }} + + + + {{ shareFromNextcloudLabel }} + + + {{ provider.label }} + + - + + + {{ t('spreed', 'Create new poll') }} @@ -141,15 +155,65 @@ + + + + + + + {{ t('spreed', 'Create and share a new file') }} + + + + + + + + + + + + + + + {{ t('spreed', 'Close') }} + + + {{ t('spreed', 'Create file') }} + + + + + @@ -648,4 +865,38 @@ export default { opacity: .5 !important; } } + +.new-text-file { + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + gap: 28px; + padding: 20px; + + &__buttons { + display: flex; + gap: 4px; + justify-content: center; + margin-top: 20px; + } + + &__form { + width: 100%; + + .templates-picker__list { + margin-top: 20px; + display: grid; + grid-gap: calc(var(--margin) * 2); + grid-auto-columns: 1fr; + // We want maximum 5 columns. Putting 6 as we don't count the grid gap. So it will always be lower than 6 + max-width: calc(var(--fullwidth) * 6); + grid-template-columns: repeat(auto-fit, var(--fullwidth)); + // Make sure all rows are the same height + grid-auto-rows: 1fr; + // Center the columns set + justify-content: center; + } + } +} diff --git a/src/components/NewMessageForm/TemplatePreview.vue b/src/components/NewMessageForm/TemplatePreview.vue new file mode 100644 index 00000000000..88a58530c9b --- /dev/null +++ b/src/components/NewMessageForm/TemplatePreview.vue @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + {{ nameWithoutExt }} + + + + + + + + diff --git a/src/services/filesSharingServices.js b/src/services/filesSharingServices.js index 2b9b2f1fdff..218308ba725 100644 --- a/src/services/filesSharingServices.js +++ b/src/services/filesSharingServices.js @@ -30,11 +30,11 @@ 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 { - return axios.post( + return await axios.post( generateOcsUrl('apps/files_sharing/api/v1/shares'), { shareType: 10, // OC.Share.SHARE_TYPE_ROOM, @@ -55,6 +55,28 @@ const shareFile = async function(path, token, referenceId, metadata) { } } +const getFileTemplates = async () => { + return await axios.get(generateOcsUrl('apps/files/api/v1/templates')) +} + +/** + * Share a text file to a conversation + * + * @param {string} filePath The new file destination path + * @param {string} templatePath The template source path + * @param {string} templateType The template type e.g 'user' + * @return { object } the file object + */ +const createTextFile = async function(filePath, templatePath, templateType) { + return await axios.post(generateOcsUrl('apps/files/api/v1/templates/create'), { + filePath, + templatePath, + templateType, + }) +} + export { shareFile, + getFileTemplates, + createTextFile, } diff --git a/src/store/fileUploadStore.js b/src/store/fileUploadStore.js index 38810179a25..581949d9912 100644 --- a/src/store/fileUploadStore.js +++ b/src/store/fileUploadStore.js @@ -27,7 +27,10 @@ import fromStateOr from './helper.js' import { findUniquePath, getFileExtension } from '../utils/fileUpload.js' import moment from '@nextcloud/moment' import { EventBus } from '../services/EventBus.js' -import { shareFile } from '../services/filesSharingServices.js' +import { + getFileTemplates, + shareFile, +} from '../services/filesSharingServices.js' import { setAttachmentFolder } from '../services/settingsService.js' const state = { @@ -36,6 +39,9 @@ const state = { uploads: { }, currentUploadId: undefined, + + fileTemplatesInitialised: false, + fileTemplates: [], } const getters = { @@ -93,6 +99,14 @@ const getters = { currentUploadId: (state) => { return state.currentUploadId }, + + areFileTemplatesInitialised: (state) => { + return state.fileTemplatesInitialised + }, + + getFileTemplates: (state) => () => { + return state.fileTemplates + }, } const mutations = { @@ -182,6 +196,11 @@ const mutations = { discardUpload(state, { uploadId }) { Vue.delete(state.uploads, uploadId) }, + + storeFilesTemplates(state, { template }) { + state.fileTemplates.push(template) + state.fileTemplatesInitialised = true + }, } const actions = { @@ -406,6 +425,17 @@ const actions = { commit('removeFileFromSelection', temporaryMessageId) }, + async getFileTemplates({ commit }) { + try { + const response = await getFileTemplates() + + response.data.ocs.data.forEach(template => { + commit('storeFilesTemplates', { template }) + }) + } catch (error) { + console.error('An error happened when trying to load the templates', error) + } + }, } export default { state, mutations, getters, actions }