Skip to content

Commit

Permalink
fixup! fix(outbox): add status for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
miaulalala committed Apr 3, 2024
1 parent d3e9789 commit d00de44
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/OutboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function send(int $id): JsonResponse {
if($message->getStatus() !== LocalMessage::STATUS_PROCESSED) {
return JsonResponse::error('Could not send message', Http::STATUS_INTERNAL_SERVER_ERROR, [$message]);
}
return JsonResponse::success(
return JsonResponse::success(
'Message sent', Http::STATUS_ACCEPTED
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/NewMessageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ export default {
if (!data.sendAt || data.sendAt < Math.floor((now + UNDO_DELAY) / 1000)) {
// Awaiting here would keep the modal open for a long time and thus block the user
this.$store.dispatch('outbox/sendMessageWithUndo', { id: dataForServer.id })
this.$store.dispatch('outbox/sendMessageWithUndo', { id: dataForServer.id }).catch((error) => {
logger.debug('Could not send message', { error })
})
}
if (dataForServer.id) {
// Remove old draft envelope
Expand Down
36 changes: 18 additions & 18 deletions src/components/OutboxMessageListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
-->

<template>
<ListItem
v-if="message.status !== 11"
<ListItem v-if="message.status !== 11"
class="outbox-message"
:class="{ selected }"
:name="title"
Expand All @@ -35,13 +34,12 @@
{{ subjectForSubtitle }}
</template>
<template slot="actions">
<ActionButton
:close-after-click="true"
<ActionButton :close-after-click="true"
@click="sendMessageNow">
{{ t('mail', 'Send now') }}
<template #icon>
<Send :title="t('mail', 'Send now')"
:size="20" />
:size="20" />
</template>
</ActionButton>
<ActionButton :close-after-click="true"
Expand All @@ -53,8 +51,7 @@
</ActionButton>
</template>
</ListItem>
<ListItem
v-else
<ListItem v-else
class="outbox-message"
:name="title"
:class="{ selected }"
Expand All @@ -66,17 +63,16 @@
{{ subjectForSubtitle }}
</template>
<template slot="actions">
<ActionButton
:close-after-click="true"
<ActionButton :close-after-click="true"
@click="sendMessageNow">
{{ t('mail', 'Copy to "Sent" Mailbox') }}
<template #icon>
<Send :title="t('mail', 'Copy to Sent Mailbox')"
:size="20" />
:size="20" />
</template>
</ActionButton>
<ActionButton :close-after-click="true"
@click="deleteMessage">
@click="deleteMessage">
<template #icon>
<IconDelete :size="20" />
</template>
Expand Down Expand Up @@ -133,7 +129,7 @@ export default {
details() {
if (this.message.status === 11) {
return this.t('mail', 'Could not copy to "Sent" mailbox')
} else if(this.message.status !== 0) {
} else if (this.message.status !== 0) {
return this.t('mail', 'Message could not be sent')
}
if (!this.message.sendAt) {
Expand Down Expand Up @@ -175,15 +171,19 @@ export default {
sendAt: (new Date().getTime() + UNDO_DELAY) / 1000,
}
await this.$store.dispatch('outbox/updateMessage', { message, id: message.id })
if(this.message.status !== 11) {
await this.$store.dispatch('outbox/sendMessageWithUndo', { id: message.id })
} else {
await this.$store.dispatch('outbox/copyMessageToSentMailbox', { id: message.id })
try {
if (this.message.status !== 11) {
await this.$store.dispatch('outbox/sendMessageWithUndo', { id: message.id })
} else {
await this.$store.dispatch('outbox/copyMessageToSentMailbox', { id: message.id })
}
} catch (error) {
logger.error('Could not send or copy message', { error })
await this.$store.dispatch('outbox/updateMessage', { message: error.data[0], id: message.id })
}

},
async openModal() {
if(this.message.status === 11) {
if (this.message.status === 11) {
return
}
await this.$store.dispatch('startComposerSession', {
Expand Down
19 changes: 9 additions & 10 deletions src/store/outbox/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default {
await OutboxService.sendMessage(id)
logger.debug(`Outbox message ${id} sent`)
} catch (error) {
const m = error.response.data.data
const m = error.response.data.data[0]
commit('updateMessage', { message: m })
logger.error(`Failed to send message ${id} from outbox`, { error })
throw error
Expand Down Expand Up @@ -198,17 +198,16 @@ export default {
* @param {object} store.getters Vuex getters object
* @param {object} data Action data
* @param {number} data.id Id of outbox message to send
* @return
*/
async copyMessageToSentMailbox({ getters, dispatch }, { id }) {
const message = getters.getMessage(id)
const message = getters.getMessage(id)

try {
const wasSent = await dispatch('sendMessage', { id: message.id })
showSuccess(t('mail', 'Message copied to "Sent" mailbox'))
} catch (error) {
showError(t('mail', 'Could not copy message to "Sent" mailbox'))
logger.error('Could not copy message to "Sent" mailbox ' + message.id, { message })
}
try {
await dispatch('sendMessage', { id: message.id })
showSuccess(t('mail', 'Message copied to "Sent" mailbox'))
} catch (error) {
showError(t('mail', 'Could not copy message to "Sent" mailbox'))
logger.error('Could not copy message to "Sent" mailbox ' + message.id, { message })
}
},
}
2 changes: 1 addition & 1 deletion src/store/outbox/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default {
},
updateMessage(state, { message }) {
const existing = state.messages[message.id] ?? {}
Vue.set(state.messages, message.id, Object.assign({}, existing, message))
Vue.set(state.messages, message.id, Object.assign(existing, message))
// Add the message only if it's new
if (state.messageList.indexOf(message.id) === -1) {
state.messageList.unshift(message.id)
Expand Down

0 comments on commit d00de44

Please sign in to comment.