From 722fe35aab6d497303499e975350f731e6266dee Mon Sep 17 00:00:00 2001 From: Marco Ambrosini Date: Tue, 28 Jul 2020 18:08:40 +0200 Subject: [PATCH 01/12] Store current upload id Signed-off-by: Marco Ambrosini --- src/store/fileUploadStore.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/store/fileUploadStore.js b/src/store/fileUploadStore.js index b7c7d498451..2c765c83de2 100644 --- a/src/store/fileUploadStore.js +++ b/src/store/fileUploadStore.js @@ -32,6 +32,7 @@ const state = { attachmentFolder: loadState('talk', 'attachment_folder'), uploads: { }, + currentUploadId: undefined, } const getters = { @@ -64,6 +65,10 @@ const getters = { return 0 } }, + + currentUploadId: (state) => { + return state.currentUploadId + }, } const mutations = { @@ -131,6 +136,11 @@ const mutations = { console.debug('uploadId: ' + uploadId + ' index: ' + index) Vue.set(state.uploads[uploadId].files[index], 'temporaryMessage', temporaryMessage) }, + + // Sets the id of the current upload operation + setCurrentUploadId(state, currentUploadId) { + state.currentUploadId = currentUploadId + }, } const actions = { @@ -147,6 +157,8 @@ const actions = { // Add temporary messages for (const index in state.uploads[uploadId].files) { + // Set last upload id + commit('setCurrentUploadId', { uploadId }) // Mark file as uploading to prevent a second function call to start a // second upload for the same file commit('markFileAsUploading', { uploadId, index }) From 6ef9611ebc68901b6416b19f742aaaf098ef988e Mon Sep 17 00:00:00 2001 From: Marco Ambrosini Date: Tue, 28 Jul 2020 18:08:40 +0200 Subject: [PATCH 02/12] Store visibility of the upload editor Signed-off-by: Marco Ambrosini --- src/store/fileUploadStore.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/store/fileUploadStore.js b/src/store/fileUploadStore.js index 2c765c83de2..cd073665d64 100644 --- a/src/store/fileUploadStore.js +++ b/src/store/fileUploadStore.js @@ -33,6 +33,7 @@ const state = { uploads: { }, currentUploadId: undefined, + showUploadEditor: false, } const getters = { @@ -69,6 +70,10 @@ const getters = { currentUploadId: (state) => { return state.currentUploadId }, + + showUploadEditor: (state) => { + return state.showUploadEditor + }, } const mutations = { @@ -141,6 +146,11 @@ const mutations = { setCurrentUploadId(state, currentUploadId) { state.currentUploadId = currentUploadId }, + + // Shows hides the upload editor + showUploadEditor(state, show) { + state.showUploadEditor = show + }, } const actions = { From 661348eddb5828c10b450a5a7f726601e59782ab Mon Sep 17 00:00:00 2001 From: Marco Ambrosini Date: Tue, 28 Jul 2020 18:09:05 +0200 Subject: [PATCH 03/12] Add uploadeditor component Signed-off-by: Marco Ambrosini --- src/App.vue | 3 + src/components/UploadEditor.vue | 122 ++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/components/UploadEditor.vue diff --git a/src/App.vue b/src/App.vue index 655be16cd52..d2efc9e5fb1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -32,6 +32,7 @@ + @@ -61,6 +62,7 @@ import duplicateSessionHandler from './mixins/duplicateSessionHandler' import isInCall from './mixins/isInCall' import talkHashCheck from './mixins/talkHashCheck' import { generateUrl } from '@nextcloud/router' +import UploadEditor from './components/UploadEditor' export default { name: 'App', @@ -70,6 +72,7 @@ export default { LeftSidebar, PreventUnload, RightSidebar, + UploadEditor, }, mixins: [ diff --git a/src/components/UploadEditor.vue b/src/components/UploadEditor.vue new file mode 100644 index 00000000000..02ecd1d60c8 --- /dev/null +++ b/src/components/UploadEditor.vue @@ -0,0 +1,122 @@ + + + + + + + From 07fee78682b7daf7958b201409ee0a353402295d Mon Sep 17 00:00:00 2001 From: Marco Ambrosini Date: Mon, 3 Aug 2020 12:08:38 +0200 Subject: [PATCH 04/12] Create initialiseduploads store entry and split uploadfiles logic Signed-off-by: Marco Ambrosini --- src/components/UploadEditor.vue | 2 +- src/store/fileUploadStore.js | 62 +++++++++++++++++++++++++-------- src/utils/fileUpload.js | 2 +- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/components/UploadEditor.vue b/src/components/UploadEditor.vue index 02ecd1d60c8..6200771a083 100644 --- a/src/components/UploadEditor.vue +++ b/src/components/UploadEditor.vue @@ -69,7 +69,7 @@ export default { files() { if (this.currentUploadId) { - return this.$store.getters.getShareableFiles(this.currentUploadId) + return this.$store.getters.getInitialisedUploads(this.currentUploadId) } return [] }, diff --git a/src/store/fileUploadStore.js b/src/store/fileUploadStore.js index cd073665d64..0bd95cc6a26 100644 --- a/src/store/fileUploadStore.js +++ b/src/store/fileUploadStore.js @@ -37,6 +37,22 @@ const state = { } const getters = { + + getInitialisedUploads: (state) => (uploadId) => { + if (state.uploads[uploadId]) { + const initialisedUploads = {} + for (const index in state.uploads[uploadId].files) { + const currentFile = state.uploads[uploadId].files[index] + if (currentFile.status === 'initialised') { + initialisedUploads[index] = (currentFile) + } + } + return initialisedUploads + } else { + return {} + } + }, + // Returns all the files that have been successfully uploaded provided an // upload id getShareableFiles: (state) => (uploadId) => { @@ -106,6 +122,11 @@ const mutations = { Vue.set(state.uploads[uploadId].files[index], 'sharePath', sharePath) }, + // Marks a given file as initialised + markFileAsInitialised(state, { uploadId, index }) { + state.uploads[uploadId].files[index].status = 'initialised' + }, + // Marks a given file as uploading markFileAsUploading(state, { uploadId, index }) { state.uploads[uploadId].files[index].status = 'uploading' @@ -154,36 +175,47 @@ const mutations = { } const actions = { - /** - * Uploads the files to the root directory of the user - * @param {object} param0 Commit, state and getters - * @param {object} param1 The unique uploadId, the conversation token and the - * files array - */ - async uploadFiles({ commit, dispatch, state, getters }, { uploadId, token, files }) { + + initialiseUpload({ commit, dispatch }, { uploadId, token, files }) { + // Set last upload id + commit('setCurrentUploadId', uploadId) + // Show upload editor + commit('showUploadEditor', true) files.forEach(file => { commit('addFileToBeUploaded', { uploadId, token, file }) }) // Add temporary messages for (const index in state.uploads[uploadId].files) { - // Set last upload id - commit('setCurrentUploadId', { uploadId }) - // Mark file as uploading to prevent a second function call to start a - // second upload for the same file - commit('markFileAsUploading', { uploadId, index }) + // Mark file as initialised + commit('markFileAsInitialised', { uploadId, index }) // currentFile to be uploaded const currentFile = state.uploads[uploadId].files[index].file // Create temporary message for the file and add it to the message list const temporaryMessage = createTemporaryMessage('{file}', token, uploadId, index, currentFile) - dispatch('addTemporaryMessage', temporaryMessage) - // Scroll the message list - EventBus.$emit('scrollChatToBottom') + // Add the temporary messages to the store commit('setTemporaryMessageForFile', { uploadId, index, temporaryMessage }) } + }, + + /** + * Uploads the files to the root directory of the user + * @param {object} param0 Commit, state and getters + * @param {object} uploadId The unique uploadId + */ + async uploadFiles({ commit, dispatch, state, getters }, uploadId) { // Iterate through the previously indexed files for a given conversation (token) for (const index in state.uploads[uploadId].files) { + // Mark file as uploading to prevent a second function call to start a + // second upload for the same file + commit('markFileAsInitialised', { uploadId, index }) + // Store the previously created temporary message + const temporaryMessage = state.uploads[uploadId].files[index].temporaryMessage + // Add temporary messages (files) to the messages list + dispatch('addTemporaryMessage', temporaryMessage) + // Scroll the message list + EventBus.$emit('scrollChatToBottom') // currentFile to be uploaded const currentFile = state.uploads[uploadId].files[index].file // userRoot path diff --git a/src/utils/fileUpload.js b/src/utils/fileUpload.js index 5488e44f195..4fc5e5c33a9 100644 --- a/src/utils/fileUpload.js +++ b/src/utils/fileUpload.js @@ -69,7 +69,7 @@ const findUniquePath = async function(client, userRoot, path) { */ const processFiles = async function(files, token, uploadId) { // Process these files in the store - await store.dispatch('uploadFiles', { uploadId, token, files }) + await store.dispatch('initialiseUpload', { uploadId, token, files }) // Get the files that have successfully been uploaded from the store const shareableFiles = store.getters.getShareableFiles(uploadId) From 551305d3c92be066b32d1f0d7d3371bcea4197f3 Mon Sep 17 00:00:00 2001 From: Marco Ambrosini Date: Mon, 3 Aug 2020 15:45:37 +0200 Subject: [PATCH 05/12] Add ability to add more files to the current upload Signed-off-by: Marco Ambrosini --- src/components/UploadEditor.vue | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/components/UploadEditor.vue b/src/components/UploadEditor.vue index 6200771a083..6a69ae51f70 100644 --- a/src/components/UploadEditor.vue +++ b/src/components/UploadEditor.vue @@ -22,6 +22,13 @@