Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Dashboard.vue « components « src - github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 17c6b9d2816aeffa9e595f5543d5d493e5c17c9e (plain)
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
<!--
  - @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
  -
  - @author Julius Härtl <jus@bitgrid.net>
  - @author Richard Steinmetz <richard@steinmetz.cloud>
  -
  - @license AGPL-3.0-or-later
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
  -
  -->

<template>
	<DashboardWidget :items="importantMessages"
		:show-more-url="''"
		:loading="loading"
		@hide="() => {}"
		@markDone="() => {}">
		<template #default="{ item }">
			<DashboardWidgetItem :class="{unread: itemUnread(item)}"
				:target-url="itemTargetUrl(item)"
				:main-text="itemMainText(item)"
				:sub-text="itemSubText(item)">
				<template #avatar>
					<Avatar v-if="item.from"
						:email="item.from[0].email"
						:display-name="item.from[0].label"
						:disable-tooltip="true"
						:size="44" />
				</template>
			</DashboardWidgetItem>
		</template>
		<template #empty-content>
			<EmptyContent id="mail--empty-content" icon="icon-checkmark">
				<template #desc>
					{{ t('mail', 'No message found yet') }}
					<div class="no-account">
						<a v-if="accounts.length === 0" :href="accountSetupUrl" class="button">{{ t('mail', 'Set up an account') }}</a>
					</div>
				</template>
			</EmptyContent>
		</template>
	</DashboardWidget>
</template>

<script>
import { loadState } from '@nextcloud/initial-state'
import { generateUrl, imagePath } from '@nextcloud/router'
import { DashboardWidget, DashboardWidgetItem } from '@nextcloud/vue-dashboard'
import orderBy from 'lodash/fp/orderBy'
import prop from 'lodash/fp/prop'
import EmptyContent from '@nextcloud/vue/dist/Components/EmptyContent'

import Avatar from '../components/Avatar'
import { fetchEnvelopes } from '../service/MessageService'
import logger from '../logger'
import { fetchAll } from '../service/MailboxService'

const accounts = loadState('mail', 'mail-accounts')
const orderByDateInt = orderBy(prop('dateInt'), 'desc')

export default {
	name: 'Dashboard',
	components: {
		Avatar,
		DashboardWidget,
		DashboardWidgetItem,
		EmptyContent,
	},
	props: {
		query: {
			type: String,
			required: true,
		},
	},
	data() {
		return {
			messages: [],
			accounts,
			loading: true,
			fetchedAccounts: 0,
			emptyImage: imagePath('mail', 'newsletter.svg'),
			accountSetupUrl: generateUrl('/apps/mail/#/setup'),
		}
	},
	computed: {
		importantMessages() {
			if (!this.messages) {
				return []
			}
			return orderByDateInt(this.messages).slice(0, 7)
		},
	},
	async mounted() {
		const accountInboxes = await Promise.all(this.accounts.map(async(account) => {
			logger.debug('account', {
				account,
			})

			const mailboxes = await fetchAll(account.accountId)

			logger.debug('mailboxes', {
				mailboxes,
			})

			return mailboxes.filter(mb => mb.specialRole === 'inbox')
		}))
		const inboxes = accountInboxes.flat()

		logger.debug(`found ${inboxes.length} inboxes`, {
			inboxes,
		})

		await Promise.all(inboxes.map(async(mailbox) => {
			const messages = await fetchEnvelopes(mailbox.accountId, mailbox.databaseId, this.query, undefined, 10)
			this.messages = this.messages !== null ? [...this.messages, ...messages] : messages
			this.fetchedAccounts++
		}))

		this.loading = false
	},
	methods: {
		itemMainText(item) {
			return item.from ? item.from[0].label : ''
		},
		itemSubText(item) {
			return item.subject
		},
		itemTargetUrl(item) {
			return generateUrl(`/apps/mail/box/priority/thread/${item.databaseId}`)
		},
		itemUnread(item) {
			return !item.flags.seen
		},
	},
}
</script>

<style lang="scss" scoped>
#mail--empty-content {
	text-align: center;
	margin-top: 5vh;
}
.no-account {
	margin-top: 5vh;
	margin-right: 5px;
}
.unread ::v-deep .item__details {
	font-weight: bold;
}
</style>