Newer
Older
<!--
- @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
-
- @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
-
- @license GNU AGPL version 3 or any later version
-
- 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>
v-if="visible"
:icon="icon"
:title="title"
:to="to"
@update:menuOpen="onMenuToggle">
<!-- actions -->
<template slot="actions">
v-if="!account.isUnified && mailbox.specialRole !== 'flagged'"
{{ statsText }}
</ActionText>
v-if="mailbox.specialRole !== 'flagged' && !account.isUnified"
:title="t('mail', 'Mark all as read')"
:disabled="loadingMarkAsRead"
{{ t('mail', 'Mark all messages of this mailbox as read') }}
v-if="!editing && top && !account.isUnified && mailbox.specialRole !== 'flagged'"
{{ t('mail', 'Add subfolder') }}
<ActionInput v-if="editing" icon="icon-folder" @submit.prevent.stop="createMailbox" />
<ActionText v-if="showSaving" icon="icon-loading-small">
{{ t('mail', 'Saving') }}
</ActionText>
v-if="debug && !account.isUnified && mailbox.specialRole !== 'flagged'"
icon="icon-settings"
:title="t('mail', 'Clear cache')"
:disabled="clearingCache"
{{ t('mail', 'Clear locally cached data, in case there are issues with synchronization.') }}
</ActionButton>
<ActionButton v-if="!account.isUnified && !mailbox.specialRole" icon="icon-delete" @click="deleteMailbox">
{{ t('mail', 'Delete folder') }}
</ActionButton>
<AppNavigationCounter v-if="mailbox.unread" slot="counter">
{{ mailbox.unread }}
<!-- submailboxes -->
<NavigationMailbox
v-for="subMailbox in subMailboxes"
:key="genId(subMailbox)"
</template>
<script>
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem'
import AppNavigationCounter from '@nextcloud/vue/dist/Components/AppNavigationCounter'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
import ActionInput from '@nextcloud/vue/dist/Components/ActionInput'
import ActionText from '@nextcloud/vue/dist/Components/ActionText'
import { clearCache } from '../service/MessageService'
import { getMailboxStatus } from '../service/MailboxService'
import logger from '../logger'
import { translatePlural as n } from '@nextcloud/l10n'
import { translate as translateMailboxName } from '../i18n/MailboxTranslator'
export default {
components: {
AppNavigationItem,
ActionButton,
ActionInput,
},
props: {
account: {
type: Object,
required: true,
},
type: Object,
required: true,
},
top: {
type: Boolean,
default: true,
},
filter: {
type: String,
default: '',
required: false,
},
data() {
return {
debug: window?.OC?.debug || false,
clearingCache: false,
visible() {
return (
this.account.showSubscribedOnly === false
|| (this.mailbox.attributes && this.mailbox.attributes.includes('\\subscribed'))
if (this.filter === 'starred') {
// Little hack to trick the translation logic into a different path
return translateMailboxName({
specialUse: ['flagged'],
})
}
if (this.filter === 'starred') {
return 'icon-flagged'
Jan-Christoph Borchardt
committed
return 'icon-important'
return this.mailbox.specialRole ? 'icon-' + this.mailbox.specialRole : 'icon-folder'
filter: this.filter ? this.filter : undefined,
subMailboxes() {
return this.$store.getters.getSubMailboxes(this.mailbox.databaseId)
if (this.mailboxStats && 'total' in this.mailboxStats && 'unread' in this.mailboxStats) {
if (this.mailboxStats.unread === 0) {
return n('mail', '{total} message', '{total} messages', this.mailboxStats.total, {
total: this.mailboxStats.total,
return n(
'mail',
'{unread} unread of {total}',
'{unread} unread of {total}',
total: this.mailboxStats.total,
unread: this.mailboxStats.unread,
},
},
methods: {
* Generate unique key id for a specific mailbox
* @param {Object} mailbox the mailbox to gen id for
genId(mailbox) {
return 'mailbox-' + mailbox.databaseId
/**
* On menu toggle, fetch stats
* @param {boolean} open menu opened state
*/
onMenuToggle(open) {
if (open) {
async fetchMailboxStats() {
this.mailboxStats = null
if (this.account.isUnified || this.mailbox.specialRole === 'flagged') {
const stats = await getMailboxStatus(this.mailbox.databaseId)
logger.debug(`loaded mailbox stats for ${this.mailbox.databaseId}`, { stats })
this.mailboxStats = stats
} catch (error) {
this.mailboxStats = { error: true }
logger.error(`could not load mailbox stats for ${this.mailbox.databaseId}`, error)
const withPrefix = atob(this.mailbox.databaseId) + this.mailbox.delimiter + name
logger.info(`creating mailbox ${withPrefix} as submailbox of ${this.mailbox.databaseId}`)
this.menuOpen = false
account: this.account,
name: withPrefix,
})
logger.error(`could not create mailbox ${withPrefix}`, { error })
throw error
} finally {
this.editing = false
this.showSaving = false
}
logger.info(`mailbox ${withPrefix} created`)
this.showSubMailboxes = true
this.loadingMarkAsRead = true
this.$store
.then(() => logger.info(`mailbox ${this.mailbox.databaseId} marked as read`))
.catch((error) => logger.error(`could not mark mailbox ${this.mailbox.databaseId} as read`, { error }))
.then(() => (this.loadingMarkAsRead = false))
async clearCache() {
try {
this.clearingCache = true
logger.debug('clearing message cache', {
accountId: this.account.id,
await clearCache(this.account.id, this.mailbox.databaseId)
// TODO: there might be a nicer way to handle this
window.location.reload(false)
} finally {
this.clearCache = false
}
},
deleteMailbox() {
const id = this.mailbox.databaseId
logger.info('delete mailbox', { mailbox: this.mailbox })
t('mail', 'The folder and all messages in it will be deleted.'),
t('mail', 'Delete folder'),
{
type: OC.dialogs.YES_NO_BUTTONS,
confirm: t('mail', 'Delete folder {name}', { name: this.mailbox.displayName }),
confirmClasses: 'error',
cancel: t('mail', 'Cancel'),
},
(result) => {
if (result) {
return this.$store
.dispatch('deleteMailbox', { mailbox: this.mailbox })
.catch((error) => logger.error('could not delete mailbox', { error }))
},
}
</script>