1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
<template>
<Modal
size="normal"
:title="t('mail', 'Outbox draft')"
@close="$emit('close')">
<Composer
:from-account="message.accountId"
:to="message.to"
:cc="message.cc"
:bcc="message.bcc"
:subject="message.subject"
:body="outboxBody"
:draft="saveDraft"
:send="sendMessage" />
</Modal>
</template>
<script>
import Modal from '@nextcloud/vue/dist/Components/Modal'
import logger from '../logger'
import { html, plain, toPlain } from '../util/text'
import Composer from './Composer'
export default {
name: 'OutboxComposer',
components: {
Modal,
Composer,
},
props: {
message: {
type: Object,
required: true,
},
},
computed: {
outboxBody() {
if (this.message.html) {
return html(this.message.text)
}
return plain(this.message.text)
},
},
methods: {
stringToRecipients(str) {
if (str === undefined) {
return []
}
return [
{
label: str,
email: str,
},
]
},
async saveDraft(data) {
if (data.draftId === undefined && this.draft) {
logger.debug('draft data does not have a draftId, adding one', {
draft: this.draft,
data,
id: this.draft.databaseId,
})
data.draftId = this.draft.databaseId
}
const dataForServer = {
...data,
body: data.isHtml ? data.body.value : toPlain(data.body).value,
}
await this.$store.dispatch('outbox/updateMessage', { message: dataForServer, id: this.message.id })
},
async sendMessage(data) {
logger.debug('sending message', { data })
const now = new Date().getTime()
const dataForServer = {
accountId: data.account,
sendAt: Math.floor(now / 1000), // JS timestamp is in milliseconds
subject: data.subject,
body: data.isHtml ? data.body.value : toPlain(data.body).value,
isHtml: data.isHtml,
isMdn: false,
inReplyToMessageId: '',
to: data.to,
cc: data.cc,
bcc: data.bcc,
attachmentIds: [],
}
const message = await this.$store.dispatch('outbox/enqueueMessage', {
message: dataForServer,
})
await this.$store.dispatch('outbox/sendMessage', { id: message.id })
// Remove old draft envelope
this.$store.commit('removeEnvelope', { id: data.draftId })
this.$store.commit('removeMessage', { id: data.draftId })
},
},
}
</script>
<style lang="scss" scoped>
@media only screen and (max-width: 600px) {
::v-deep .modal-container {
max-width: 80%;
}
}
::v-deep .modal-container {
width: 80%;
min-height: 60%;
}
::v-deep .modal-wrapper .modal-container {
overflow-y: auto !important;
overflow-x: auto !important;
}
</style>
|