Merge quota requests into folders request

This commit is contained in:
djmaze 2021-11-01 16:26:07 +01:00
parent 20eb01de08
commit 8d3bcdc2f2
9 changed files with 45 additions and 51 deletions

View file

@ -1,7 +1,7 @@
import 'External/User/ko';
import { isArray, arrayLength, pInt, pString, forEachObjectValue } from 'Common/Utils';
import { isPosNumeric, delegateRunOnDestroy, mailToHelper } from 'Common/UtilsUser';
import { isArray, arrayLength, pString, forEachObjectValue } from 'Common/Utils';
import { delegateRunOnDestroy, mailToHelper } from 'Common/UtilsUser';
import {
Capa,
@ -54,7 +54,6 @@ import { IdentityUserStore } from 'Stores/User/Identity';
import { FolderUserStore } from 'Stores/User/Folder';
import { PgpUserStore } from 'Stores/User/Pgp';
import { MessageUserStore } from 'Stores/User/Message';
import { QuotaUserStore } from 'Stores/User/Quota';
import { ThemeStore } from 'Stores/Theme';
import * as Local from 'Storage/Client';
@ -89,7 +88,6 @@ class AppUser extends AbstractApp {
this.moveCache = {};
this.quotaDebounce = this.quota.debounce(30000);
this.moveOrDeleteResponseHelper = this.moveOrDeleteResponseHelper.bind(this);
this.messagesMoveTrigger = this.messagesMoveTrigger.debounce(500);
@ -468,19 +466,6 @@ class AppUser extends AbstractApp {
});
}
quota() {
Remote.quota((iError, data) => {
if (
!iError &&
1 < arrayLength(data.Result) &&
isPosNumeric(data.Result[0]) &&
isPosNumeric(data.Result[1])
) {
QuotaUserStore.populateData(pInt(data.Result[1]), pInt(data.Result[0]));
}
});
}
/**
* @param {string} folder
* @param {Array=} list = []
@ -844,7 +829,7 @@ class AppUser extends AbstractApp {
}, refreshFolders);
// Every 15 minutes
setInterval(()=>this.quota() | this.foldersReload(), 900000);
setInterval(()=>this.foldersReload(), 900000);
ContactUserStore.init();
@ -855,7 +840,6 @@ class AppUser extends AbstractApp {
if (getFolderInboxName() !== cF) {
this.folderInformation(cF);
}
this.quota();
FolderUserStore.listStatusSupported() || this.folderInformationMultiply(true);
}, 1000);

View file

@ -149,6 +149,8 @@ export class FolderCollectionModel extends AbstractCollectionModel
FolderUserStore.sortSupported(!!this.IsSortSupported);
FolderUserStore.metadataSupported(!!this.IsMetadataSupported);
FolderUserStore.listStatusSupported(!!this.IsListStatusSupported);
FolderUserStore.quotaUsage(this.quotaUsage);
FolderUserStore.quotaLimit(this.quotaLimit);
FolderUserStore.sentFolder(normalizeFolder(SettingsGet('SentFolder')));
FolderUserStore.draftFolder(normalizeFolder(SettingsGet('DraftFolder')));

View file

@ -27,6 +27,9 @@ export const FolderUserStore = new class {
listStatusSupported: false,
// sortMode: '',
quotaLimit: 0,
quotaUsage: 0,
sentFolder: '',
draftFolder: '',
spamFolder: '',
@ -103,6 +106,11 @@ export const FolderUserStore = new class {
trashFolder: fSetSystemFolderType(FolderType.Trash),
archiveFolder: fSetSystemFolderType(FolderType.Archive)
});
this.quotaPercentage = ko.computed(() => {
const quota = this.quotaLimit(), usage = this.quotaUsage();
return 0 < quota ? Math.ceil((usage / quota) * 100) : 0;
});
}
/**

View file

@ -1,24 +0,0 @@
import ko from 'ko';
export const QuotaUserStore = new class {
constructor() {
this.quota = ko.observable(0);
this.usage = ko.observable(0);
this.percentage = ko.computed(() => {
const quota = this.quota(),
usage = this.usage();
return 0 < quota ? Math.ceil((usage / quota) * 100) : 0;
});
}
/**
* @param {number} quota
* @param {number} usage
*/
populateData(quota, usage) {
this.quota(quota * 1024);
this.usage(usage * 1024);
}
};

View file

@ -31,7 +31,6 @@ import {
} from 'Common/Cache';
import { AppUserStore } from 'Stores/User/App';
import { QuotaUserStore } from 'Stores/User/Quota';
import { SettingsUserStore } from 'Stores/User/Settings';
import { FolderUserStore } from 'Stores/User/Folder';
import { MessageUserStore } from 'Stores/User/Message';
@ -84,7 +83,7 @@ export class MailMessageList extends AbstractViewRight {
initOnStartOrLangChange(() => this.emptySubjectValue = i18n('MESSAGE_LIST/EMPTY_SUBJECT_TEXT'));
this.userUsageProc = QuotaUserStore.percentage;
this.userUsageProc = FolderUserStore.quotaPercentage;
this.addObservables({
moveDropdownTrigger: false,
@ -908,9 +907,9 @@ export class MailMessageList extends AbstractViewRight {
quotaTooltip() {
return i18n('MESSAGE_LIST/QUOTA_SIZE', {
SIZE: FileInfo.friendlySize(QuotaUserStore.usage()),
PROC: QuotaUserStore.percentage(),
LIMIT: FileInfo.friendlySize(QuotaUserStore.quota())
SIZE: FileInfo.friendlySize(FolderUserStore.quotaUsage()),
PROC: FolderUserStore.quotaPercentage(),
LIMIT: FileInfo.friendlySize(FolderUserStore.quotaLimit())
}).replace(/<[^>]+>/g, '');
}
}

View file

@ -743,7 +743,7 @@ class ImapClient extends \MailSo\Net\NetClient
*
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
* /
*/
public function Quota(string $sRootName = '') : ?array
{
if ($this->IsSupported('QUOTA'))
@ -753,7 +753,6 @@ class ImapClient extends \MailSo\Net\NetClient
return null;
}
*/
/**
* https://datatracker.ietf.org/doc/html/rfc2087#section-4.3

View file

@ -57,6 +57,9 @@ class FolderCollection extends \MailSo\Base\Collection
*/
public $SystemFolders = array();
public $quotaUsage = 0;
public $quotaLimit = 0;
public function append($oFolder, bool $bToTop = false) : void
{
assert($oFolder instanceof Folder);
@ -149,6 +152,8 @@ class FolderCollection extends \MailSo\Base\Collection
'IsThreadsSupported' => $this->IsThreadsSupported,
'IsSortSupported' => $this->IsSortSupported,
'IsListStatusSupported' => $this->IsListStatusSupported,
'quotaUsage' => $this->quotaUsage,
'quotaLimit' => $this->quotaLimit,
'Optimized' => $this->Optimized,
'CountRec' => $this->CountRec(),
'SystemFolders' => empty($this->SystemFolders) ? null : $this->SystemFolders

View file

@ -1771,6 +1771,11 @@ class MailClient
return $oMessageCollection;
}
public function Quota(string $sRootName = '') : ?array
{
return $this->oImapClient->Quota($sRootName);
}
public function QuotaRoot(string $sFolderName = 'INBOX') : ?array
{
return $this->oImapClient->QuotaRoot($sFolderName);

View file

@ -12,11 +12,27 @@ trait Folders
private function getFolderCollection(bool $HideUnsubscribed) : ?\MailSo\Mail\FolderCollection
{
return $this->MailClient()->Folders('', '*',
$oFolderCollection = $this->MailClient()->Folders('', '*',
$HideUnsubscribed,
(int) $this->Config()->Get('labs', 'imap_folder_list_limit', 200),
(bool) $this->Config()->Get('labs', 'imap_use_list_status', true)
);
if ($oFolderCollection) {
$oAccount = $this->getAccountFromToken();
if ($this->GetCapa(false, Capa::QUOTA, $oAccount)) {
try {
$aQuota = $this->MailClient()->Quota();
// $aQuota = $this->MailClient()->QuotaRoot();
$oFolderCollection->quotaUsage = $aQuota[0] * 1024;
$oFolderCollection->quotaLimit = $aQuota[1] * 1024;
} catch (\Throwable $oException) {
// ignore
}
}
}
return $oFolderCollection;
}
public function DoFolders() : array