mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Centralize loading of accounts and identities
This commit is contained in:
parent
7c1f70c51e
commit
ea55eb13e5
6 changed files with 42 additions and 38 deletions
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue