-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathHome.vue
More file actions
188 lines (165 loc) Β· 4.91 KB
/
Copy pathHome.vue
File metadata and controls
188 lines (165 loc) Β· 4.91 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!--
- SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcContent app-name="mail" class="mail-content">
<Navigation />
<Outbox v-if="$route.name === 'outbox'" />
<MailboxThread
v-else-if="activeAccount"
:account="activeAccount"
:mailbox="activeMailbox" />
<template v-if="hasComposerSession && accounts !== null">
<ComposerSessionIndicator @close="onCloseMessageModal" />
<NewMessageModal ref="newMessageModal" :accounts="accounts" />
</template>
</NcContent>
</template>
<script>
import { NcContent } from '@nextcloud/vue'
import { mapState, mapStores } from 'pinia'
import ComposerSessionIndicator from '../components/ComposerSessionIndicator.vue'
import MailboxThread from '../components/MailboxThread.vue'
import Navigation from '../components/Navigation.vue'
import Outbox from '../components/Outbox.vue'
import logger from '../logger.js'
import { testAccountConnection } from '../service/AccountService.js'
import useMainStore from '../store/mainStore.js'
import '../styles/mail.scss'
export default {
name: 'Home',
components: {
NcContent,
MailboxThread,
Navigation,
NewMessageModal: () => import(/* webpackChunkName: "new-message-modal" */ '../components/NewMessageModal.vue'),
Outbox,
ComposerSessionIndicator,
},
data() {
return {
hasComposerSession: false,
}
},
computed: {
...mapStores(useMainStore),
...mapState(useMainStore, ['composerSessionId']),
accounts() {
return this.mainStore.getAccounts.filter((a) => !a.isUnified)
},
activeAccount() {
return this.mainStore.getAccount(this.activeMailbox?.accountId)
},
activeMailbox() {
return this.mainStore.getMailbox(this.$route.params.mailboxId)
},
},
watch: {
async composerSessionId(id) {
// Session was closed or discarded
if (!id) {
this.hasComposerSession = false
return
}
// A new session is replacing the old session. Fully reset the NewMessageModal
// component in this case and wait for the template to fully render before showing the
// modal again.
if (this.hasComposerSession) {
this.hasComposerSession = false
await this.$nextTick()
}
this.hasComposerSession = true
},
},
async beforeMount() {
for (const account of this.accounts) {
await this.mainStore.patchAccountMutation({
account,
data: { connectionStatus: await testAccountConnection(account.accountId) },
})
}
},
created() {
const accounts = this.mainStore.getAccounts
let startMailboxId = this.mainStore.getPreference('start-mailbox-id')
if (startMailboxId && !this.mainStore.getMailbox(startMailboxId)) {
// The start ID is set but the mailbox doesn't exist anymore
startMailboxId = null
}
if (this.$route.name === 'home' && accounts.length > 1 && startMailboxId) {
logger.debug('Loading start folder', { id: startMailboxId })
this.$router.replace({
name: 'mailbox',
params: {
mailboxId: startMailboxId,
},
})
} else if (this.$route.name === 'home' && accounts.length > 1) {
// Show first account
const firstAccount = accounts[0]
// FIXME: this assumes that there's at least one mailbox
const firstMailbox = this.mainStore.getMailboxes(firstAccount.id)[0]
logger.debug('loading first mailbox of first account', { accountId: firstAccount.id, mailboxId: firstMailbox.databaseId })
this.$router.replace({
name: 'mailbox',
params: {
mailboxId: firstMailbox.databaseId,
},
})
} else if (this.$route.name === 'home' && accounts.length === 1) {
logger.debug('the only account we have is the unified one -> show the setup page')
this.$router.replace({
name: 'setup',
})
} else if (this.$route.name === 'mailto') {
if (accounts.length === 0) {
logger.error('cannot handle mailto:, no accounts configured')
return
}
// Show first account
const firstAccount = accounts[0]
// FIXME: this assumes that there's at least one mailbox
const firstMailbox = this.mainStore.getMailboxes(firstAccount.id)[0]
logger.debug('loading composer with first account and folder', { accountId: firstAccount.id, mailboxId: firstMailbox.id })
this.$router.replace({
name: 'message',
params: {
mailboxId: firstMailbox.databaseId,
threadId: 'mailto',
},
query: {
to: this.$route.query.to,
cc: this.$route.query.cc,
bcc: this.$route.query.bcc,
subject: this.$route.query.subject,
body: this.$route.query.body,
},
})
}
},
methods: {
hideMessage() {
this.$router.replace({
name: 'mailbox',
params: {
mailboxId: this.$route.params.mailboxId,
filter: this.$route.params?.filter,
},
})
},
async onCloseMessageModal() {
await this.$refs.newMessageModal.onClose()
},
},
}
</script>
<style lang="scss" scoped>
:deep(.app-content-details) {
margin: 0 auto;
display: flex;
flex-direction: column;
flex: 1 1 100%;
min-width: 70%;
}
</style>