Skip to content

Commit

Permalink
Merge pull request #1409 from nextcloud/fix/await-attachment-upload-s…
Browse files Browse the repository at this point in the history
…end-message

Fix awaiting of local attachment upload before sending a message
  • Loading branch information
ChristophWurst committed Dec 20, 2018
2 parents 032cd24 + 8356a34 commit bb73652
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
25 changes: 19 additions & 6 deletions src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@
:value="submitButtonTitle"
v-on:click="onSend">
</div>
<ComposerAttachments v-model="attachments" />
<ComposerAttachments v-model="attachments"
@upload="onAttachmentsUploading"/>
<span id="draft-status" v-if="savingDraft === true">{{ t('mail', 'Saving draft …') }}</span>
<span id="draft-status" v-else-if="savingDraft === false">{{ t('mail', 'Draft saved') }}</span>
</div>
<Loading v-else-if="state === STATES.UPLOADING"
:hint="t('mail', 'Uploading attachments …')" />
<Loading v-else-if="state === STATES.SENDING"
:hint="t('mail', 'Sending …')" />
<div v-else-if="state === STATES.ERROR"
Expand Down Expand Up @@ -134,9 +137,10 @@
const STATES = Object.seal({
EDITING: 0,
SENDING: 1,
ERROR: 2,
FINISHED: 3,
UPLOADING: 1,
SENDING: 2,
ERROR: 3,
FINISHED: 4,
})
export default {
Expand Down Expand Up @@ -197,6 +201,7 @@
message: '',
submitButtonTitle: t('mail', 'Send'),
draftsPromise: Promise.resolve(),
attachmentsPromise: Promise.resolve(),
savingDraft: undefined,
saveDraftDebounced: _.debounce(this.saveDraft, 700),
state: STATES.EDITING,
Expand Down Expand Up @@ -282,6 +287,12 @@
)
})
},
onAttachmentsUploading (uploaded) {
this.attachmentsPromise = this.attachmentsPromise
.then(() => uploaded)
.catch(console.error.bind(this))
.then(() => console.debug('attachments uploaded'))
},
onNewToAddr (addr) {
this.onNewAddr(addr, this.selectTo)
},
Expand All @@ -300,9 +311,11 @@
list.push(res)
},
onSend () {
this.state = STATES.SENDING
this.state = STATES.UPLOADING
return this.draftsPromise
return this.attachmentsPromise
.then(() => this.state = STATES.SENDING)
.then(() => this.draftsPromise)
.then(this.getMessageData())
.then(data => this.send(data))
.then(() => console.info('message sent'))
Expand Down
6 changes: 5 additions & 1 deletion src/components/ComposerAttachments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
onLocalAttachmentSelected (e) {
this.uploading = true
return Promise.all(
const done = Promise.all(
_.map(
e.target.files,
file => uploadLocalAttachment(file)
Expand All @@ -104,6 +104,10 @@
)
.catch(console.error.bind(this))
.then(() => this.uploading = false)
this.$emit('upload', done)
return done
},
onAddCloudAttachment () {
return pickFileOrDirectory(t('mail', 'Choose a file to add as attachment'))
Expand Down

0 comments on commit bb73652

Please sign in to comment.