mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-06 05:04:24 +08:00
Improve folderInformation and folderInformationMultiply
This commit is contained in:
parent
a3dc8ad639
commit
26015aaf18
3 changed files with 41 additions and 59 deletions
|
@ -536,59 +536,46 @@ class AppUser extends AbstractApp {
|
|||
if (folder && folder.trim()) {
|
||||
Remote.folderInformation(
|
||||
(iError, data) => {
|
||||
if (!iError && data.Result.Hash && data.Result.Folder) {
|
||||
let check = false,
|
||||
unreadCountChange = false;
|
||||
|
||||
const folderFromCache = getFolderFromCacheList(data.Result.Folder);
|
||||
if (!iError && data.Result) {
|
||||
const result = data.Result,
|
||||
hash = getFolderHash(result.Folder),
|
||||
folderFromCache = getFolderFromCacheList(result.Folder);
|
||||
if (folderFromCache) {
|
||||
folderFromCache.expires = Date.now();
|
||||
|
||||
if (data.Result.Hash) {
|
||||
setFolderHash(data.Result.Folder, data.Result.Hash);
|
||||
}
|
||||
setFolderHash(result.Folder, result.Hash);
|
||||
|
||||
if (null != data.Result.MessageCount) {
|
||||
folderFromCache.messageCountAll(data.Result.MessageCount);
|
||||
}
|
||||
folderFromCache.messageCountAll(result.MessageCount);
|
||||
|
||||
if (null != data.Result.MessageUnseenCount) {
|
||||
if (pInt(folderFromCache.messageCountUnread()) !== pInt(data.Result.MessageUnseenCount)) {
|
||||
unreadCountChange = true;
|
||||
}
|
||||
let unreadCountChange = (folderFromCache.messageCountUnread() !== result.MessageUnseenCount);
|
||||
|
||||
folderFromCache.messageCountUnread(data.Result.MessageUnseenCount);
|
||||
}
|
||||
folderFromCache.messageCountUnread(result.MessageUnseenCount);
|
||||
|
||||
if (unreadCountChange) {
|
||||
MessageFlagsCache.clearFolder(folderFromCache.fullNameRaw);
|
||||
}
|
||||
|
||||
if (data.Result.Flags) {
|
||||
Object.entries(data.Result.Flags).forEach(([uid,flags]) => {
|
||||
check = true;
|
||||
MessageFlagsCache.storeByFolderAndUid(folderFromCache.fullNameRaw, uid.toString(), [
|
||||
if (result.Flags.length) {
|
||||
result.Flags.forEach(flags =>
|
||||
MessageFlagsCache.storeByFolderAndUid(folderFromCache.fullNameRaw, flags.Uid.toString(), [
|
||||
!!flags.IsUnseen,
|
||||
!!flags.IsFlagged,
|
||||
!!flags.IsAnswered,
|
||||
!!flags.IsForwarded,
|
||||
!!flags.IsReadReceipt
|
||||
]);
|
||||
});
|
||||
])
|
||||
);
|
||||
|
||||
if (check) {
|
||||
this.reloadFlagsCurrentMessageListAndMessageFromCache();
|
||||
}
|
||||
this.reloadFlagsCurrentMessageListAndMessageFromCache();
|
||||
}
|
||||
|
||||
MessageUserStore.initUidNextAndNewMessages(
|
||||
folderFromCache.fullNameRaw,
|
||||
data.Result.UidNext,
|
||||
data.Result.NewMessages
|
||||
result.UidNext,
|
||||
result.NewMessages
|
||||
);
|
||||
|
||||
const hash = getFolderHash(data.Result.Folder);
|
||||
if (!hash || unreadCountChange || data.Result.Hash !== hash) {
|
||||
if (!hash || unreadCountChange || result.Hash !== hash) {
|
||||
if (folderFromCache.fullNameRaw === FolderUserStore.currentFolderFullNameRaw()) {
|
||||
this.reloadMessageList();
|
||||
} else if (getFolderInboxName() === folderFromCache.fullNameRaw) {
|
||||
|
@ -616,26 +603,17 @@ class AppUser extends AbstractApp {
|
|||
oData.Result.List.forEach(item => {
|
||||
const hash = getFolderHash(item.Folder),
|
||||
folder = getFolderFromCacheList(item.Folder);
|
||||
let unreadCountChange = false;
|
||||
|
||||
if (folder) {
|
||||
folder.expires = utc;
|
||||
|
||||
if (item.Hash) {
|
||||
setFolderHash(item.Folder, item.Hash);
|
||||
}
|
||||
setFolderHash(item.Folder, item.Hash);
|
||||
|
||||
if (null != item.MessageCount) {
|
||||
folder.messageCountAll(item.MessageCount);
|
||||
}
|
||||
folder.messageCountAll(item.MessageCount);
|
||||
|
||||
if (null != item.MessageUnseenCount) {
|
||||
if (pInt(folder.messageCountUnread()) !== pInt(item.MessageUnseenCount)) {
|
||||
unreadCountChange = true;
|
||||
}
|
||||
let unreadCountChange = folder.messageCountUnread() !== item.MessageUnseenCount;
|
||||
|
||||
folder.messageCountUnread(item.MessageUnseenCount);
|
||||
}
|
||||
folder.messageCountUnread(item.MessageUnseenCount);
|
||||
|
||||
if (unreadCountChange) {
|
||||
MessageFlagsCache.clearFolder(folder.fullNameRaw);
|
||||
|
|
|
@ -705,7 +705,7 @@ class MailClient
|
|||
'Hash' => $this->GenerateFolderHash($sFolderName, $iCount, $iUnseenCount, $sUidNext, $sHighestModSeq),
|
||||
'MessageCount' => $iCount,
|
||||
'MessageUnseenCount' => $iUnseenCount,
|
||||
'UidNext' => $sUidNext,
|
||||
'UidNext' => (int) $sUidNext,
|
||||
'Flags' => $aFlags,
|
||||
'HighestModSeq' => $sHighestModSeq,
|
||||
'NewMessages' => 'INBOX' === $sFolderName && \MailSo\Config::$CheckNewMessages ?
|
||||
|
|
|
@ -357,22 +357,21 @@ trait Folders
|
|||
$sFolder, $sPrevUidNext, $aFlagsFilteredUids
|
||||
);
|
||||
|
||||
if (isset($aInboxInformation['Flags']) && \is_array($aInboxInformation['Flags']))
|
||||
foreach ($aInboxInformation['Flags'] as $iUid => $aFlags)
|
||||
{
|
||||
foreach ($aInboxInformation['Flags'] as $iUid => $aFlags)
|
||||
{
|
||||
$aLowerFlags = array_map('strtolower', $aFlags);
|
||||
$aInboxInformation['Flags'][$iUid] = array(
|
||||
'IsUnseen' => \in_array('\\unseen', $aLowerFlags) || !\in_array('\\seen', $aLowerFlags),
|
||||
'IsSeen' => in_array('\\seen', $aLowerFlags),
|
||||
'IsFlagged' => in_array('\\flagged', $aLowerFlags),
|
||||
'IsAnswered' => in_array('\\answered', $aLowerFlags),
|
||||
'IsDeleted' => in_array('\\deleted', $aLowerFlags),
|
||||
'IsForwarded' => 0 < strlen($sForwardedFlag) && in_array(strtolower($sForwardedFlag), $aLowerFlags),
|
||||
'IsReadReceipt' => 0 < strlen($sReadReceiptFlag) && in_array(strtolower($sReadReceiptFlag), $aLowerFlags)
|
||||
);
|
||||
}
|
||||
$aLowerFlags = \array_map('strtolower', $aFlags);
|
||||
$aInboxInformation['Flags'][$iUid] = array(
|
||||
'Uid' => $iUid,
|
||||
'IsUnseen' => \in_array('\\unseen', $aLowerFlags) || !\in_array('\\seen', $aLowerFlags),
|
||||
'IsSeen' => \in_array('\\seen', $aLowerFlags),
|
||||
'IsFlagged' => \in_array('\\flagged', $aLowerFlags),
|
||||
'IsAnswered' => \in_array('\\answered', $aLowerFlags),
|
||||
'IsDeleted' => \in_array('\\deleted', $aLowerFlags),
|
||||
'IsForwarded' => $sForwardedFlag && \in_array(\strtolower($sForwardedFlag), $aLowerFlags),
|
||||
'IsReadReceipt' => $sReadReceiptFlag && \in_array(\strtolower($sReadReceiptFlag), $aLowerFlags)
|
||||
);
|
||||
}
|
||||
$aInboxInformation['Flags'] = \array_values($aInboxInformation['Flags']);
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
|
@ -409,7 +408,12 @@ trait Folders
|
|||
$aInboxInformation = $this->MailClient()->FolderInformation($sFolder, '', array());
|
||||
if (isset($aInboxInformation['Folder']))
|
||||
{
|
||||
$aResult['List'][] = $aInboxInformation;
|
||||
$aResult['List'][] = [
|
||||
'Folder' => $aInboxInformation['Folder'],
|
||||
'Hash' => $aInboxInformation['Hash'],
|
||||
'MessageCount' => $aInboxInformation['MessageCount'],
|
||||
'MessageUnseenCount' => $aInboxInformation['MessageUnseenCount'],
|
||||
];
|
||||
}
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
|
|
Loading…
Add table
Reference in a new issue