Skip to content

Commit

Permalink
fix(shares): allow to retry failed uploads
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Dec 15, 2023
1 parent 07fd984 commit 5584fcc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ export default {
sendingErrorCanRetry() {
return this.sendingFailure === 'timeout' || this.sendingFailure === 'other'
|| this.sendingFailure === 'failed-upload'
},
sendingErrorIconTooltip() {
Expand Down Expand Up @@ -810,8 +811,14 @@ export default {
handleRetry() {
if (this.sendingErrorCanRetry) {
EventBus.$emit('retry-message', this.id)
EventBus.$emit('focus-chat-input')
if (this.sendingFailure === 'failed-upload') {
const caption = this.renderedMessage !== this.message ? this.message : undefined
this.$store.dispatch('retryUploadFiles', { uploadId: this.messageObject.uploadId, caption })
this.$store.dispatch('removeTemporaryMessageFromStore', this.messageObject)
} else {
EventBus.$emit('retry-message', this.id)
EventBus.$emit('focus-chat-input')
}
}
},
Expand Down
34 changes: 34 additions & 0 deletions src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
shareFile,
} from '../services/filesSharingServices.js'
import { setAttachmentFolder } from '../services/settingsService.js'
import { useChatExtrasStore } from '../stores/chatExtras.js'
import {
hasDuplicateUploadNames,
findUniquePath,
Expand Down Expand Up @@ -66,6 +67,11 @@ const getters = {
.filter(([_index, uploadedFile]) => uploadedFile.status === 'initialised')
},

getFailedUploads: (state, getters) => (uploadId) => {
return getters.getUploadsArray(uploadId)
.filter(([_index, uploadedFile]) => uploadedFile.status === 'failedUpload')
},

// Returns all the files that have been successfully uploaded provided an
// upload id
getShareableFiles: (state, getters) => (uploadId) => {
Expand Down Expand Up @@ -132,6 +138,11 @@ const mutations = {
Vue.set(state.localUrls, temporaryMessage.referenceId, localUrl)
},

// Marks a given file as initialized (for retry)
markFileAsInitializedUpload(state, { uploadId, index }) {
state.uploads[uploadId].files[index].status = 'initialised'
},

// Marks a given file as failed upload
markFileAsFailedUpload(state, { uploadId, index, status }) {
state.uploads[uploadId].files[index].status = 'failedUpload'
Expand Down Expand Up @@ -427,6 +438,29 @@ const actions = {

EventBus.$emit('upload-finished')
},

/**
* Re-initialize failed uploads and open UploadEditor dialog
* Insert caption if was provided
*
* @param {object} context default store context;
* @param {object} data payload;
* @param {string} data.uploadId the internal id of the upload;
* @param {string} [data.caption] the message caption;
*/
retryUploadFiles(context, { uploadId, caption }) {
context.getters.getFailedUploads(uploadId).forEach(([index, _uploadedFile]) => {
context.commit('markFileAsInitializedUpload', { uploadId, index })
})

if (caption) {
const chatExtrasStore = useChatExtrasStore()
chatExtrasStore.setChatInput({ token: context.getters.getToken(), text: caption })
}

context.commit('setCurrentUploadId', uploadId)
},

/**
* Set the folder to store new attachments in
*
Expand Down
5 changes: 5 additions & 0 deletions src/store/fileUploadStore.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { createLocalVue } from '@vue/test-utils'
import mockConsole from 'jest-mock-console'
import { cloneDeep } from 'lodash'
import { createPinia, setActivePinia } from 'pinia'
import Vuex from 'vuex'

import { showError } from '@nextcloud/dialogs'

// eslint-disable-next-line no-unused-vars -- required for testing
import storeConfig from './storeConfig.js'
// eslint-disable-next-line import/order -- required for testing
import fileUploadStore from './fileUploadStore.js'
import { getDavClient } from '../services/DavClient.js'
import { shareFile } from '../services/filesSharingServices.js'
Expand Down Expand Up @@ -39,6 +43,7 @@ describe('fileUploadStore', () => {

localVue = createLocalVue()
localVue.use(Vuex)
setActivePinia(createPinia())

mockedActions = {
createTemporaryMessage: jest.fn()
Expand Down

0 comments on commit 5584fcc

Please sign in to comment.