Skip to content

Commit 4daefc3

Browse files
committed
feat: manually refresh folder list
Signed-off-by: Hamza <[email protected]>
1 parent 49bff1d commit 4daefc3

File tree

7 files changed

+23
-8
lines changed

7 files changed

+23
-8
lines changed

lib/Contracts/IMailManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ public function getMailbox(string $uid, int $id): Mailbox;
3535

3636
/**
3737
* @param Account $account
38+
* @param bool $forceSync
3839
*
3940
* @return Mailbox[]
4041
*
4142
* @throws ServiceException
4243
*/
43-
public function getMailboxes(Account $account): array;
44+
public function getMailboxes(Account $account, bool $forceSync = false): array;
4445

4546
/**
4647
* @param Account $account

lib/Controller/MailboxesController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,18 @@ public function __construct(
6161
* @NoAdminRequired
6262
*
6363
* @param int $accountId
64+
* @param bool $forceSync
6465
*
6566
* @return JSONResponse
6667
*
6768
* @throws ClientException
6869
* @throws ServiceException
6970
*/
7071
#[TrapError]
71-
public function index(int $accountId): JSONResponse {
72+
public function index(int $accountId, bool $forceSync = false): JSONResponse {
7273
$account = $this->accountService->find($this->currentUserId, $accountId);
7374

74-
$mailboxes = $this->mailManager->getMailboxes($account);
75+
$mailboxes = $this->mailManager->getMailboxes($account, $forceSync);
7576
return new JSONResponse([
7677
'id' => $accountId,
7778
'email' => $account->getEmail(),

lib/Service/MailManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ public function getMailbox(string $uid, int $id): Mailbox {
130130

131131
/**
132132
* @param Account $account
133+
* @param bool $forceSync
133134
*
134135
* @return Mailbox[]
135136
* @throws ServiceException
136137
*/
137138
#[\Override]
138-
public function getMailboxes(Account $account): array {
139-
$this->mailboxSync->sync($account, $this->logger);
139+
public function getMailboxes(Account $account, bool $forceSync = false): array {
140+
$this->mailboxSync->sync($account, $this->logger, $forceSync);
140141

141142
return $this->mailboxMapper->findAll($account);
142143
}

src/components/AppSettingsMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
<List
113113
:text-blocks="getMyTextBlocks()"
114114
@show-toolbar="handleShowToolbar" />
115-
<NcButton variant="secondary" @click="() => textBlockDialogOpen = true" wide>
115+
<NcButton variant="secondary" wide @click="() => textBlockDialogOpen = true">
116116
{{ t('mail', 'New text block') }}
117117
</NcButton>
118118
<template v-if="getSharedTextBlocks().length > 0">

src/components/NewMessageButtonHeader.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export default {
7272
}
7373
return undefined
7474
},
75+
76+
account() {
77+
return this.mainStore.getAccount(this.currentMailbox.accountId)
78+
},
7579
},
7680
7781
methods: {
@@ -83,6 +87,7 @@ export default {
8387
this.refreshing = true
8488
try {
8589
await this.mainStore.syncEnvelopes({ mailboxId: this.currentMailbox.databaseId })
90+
await this.mainStore.syncMailboxesForAccount(this.account)
8691
logger.debug('Current folder is sync\'ing ')
8792
} catch (error) {
8893
logger.error('could not sync current folder', { error })

src/service/MailboxService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import axios from '@nextcloud/axios'
66
import { generateUrl } from '@nextcloud/router'
77

8-
export async function fetchAll(accountId) {
9-
const url = generateUrl('/apps/mail/api/mailboxes?accountId={accountId}', {
8+
export async function fetchAll(accountId, forceSync = false) {
9+
const url = generateUrl(`/apps/mail/api/mailboxes?accountId={accountId}&forceSync=${forceSync}`, {
1010
accountId,
1111
})
1212

src/store/mainStore/actions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ export default function mainStoreActions() {
219219
logger.debug(`account ${account.id} created`, { account })
220220
return account
221221
},
222+
async syncMailboxesForAccount(account) {
223+
logger.debug(`Fetching mailboxes for account ${account.id}, …`, { account })
224+
account.mailboxes = await fetchAllMailboxes(account.id, true)
225+
const mailboxes = sortMailboxes(account.mailboxes || [], account)
226+
Vue.set(account, 'mailboxes', [])
227+
mailboxes.map(addMailboxToState(this.mailboxes, account))
228+
},
222229
async finishAccountSetup({ account }) {
223230
logger.debug(`Fetching mailboxes for account ${account.id}, …`, { account })
224231
account.mailboxes = await fetchAllMailboxes(account.id)

0 commit comments

Comments
 (0)