From 87bee226b448b162d39773dd5c2b451632758af5 Mon Sep 17 00:00:00 2001 From: djmaze Date: Thu, 18 Mar 2021 13:52:56 +0100 Subject: [PATCH] Easier refresh Folders --- dev/App/User.js | 12 +++++++----- dev/Model/FolderCollection.js | 2 +- dev/Stores/User/Folder.js | 12 +++++------- dev/Stores/User/Message.js | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dev/App/User.js b/dev/App/User.js index cc23c5794..0da39b022 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -81,6 +81,9 @@ import { FolderSystemPopupView } from 'View/Popup/FolderSystem'; import { AskPopupView } from 'View/Popup/Ask'; import { TwoFactorConfigurationPopupView } from 'View/Popup/TwoFactorConfiguration'; +// Every 5 minutes +const refreshFolders = 300000; + class AppUser extends AbstractApp { constructor() { super(Remote); @@ -561,7 +564,7 @@ class AppUser extends AbstractApp { const folderFromCache = getFolderFromCacheList(data.Result.Folder); if (folderFromCache) { - folderFromCache.interval = Date.now(); + folderFromCache.expires = Date.now(); if (data.Result.Hash) { setFolderHash(data.Result.Folder, data.Result.Hash); @@ -630,7 +633,7 @@ class AppUser extends AbstractApp { * @param {boolean=} boot = false */ folderInformationMultiply(boot = false) { - const folders = FolderUserStore.getNextFolderNames(); + const folders = FolderUserStore.getNextFolderNames(refreshFolders); if (isNonEmptyArray(folders)) { Remote.folderInformationMultiply((iError, oData) => { if (!iError && oData && oData.Result && oData.Result.List && isNonEmptyArray(oData.Result.List)) { @@ -641,7 +644,7 @@ class AppUser extends AbstractApp { let unreadCountChange = false; if (folder) { - folder.interval = utc; + folder.expires = utc; if (item.Hash) { setFolderHash(item.Folder, item.Hash); @@ -956,7 +959,6 @@ class AppUser extends AbstractApp { // false ? AboutUserScreen : null ]); - // Every 5 minutes setInterval(() => { const cF = FolderUserStore.currentFolderFullNameRaw(), iF = getFolderInboxName(); @@ -965,7 +967,7 @@ class AppUser extends AbstractApp { this.folderInformation(cF); } this.folderInformationMultiply(); - }, 300000); + }, refreshFolders); // Every 15 minutes setInterval(this.quota, 900000); diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index 9ccf90013..017fa37a9 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -187,7 +187,7 @@ export class FolderModel extends AbstractModel { this.delimiter = ''; this.namespace = ''; this.deep = 0; - this.interval = 0; + this.expires = 0; this.selectable = false; this.exists = true; diff --git a/dev/Stores/User/Folder.js b/dev/Stores/User/Folder.js index 164b30ea4..1c1a94e0f 100644 --- a/dev/Stores/User/Folder.js +++ b/dev/Stores/User/Folder.js @@ -157,25 +157,23 @@ export const FolderUserStore = new class { /** * @returns {Array} */ - getNextFolderNames() { + getNextFolderNames(ttl) { const result = [], limit = 10, utc = Date.now(), - timeout = utc - 60000 * 5, + timeout = utc - ttl, timeouts = [], - inboxFolderName = getFolderInboxName(), bDisplaySpecSetting = this.displaySpecSetting(), fSearchFunction = (list) => { list.forEach(folder => { if ( folder && - inboxFolderName !== folder.fullNameRaw && folder.selectable && folder.exists && - timeout > folder.interval && + timeout > folder.expires && (folder.isSystemFolder() || (folder.subscribed() && (folder.checkable() || !bDisplaySpecSetting))) ) { - timeouts.push([folder.interval, folder.fullNameRaw]); + timeouts.push([folder.expires, folder.fullNameRaw]); } if (folder && folder.subFolders.length) { @@ -191,7 +189,7 @@ export const FolderUserStore = new class { timeouts.find(aItem => { const folder = getFolderFromCacheList(aItem[1]); if (folder) { - folder.interval = utc; + folder.expires = utc; result.push(aItem[1]); } diff --git a/dev/Stores/User/Message.js b/dev/Stores/User/Message.js index 3d597c676..24e2be80a 100644 --- a/dev/Stores/User/Message.js +++ b/dev/Stores/User/Message.js @@ -671,7 +671,7 @@ export const MessageUserStore = new class { folder = getFolderFromCacheList(collection.Folder); if (folder && !cached) { - folder.interval = Date.now(); + folder.expires = Date.now(); setFolderHash(collection.Folder, collection.FolderHash);