diff --git a/dev/App/User.js b/dev/App/User.js index b18f8a5d9..386a1c6e6 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -1,8 +1,8 @@ import 'External/User/ko'; import { SMAudio } from 'Common/Audio'; -import { isArray, pInt } from 'Common/Utils'; -import { mailToHelper, setLayoutResizer, dropdownsDetectVisibility } from 'Common/UtilsUser'; +import { pInt } from 'Common/Utils'; +import { mailToHelper, setLayoutResizer, dropdownsDetectVisibility, loadAccountsAndIdentities } from 'Common/UtilsUser'; import { FolderType, @@ -33,7 +33,6 @@ import { SettingsUserStore } from 'Stores/User/Settings'; import { NotificationUserStore } from 'Stores/User/Notification'; import { AccountUserStore } from 'Stores/User/Account'; import { ContactUserStore } from 'Stores/User/Contact'; -import { IdentityUserStore } from 'Stores/User/Identity'; import { FolderUserStore } from 'Stores/User/Folder'; import { PgpUserStore } from 'Stores/User/Pgp'; import { MessagelistUserStore } from 'Stores/User/Messagelist'; @@ -43,9 +42,6 @@ import { MessageUserStore } from 'Stores/User/Message'; import Remote from 'Remote/User/Fetch'; -import { AccountModel } from 'Model/Account'; -import { IdentityModel } from 'Model/Identity'; - import { LoginUserScreen } from 'Screen/User/Login'; import { MailBoxUserScreen } from 'Screen/User/MailBox'; import { SettingsUserScreen } from 'Screen/User/Settings'; @@ -139,31 +135,6 @@ export class AppUser extends AbstractApp { } } - accountsAndIdentities() { - AccountUserStore.loading(true); - IdentityUserStore.loading(true); - - Remote.request('AccountsAndIdentities', (iError, oData) => { - AccountUserStore.loading(false); - IdentityUserStore.loading(false); - - if (!iError) { - let items = oData.Result.Accounts; - AccountUserStore(isArray(items) - ? items.map(oValue => new AccountModel(oValue.email, oValue.name)) - : [] - ); - AccountUserStore.unshift(new AccountModel(SettingsGet('mainEmail'), '', false)); - - items = oData.Result.Identities; - IdentityUserStore(isArray(items) - ? items.map(identityData => IdentityModel.reviveFromJson(identityData)) - : [] - ); - } - }); - } - /** * @param {string} folder * @param {Array=} list = [] @@ -216,9 +187,7 @@ export class AppUser extends AbstractApp { setRefreshFoldersInterval(pInt(SettingsGet('CheckMailInterval'))); - ContactUserStore.init(); - - this.accountsAndIdentities(); + loadAccountsAndIdentities(); setTimeout(() => { const cF = FolderUserStore.currentFolderFullName(); @@ -267,7 +236,6 @@ export class AppUser extends AbstractApp { console.error(e); } }); - } else { startScreens([LoginUserScreen]); } diff --git a/dev/Common/UtilsUser.js b/dev/Common/UtilsUser.js index ee7922f58..9f721f8de 100644 --- a/dev/Common/UtilsUser.js +++ b/dev/Common/UtilsUser.js @@ -12,6 +12,12 @@ import { ThemeStore } from 'Stores/Theme'; import Remote from 'Remote/User/Fetch'; import { attachmentDownload } from 'Common/Links'; +import { AccountModel } from 'Model/Account'; +import { IdentityModel } from 'Model/Identity'; +import { AccountUserStore } from 'Stores/User/Account'; +import { IdentityUserStore } from 'Stores/User/Identity'; +import { isArray } from 'Common/Utils'; + export const moveAction = ko.observable(false), @@ -20,6 +26,32 @@ dropdownsDetectVisibility = (() => dropdownVisibility(!!dropdowns.find(item => item.classList.contains('show'))) ).debounce(50), + +loadAccountsAndIdentities = () => { + AccountUserStore.loading(true); + IdentityUserStore.loading(true); + + Remote.request('AccountsAndIdentities', (iError, oData) => { + AccountUserStore.loading(false); + IdentityUserStore.loading(false); + + if (!iError) { + let items = oData.Result.Accounts; + AccountUserStore(isArray(items) + ? items.map(oValue => new AccountModel(oValue.email, oValue.name)) + : [] + ); + AccountUserStore.unshift(new AccountModel(SettingsGet('mainEmail'), '', false)); + + items = oData.Result.Identities; + IdentityUserStore(isArray(items) + ? items.map(identityData => IdentityModel.reviveFromJson(identityData)) + : [] + ); + } + }); +}, + /** * @param {string} link * @returns {boolean} diff --git a/dev/Screen/User/MailBox.js b/dev/Screen/User/MailBox.js index 8450f7648..6b1e605ef 100644 --- a/dev/Screen/User/MailBox.js +++ b/dev/Screen/User/MailBox.js @@ -67,6 +67,7 @@ export class MailBoxUserScreen extends AbstractScreen { * @returns {void} */ onRoute(folderHash, page, search, messageUid) { + // Only works when FolderUserStore.folderList() is loaded const folder = getFolderFromHashMap(folderHash.replace(/~([\d]+)$/, '')); if (folder) { FolderUserStore.currentFolder(folder); diff --git a/dev/Settings/User/Accounts.js b/dev/Settings/User/Accounts.js index 0e82bc6f0..edaf08ad8 100644 --- a/dev/Settings/User/Accounts.js +++ b/dev/Settings/User/Accounts.js @@ -2,6 +2,7 @@ import ko from 'ko'; //import { koComputable } from 'External/ko'; import { SettingsCapa, SettingsGet } from 'Common/Globals'; +import { loadAccountsAndIdentities } from 'Common/UtilsUser'; import { AccountUserStore } from 'Stores/User/Account'; import { IdentityUserStore } from 'Stores/User/Identity'; @@ -64,7 +65,7 @@ export class UserSettingsAccounts /*extends AbstractViewSettings*/ { rl.route.root(); setTimeout(() => location.reload(), 1); } else { - rl.app.accountsAndIdentities(); + loadAccountsAndIdentities(); } }, { emailToDelete: accountToRemove.email diff --git a/dev/View/Popup/Account.js b/dev/View/Popup/Account.js index 02ab08e29..e79cb8116 100644 --- a/dev/View/Popup/Account.js +++ b/dev/View/Popup/Account.js @@ -1,5 +1,6 @@ import { addObservablesTo } from 'External/ko'; import { getNotification } from 'Common/Translator'; +import { loadAccountsAndIdentities } from 'Common/UtilsUser'; import Remote from 'Remote/User/Fetch'; @@ -37,7 +38,7 @@ export class AccountPopupView extends AbstractViewPopup { this.submitError(getNotification(iError)); this.submitErrorAdditional(data?.ErrorMessageAdditional); } else { - rl.app.accountsAndIdentities(); + loadAccountsAndIdentities(); this.close(); } }, data diff --git a/dev/View/Popup/Identity.js b/dev/View/Popup/Identity.js index d1d8b20be..8db81772d 100644 --- a/dev/View/Popup/Identity.js +++ b/dev/View/Popup/Identity.js @@ -2,6 +2,7 @@ import { addObservablesTo } from 'External/ko'; import { getNotification } from 'Common/Translator'; +import { loadAccountsAndIdentities } from 'Common/UtilsUser'; import Remote from 'Remote/User/Fetch'; @@ -52,7 +53,7 @@ export class IdentityPopupView extends AbstractViewPopup { if (iError) { this.submitError(getNotification(iError)); } else { - rl.app.accountsAndIdentities(); + loadAccountsAndIdentities(); this.close(); } }, data