diff --git a/dev/App/User.js b/dev/App/User.js index 960850a83..a653f469b 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -24,8 +24,6 @@ import { UNUSED_OPTION_VALUE } from 'Common/Consts'; import { MessageFlagsCache, - setFolderHash, - getFolderHash, getFolderInboxName, getFolderFromCacheList } from 'Common/Cache'; @@ -222,17 +220,16 @@ export class AppUser extends AbstractApp { (iError, data) => { if (!iError && data.Result) { const result = data.Result, - hash = getFolderHash(result.Folder), folderFromCache = getFolderFromCacheList(result.Folder); if (folderFromCache) { + const oldHash = folderFromCache.hash, + unreadCountChange = (folderFromCache.unreadEmails() !== result.unreadEmails); + +// folderFromCache.revivePropertiesFromJson(result); folderFromCache.expires = Date.now(); - - setFolderHash(result.Folder, result.Hash); - + folderFromCache.uidNext = result.UidNext; + folderFromCache.hash = result.Hash; folderFromCache.totalEmails(result.totalEmails); - - let unreadCountChange = (folderFromCache.unreadEmails() !== result.unreadEmails); - folderFromCache.unreadEmails(result.unreadEmails); if (unreadCountChange) { @@ -247,13 +244,9 @@ export class AppUser extends AbstractApp { MessagelistUserStore.reloadFlagsAndCachedMessage(); } - MessagelistUserStore.initUidNextAndNewMessages( - folderFromCache.fullName, - result.UidNext, - result.NewMessages - ); + MessagelistUserStore.notifyNewMessages(folderFromCache.fullName, result.NewMessages); - if (!hash || unreadCountChange || result.Hash !== hash) { + if (!oldHash || unreadCountChange || result.Hash !== oldHash) { if (folderFromCache.fullName === FolderUserStore.currentFolderFullName()) { MessagelistUserStore.reload(); } else if (getFolderInboxName() === folderFromCache.fullName) { diff --git a/dev/Common/Cache.js b/dev/Common/Cache.js index 280450812..45bf56f48 100644 --- a/dev/Common/Cache.js +++ b/dev/Common/Cache.js @@ -4,7 +4,6 @@ import { isArray } from 'Common/Utils'; let FOLDERS_CACHE = {}, FOLDERS_NAME_CACHE = {}, MESSAGE_FLAGS_CACHE = {}, - NEW_MESSAGE_CACHE = {}, REQUESTED_MESSAGE_CACHE = {}, inboxFolderName = 'INBOX'; @@ -16,7 +15,6 @@ export const FOLDERS_CACHE = {}; FOLDERS_NAME_CACHE = {}; MESSAGE_FLAGS_CACHE = {}; - NEW_MESSAGE_CACHE = {}; REQUESTED_MESSAGE_CACHE = {}; }, @@ -40,29 +38,6 @@ export const */ hasRequestedMessage = (folder, uid) => true === REQUESTED_MESSAGE_CACHE[getMessageKey(folder, uid)], - /** - * @param {string} folderFullName - * @param {string} uid - */ - addNewMessageCache = (folderFullName, uid) => NEW_MESSAGE_CACHE[getMessageKey(folderFullName, uid)] = true, - - /** - * @param {string} folderFullName - * @param {string} uid - */ - hasNewMessageAndRemoveFromCache = (folderFullName, uid) => { - if (NEW_MESSAGE_CACHE[getMessageKey(folderFullName, uid)]) { - NEW_MESSAGE_CACHE[getMessageKey(folderFullName, uid)] = null; - return true; - } - return false; - }, - - /** - * @returns {void} - */ - clearNewMessageCache = () => NEW_MESSAGE_CACHE = {}, - /** * @returns {string} */ @@ -91,13 +66,6 @@ export const FOLDERS_NAME_CACHE[folder.fullNameHash] = folder.fullName; }, - /** - * @param {string} folderFullName - * @returns {string} - */ - getFolderHash = folderFullName => - FOLDERS_CACHE[folderFullName] ? FOLDERS_CACHE[folderFullName].hash : '', - /** * @param {string} folderFullName * @param {string} folderHash @@ -105,20 +73,6 @@ export const setFolderHash = (folderFullName, folderHash) => FOLDERS_CACHE[folderFullName] && (FOLDERS_CACHE[folderFullName].hash = folderHash), - /** - * @param {string} folderFullName - * @returns {string} - */ - getFolderUidNext = folderFullName => - FOLDERS_CACHE[folderFullName] ? FOLDERS_CACHE[folderFullName].uidNext : 0, - - /** - * @param {string} folderFullName - * @param {string} uidNext - */ - setFolderUidNext = (folderFullName, uidNext) => - FOLDERS_CACHE[folderFullName] && (FOLDERS_CACHE[folderFullName].uidNext = uidNext), - /** * @param {string} folderFullName * @returns {?FolderModel} diff --git a/dev/Common/Folders.js b/dev/Common/Folders.js index 7ca52a6cd..85eff9d29 100644 --- a/dev/Common/Folders.js +++ b/dev/Common/Folders.js @@ -2,10 +2,8 @@ import { isArray, arrayLength } from 'Common/Utils'; import { MessageFlagsCache, setFolderHash, - getFolderHash, getFolderInboxName, - getFolderFromCacheList, - getFolderUidNext + getFolderFromCacheList } from 'Common/Cache'; import { SettingsUserStore } from 'Stores/User/Settings'; import { FolderUserStore } from 'Stores/User/Folder'; @@ -34,7 +32,8 @@ sortFolders = folders => { */ fetchFolderInformation = (fCallback, folder, list = []) => { let fetch = !arrayLength(list); - const uids = []; + const uids = [], + folderFromCache = getFolderFromCacheList(folder); if (!fetch) { list.forEach(messageListItem => { @@ -57,7 +56,7 @@ fetchFolderInformation = (fCallback, folder, list = []) => { Remote.request('FolderInformation', fCallback, { Folder: folder, FlagsUids: uids, - UidNext: getFolderUidNext(folder) // Used to check for new messages + UidNext: (folderFromCache && folderFromCache.uidNext) || 0 // Used to check for new messages }); } else if (SettingsUserStore.useThreads()) { MessagelistUserStore.reloadFlagsAndCachedMessage(); @@ -140,25 +139,23 @@ folderInformationMultiply = (boot = false) => { if (!iError && arrayLength(oData.Result)) { const utc = Date.now(); oData.Result.forEach(item => { - const hash = getFolderHash(item.Folder), - folder = getFolderFromCacheList(item.Folder); + const folder = getFolderFromCacheList(item.Folder); if (folder) { + const oldHash = folder.hash, + unreadCountChange = folder.unreadEmails() !== item.unreadEmails; + +// folder.revivePropertiesFromJson(item); folder.expires = utc; - - setFolderHash(item.Folder, item.Hash); - + folder.hash = item.Hash; folder.totalEmails(item.totalEmails); - - let unreadCountChange = folder.unreadEmails() !== item.unreadEmails; - folder.unreadEmails(item.unreadEmails); if (unreadCountChange) { MessageFlagsCache.clearFolder(folder.fullName); } - if (!hash || item.Hash !== hash) { + if (!oldHash || item.Hash !== oldHash) { if (folder.fullName === FolderUserStore.currentFolderFullName()) { MessagelistUserStore.reload(); } diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index 48914fbf7..af05d3e2f 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -3,7 +3,7 @@ import { AbstractCollectionModel } from 'Model/AbstractCollection'; import { UNUSED_OPTION_VALUE } from 'Common/Consts'; import { isArray, getKeyByValue, forEachObjectEntry, b64EncodeJSONSafe } from 'Common/Utils'; import { ClientSideKeyNameExpandedFolders, FolderType, FolderMetadataKeys } from 'Common/EnumsUser'; -import { getFolderFromCacheList, setFolder, setFolderInboxName, setFolderHash } from 'Common/Cache'; +import { getFolderFromCacheList, setFolder, setFolderInboxName } from 'Common/Cache'; import { Settings, SettingsGet, fireEvent } from 'Common/Globals'; import * as Local from 'Storage/Client'; @@ -138,13 +138,24 @@ export class FolderCollectionModel extends AbstractCollectionModel let oCacheFolder = getFolderFromCacheList(oFolder.FullName), type = FolderType[getKeyByValue(SystemFolders, oFolder.FullName)]; - if (!oCacheFolder) { + if (oCacheFolder) { +// oCacheFolder.revivePropertiesFromJson(oFolder); + if (oFolder.Hash) { + oCacheFolder.hash = oFolder.Hash; + } + if (null != oFolder.totalEmails) { + oCacheFolder.totalEmails(oFolder.totalEmails); + } + if (null != oFolder.unreadEmails) { + oCacheFolder.unreadEmails(oFolder.unreadEmails); + } + } else { oCacheFolder = FolderModel.reviveFromJson(oFolder); if (!oCacheFolder) return null; if (1 == type) { - oCacheFolder.type(FolderType.Inbox); + oCacheFolder.type(type); setFolderInboxName(oFolder.FullName); } setFolder(oCacheFolder); @@ -158,18 +169,6 @@ export class FolderCollectionModel extends AbstractCollectionModel || !isArray(expandedFolders) || !expandedFolders.includes(oCacheFolder.fullName)); - if (oFolder.Hash) { - setFolderHash(oCacheFolder.fullName, oFolder.Hash); - } - - if (null != oFolder.totalEmails) { - oCacheFolder.totalEmails(oFolder.totalEmails); - } - - if (null != oFolder.unreadEmails) { - oCacheFolder.unreadEmails(oFolder.unreadEmails); - } - return oCacheFolder; }); @@ -240,8 +239,9 @@ export class FolderModel extends AbstractModel { this.exists = true; -// this.hash = ''; -// this.uidNext = 0; + this.hash = ''; +// this.id = null; + this.uidNext = null; this.addObservables({ name: '', diff --git a/dev/Model/MessageCollection.js b/dev/Model/MessageCollection.js index 8f05bc0a4..e7830516a 100644 --- a/dev/Model/MessageCollection.js +++ b/dev/Model/MessageCollection.js @@ -2,8 +2,7 @@ import { AbstractCollectionModel } from 'Model/AbstractCollection'; import { MessageModel } from 'Model/Message'; import { - MessageFlagsCache, - hasNewMessageAndRemoveFromCache + MessageFlagsCache } from 'Common/Cache'; 'use strict'; @@ -34,16 +33,10 @@ export class MessageCollectionModel extends AbstractCollectionModel * @returns {MessageCollectionModel} */ static reviveFromJson(object, cached) { - let newCount = 0; return super.reviveFromJson(object, message => { message = MessageModel.reviveFromJson(message); if (message) { - if (hasNewMessageAndRemoveFromCache(message.folder, message.uid) && 5 >= newCount) { - ++newCount; - } - message.deleted(false); - cached ? MessageFlagsCache.initMessage(message) : MessageFlagsCache.store(message); return message; } diff --git a/dev/Remote/User/Fetch.js b/dev/Remote/User/Fetch.js index 32366fd04..c99ccbb9a 100644 --- a/dev/Remote/User/Fetch.js +++ b/dev/Remote/User/Fetch.js @@ -1,8 +1,6 @@ import { pString, pInt, b64EncodeJSONSafe } from 'Common/Utils'; import { - getFolderHash, - getFolderUidNext, getFolderFromCacheList } from 'Common/Cache'; @@ -25,13 +23,14 @@ class RemoteUserFetch extends AbstractFetchRemote { messageList(fCallback, params, bSilent = false) { const sFolderFullName = pString(params.Folder), - folderHash = getFolderHash(sFolderFullName); + folder = getFolderFromCacheList(sFolderFullName), + folderHash = (folder && folder.hash) || ''; params = Object.assign({ Offset: 0, Limit: SettingsUserStore.messagesPerPage(), Search: '', - UidNext: getFolderUidNext(sFolderFullName), // Used to check for new messages + UidNext: (folder && folder.uidNext) || 0, // Used to check for new messages Sort: FolderUserStore.sortMode(), Hash: folderHash + SettingsGet('AccountHash') }, params); diff --git a/dev/Stores/User/Messagelist.js b/dev/Stores/User/Messagelist.js index a1b8295dd..9db7933c9 100644 --- a/dev/Stores/User/Messagelist.js +++ b/dev/Stores/User/Messagelist.js @@ -8,12 +8,9 @@ import { addObservablesTo, addComputablesTo } from 'External/ko'; import { getFolderInboxName, - addNewMessageCache, - setFolderUidNext, getFolderFromCacheList, setFolderHash, - MessageFlagsCache, - clearNewMessageCache + MessageFlagsCache } from 'Common/Cache'; import { mailBox } from 'Common/Links'; @@ -114,45 +111,40 @@ MessagelistUserStore.hasCheckedOrSelected = koComputable(() => || MessagelistUserStore.find(item => item.checked())) ).extend({ rateLimit: 50 }); -MessagelistUserStore.initUidNextAndNewMessages = (folder, uidNext, newMessages) => { - if (getFolderInboxName() === folder && uidNext) { - if (arrayLength(newMessages)) { - newMessages.forEach(item => addNewMessageCache(folder, item.Uid)); +MessagelistUserStore.notifyNewMessages = (folder, newMessages) => { + if (getFolderInboxName() === folder && arrayLength(newMessages)) { - NotificationUserStore.playSoundNotification(); + NotificationUserStore.playSoundNotification(); - const len = newMessages.length; - if (3 < len) { + const len = newMessages.length; + if (3 < len) { + NotificationUserStore.displayDesktopNotification( + AccountUserStore.email(), + i18n('MESSAGE_LIST/NEW_MESSAGE_NOTIFICATION', { + COUNT: len + }), + { Url: mailBox(newMessages[0].Folder) } + ); + } else { + newMessages.forEach(item => { NotificationUserStore.displayDesktopNotification( - AccountUserStore.email(), - i18n('MESSAGE_LIST/NEW_MESSAGE_NOTIFICATION', { - COUNT: len - }), - { Url: mailBox(newMessages[0].Folder) } + EmailCollectionModel.reviveFromJson(item.From).toString(), + item.subject, + { Folder: item.Folder, Uid: item.Uid } ); - } else { - newMessages.forEach(item => { - NotificationUserStore.displayDesktopNotification( - EmailCollectionModel.reviveFromJson(item.From).toString(), - item.subject, - { Folder: item.Folder, Uid: item.Uid } - ); - }); - } + }); } - - setFolderUidNext(folder, uidNext); } } /** * @param {boolean=} bDropPagePosition = false - * @param {boolean=} bDropCurrenFolderCache = false + * @param {boolean=} bDropCurrentFolderCache = false */ -MessagelistUserStore.reload = (bDropPagePosition = false, bDropCurrenFolderCache = false) => { +MessagelistUserStore.reload = (bDropPagePosition = false, bDropCurrentFolderCache = false) => { let iOffset = (MessagelistUserStore.page() - 1) * SettingsUserStore.messagesPerPage(); - if (bDropCurrenFolderCache) { + if (bDropCurrentFolderCache) { setFolderHash(FolderUserStore.currentFolderFullName(), ''); } @@ -189,9 +181,10 @@ MessagelistUserStore.reload = (bDropPagePosition = false, bDropCurrenFolderCache folder = getFolderFromCacheList(collection.Folder), folderInfo = collection.FolderInfo; if (folder && !bCached) { +// folder.revivePropertiesFromJson(result); folder.expires = Date.now(); - - setFolderHash(collection.Folder, collection.FolderHash); + folder.uidNext = folderInfo.UidNext; + folder.hash = collection.FolderHash; if (null != folderInfo.totalEmails) { folder.totalEmails(folderInfo.totalEmails); @@ -213,7 +206,7 @@ MessagelistUserStore.reload = (bDropPagePosition = false, bDropCurrenFolderCache }); folder.permanentFlags(folderInfo.PermanentFlags); - MessagelistUserStore.initUidNextAndNewMessages(folder.fullName, folderInfo.UidNext, collection.NewMessages); + MessagelistUserStore.notifyNewMessages(folder.fullName, collection.NewMessages); } MessagelistUserStore.count(collection.MessageResultCount); @@ -238,8 +231,6 @@ MessagelistUserStore.reload = (bDropPagePosition = false, bDropCurrenFolderCache MessagelistUserStore(collection); MessagelistUserStore.isIncomplete(false); - clearNewMessageCache(); - if (folder && (bCached || unreadCountChange || SettingsUserStore.useThreads())) { rl.app.folderInformation(folder.fullName, collection); } @@ -341,19 +332,24 @@ MessagelistUserStore.removeMessagesFromList = ( messages.forEach(item => item && item.isUnseen() && ++unseenCount); - if (fromFolder && !copy) { - fromFolder.totalEmails( - 0 <= fromFolder.totalEmails() - uidForRemove.length ? fromFolder.totalEmails() - uidForRemove.length : 0 - ); - - if (0 < unseenCount) { - fromFolder.unreadEmails( - 0 <= fromFolder.unreadEmails() - unseenCount ? fromFolder.unreadEmails() - unseenCount : 0 + if (fromFolder) { + fromFolder.hash = ''; + if (!copy) { + fromFolder.totalEmails( + 0 <= fromFolder.totalEmails() - uidForRemove.length ? fromFolder.totalEmails() - uidForRemove.length : 0 ); + + if (0 < unseenCount) { + fromFolder.unreadEmails( + 0 <= fromFolder.unreadEmails() - unseenCount ? fromFolder.unreadEmails() - unseenCount : 0 + ); + } } } if (toFolder) { + toFolder.hash = ''; + if (trashFolder === toFolder.fullName || spamFolder === toFolder.fullName) { unseenCount = 0; } @@ -385,14 +381,6 @@ MessagelistUserStore.removeMessagesFromList = ( } } - if (fromFolderFullName) { - setFolderHash(fromFolderFullName, ''); - } - - if (toFolderFullName) { - setFolderHash(toFolderFullName, ''); - } - if (MessagelistUserStore.threadUid()) { if ( messageList.length && diff --git a/dev/View/Popup/FolderClear.js b/dev/View/Popup/FolderClear.js index 50ba247b3..a960642b6 100644 --- a/dev/View/Popup/FolderClear.js +++ b/dev/View/Popup/FolderClear.js @@ -1,5 +1,4 @@ import { i18n, getNotification } from 'Common/Translator'; -import { setFolderHash } from 'Common/Cache'; import { MessageUserStore } from 'Stores/User/Message'; import { MessagelistUserStore } from 'Stores/User/Messagelist'; @@ -45,8 +44,7 @@ export class FolderClearPopupView extends AbstractViewPopup { folderToClear.totalEmails(0); folderToClear.unreadEmails(0); - - setFolderHash(folderToClear.fullName, ''); + folderToClear.hash = ''; Remote.request('FolderClear', iError => { this.clearingProcess(false); diff --git a/dev/View/User/MailBox/FolderList.js b/dev/View/User/MailBox/FolderList.js index 9f367cf0c..7b05be5b5 100644 --- a/dev/View/User/MailBox/FolderList.js +++ b/dev/View/User/MailBox/FolderList.js @@ -3,7 +3,7 @@ import ko from 'ko'; import { Scope } from 'Common/Enums'; import { moveAction, addShortcut } from 'Common/Globals'; import { mailBox, settings } from 'Common/Links'; -import { setFolderHash } from 'Common/Cache'; +//import { setFolderHash } from 'Common/Cache'; import { addComputablesTo } from 'External/ko'; import { AppUserStore } from 'Stores/User/App'; @@ -100,11 +100,11 @@ export class MailFolderList extends AbstractViewLeft { if (!SettingsUserStore.usePreviewPane()) { MessageUserStore.message(null); } - +/* if (folder.fullName === FolderUserStore.currentFolderFullName()) { setFolderHash(folder.fullName, ''); } - +*/ hasher.setHash( mailBox(folder.fullNameHash, 1, (event.target.matches('.flag-icon') && !folder.isFlagged()) ? 'flagged' : ''