Skip to content

Commit

Permalink
fixup! fix(shares): allow to retry failed uploads
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Dec 15, 2023
1 parent 3bb61c9 commit 5c3c31c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,6 @@ export default {
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
14 changes: 10 additions & 4 deletions src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ const getters = {
.filter(([_index, uploadedFile]) => uploadedFile.status === 'failedUpload')
},

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

// Returns all the files that have been successfully uploaded provided an
// upload id
getShareableFiles: (state, getters) => (uploadId) => {
Expand Down Expand Up @@ -306,8 +311,8 @@ const actions = {

// Tag previously indexed files and add temporary messages to the MessagesList
// If caption is provided, attach to the last temporary message
const lastIndex = getters.getUploadsArray(uploadId).at(-1).at(0)
for (const [index, uploadedFile] of getters.getUploadsArray(uploadId)) {
const lastIndex = getters.getInitialisedUploads(uploadId).at(-1).at(0)
for (const [index, uploadedFile] of getters.getInitialisedUploads(uploadId)) {
// mark all files as uploading
commit('markFileAsUploading', { uploadId, index })
// Store the previously created temporary message
Expand Down Expand Up @@ -406,7 +411,7 @@ const actions = {
const client = getDavClient()
const userRoot = '/files/' + getters.getUserId()

const uploads = getters.getUploadsArray(uploadId)
const uploads = getters.getUploadingFiles(uploadId)
// Check for duplicate names in the uploads array
if (hasDuplicateUploadNames(uploads)) {
const { uniques, duplicates } = separateDuplicateUploads(uploads)
Expand Down Expand Up @@ -449,7 +454,8 @@ const actions = {
* @param {string} [data.caption] the message caption;
*/
retryUploadFiles(context, { uploadId, caption }) {
context.getters.getFailedUploads(uploadId).forEach(([index, _uploadedFile]) => {
context.getters.getFailedUploads(uploadId).forEach(([index, file]) => {
context.dispatch('removeTemporaryMessageFromStore', file.temporaryMessage)
context.commit('markFileAsInitializedUpload', { uploadId, index })
})

Expand Down

0 comments on commit 5c3c31c

Please sign in to comment.