From 079f334bcc4b2ad26c184c85d0de0ee9be58f968 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 7 Dec 2022 17:36:04 +0100 Subject: [PATCH] Resolve #437 --- dev/Model/Account.js | 21 +++++++-- dev/Styles/User/SystemDropDown.less | 20 +++++++-- .../libraries/RainLoop/Actions/Accounts.php | 45 ++++++++++++------- .../templates/Views/User/SystemDropDown.html | 6 +-- 4 files changed, 64 insertions(+), 28 deletions(-) diff --git a/dev/Model/Account.js b/dev/Model/Account.js index 0c88bb8c1..9e220db1d 100644 --- a/dev/Model/Account.js +++ b/dev/Model/Account.js @@ -1,5 +1,6 @@ import { AbstractModel } from 'Knoin/AbstractModel'; import { addObservablesTo } from 'External/ko'; +import Remote from 'Remote/User/Fetch'; export class AccountModel extends AbstractModel { /** @@ -7,7 +8,7 @@ export class AccountModel extends AbstractModel { * @param {boolean=} canBeDelete = true * @param {number=} count = 0 */ - constructor(email, name/*, count = 0*/, isAdditional = true) { + constructor(email, name, isAdditional = true) { super(); this.name = name; @@ -16,17 +17,31 @@ export class AccountModel extends AbstractModel { this.displayName = name ? name + ' <' + email + '>' : email; addObservablesTo(this, { -// count: count || 0, + unreadEmails: null, askDelete: false, isAdditional: isAdditional }); + + // Load at random between 3 and 30 seconds + setTimeout(()=>this.fetchUnread(), (Math.ceil(Math.random() * 10)) * 3000); + } + + /** + * Get INBOX unread messages + */ + fetchUnread() { + Remote.request('AccountUnread', (iError, oData) => { + iError || this.unreadEmails(oData?.Result?.unreadEmails || null); + }, { + email: this.email + }); } /** * Imports all mail to main account *//* importAll(account) { - rl.app.Remote.streamPerLine(line => { + Remote.streamPerLine(line => { try { line = JSON.parse(line); console.dir(line); diff --git a/dev/Styles/User/SystemDropDown.less b/dev/Styles/User/SystemDropDown.less index 406df8f48..f15a81d02 100644 --- a/dev/Styles/User/SystemDropDown.less +++ b/dev/Styles/User/SystemDropDown.less @@ -69,13 +69,25 @@ white-space: nowrap; } - .counter { - display: inline-block; - } - .dropdown-menu a.account-item { padding-right: 5px; } + + span[data-unread]::after { + content: attr(data-unread); + background-color: var(--unread-count-bg-color, #999); + border-radius: 1em; + color: var(--unread-count-color, #fff); + font-size: 11px; + line-height: 1.5em; + min-width: 1.7em; + padding: 1px 4px; + text-align: center; + text-shadow: 0 -1px 0 rgba(0,0,0,.25); + position: absolute; + right: 3px; + } + } @keyframes equaliserBar { diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php index a57d7dcf2..411f0572b 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php @@ -110,37 +110,50 @@ trait Accounts return $this->TrueResponse(__FUNCTION__); } - /** - * Imports all mail from AdditionalAccount into MainAccount - */ - public function DoAccountImport(): array + protected function loadAdditionalAccountImapClient(string $sEmail): \MailSo\Imap\ImapClient { - $sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($this->GetActionParam('email', '')), true); + $sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true); if (!\strlen($sEmail)) { throw new ClientException(Notifications::AccountDoesNotExist); } $oMainAccount = $this->getMainAccountFromToken(); - $oLogger = $this->Logger(); - $aAccounts = $this->GetAccounts($oMainAccount); if (!isset($aAccounts[$sEmail])) { throw new ClientException(Notifications::AccountDoesNotExist); } - $oAccount = AdditionalAccount::NewInstanceFromTokenArray( - $this, $aAccounts[$sEmail] - ); + $oAccount = AdditionalAccount::NewInstanceFromTokenArray($this, $aAccounts[$sEmail]); if (!$oAccount) { throw new ClientException(Notifications::AccountDoesNotExist); } - $oImapTarget = new \MailSo\Imap\ImapClient; - $oImapTarget->SetLogger($oLogger); - $this->imapConnect($oMainAccount, false, $oImapTarget); + $oImapClient = new \MailSo\Imap\ImapClient; + $oImapClient->SetLogger($this->Logger()); + $this->imapConnect($oAccount, false, $oImapClient); + return $oImapClient; + } - $oImapSource = new \MailSo\Imap\ImapClient; - $oImapSource->SetLogger($oLogger); - $this->imapConnect($oAccount, false, $oImapSource); + public function DoAccountUnread(): array + { + $oImapClient = $this->loadAdditionalAccountImapClient($this->GetActionParam('email', '')); + $oInfo = $oImapClient->FolderStatus('INBOX'); + return $this->DefaultResponse(__FUNCTION__, [ + 'unreadEmails' => \max(0, $oInfo->UNSEEN) + ]); + } + + /** + * Imports all mail from AdditionalAccount into MainAccount + */ + public function DoAccountImport(): array + { + $sEmail = $this->GetActionParam('email', ''); + $oImapSource = $this->loadAdditionalAccountImapClient($sEmail); + + $oMainAccount = $this->getMainAccountFromToken(); + $oImapTarget = new \MailSo\Imap\ImapClient; + $oImapTarget->SetLogger($this->Logger()); + $this->imapConnect($oMainAccount, false, $oImapTarget); $oSync = new \SnappyMail\Imap\Sync; $oSync->oImapSource = $oImapSource; diff --git a/snappymail/v/0.0.0/app/templates/Views/User/SystemDropDown.html b/snappymail/v/0.0.0/app/templates/Views/User/SystemDropDown.html index 6be176e63..8f81d6b4e 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/SystemDropDown.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/SystemDropDown.html @@ -19,12 +19,8 @@
  • - - +