mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 21:49:21 +03:00
prettier --write
This commit is contained in:
parent
450528ff00
commit
8a0be3212d
164 changed files with 7053 additions and 9008 deletions
|
|
@ -1,19 +1,17 @@
|
|||
|
||||
import window from 'window';
|
||||
import $ from '$';
|
||||
|
||||
import {ajax} from 'Common/Links';
|
||||
import {microtime, isUnd, isNormal, pString, pInt, inArray} from 'Common/Utils';
|
||||
import {DEFAULT_AJAX_TIMEOUT, TOKEN_ERROR_LIMIT, AJAX_ERROR_LIMIT} from 'Common/Consts';
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {data as GlobalsData} from 'Common/Globals';
|
||||
import { ajax } from 'Common/Links';
|
||||
import { microtime, isUnd, isNormal, pString, pInt, inArray } from 'Common/Utils';
|
||||
import { DEFAULT_AJAX_TIMEOUT, TOKEN_ERROR_LIMIT, AJAX_ERROR_LIMIT } from 'Common/Consts';
|
||||
import { StorageResultType, Notification } from 'Common/Enums';
|
||||
import { data as GlobalsData } from 'Common/Globals';
|
||||
import * as Plugins from 'Common/Plugins';
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
import {AbstractBasicPromises} from 'Promises/AbstractBasic';
|
||||
import { AbstractBasicPromises } from 'Promises/AbstractBasic';
|
||||
|
||||
class AbstractAjaxPromises extends AbstractBasicPromises
|
||||
{
|
||||
class AbstractAjaxPromises extends AbstractBasicPromises {
|
||||
oRequests = {};
|
||||
|
||||
constructor() {
|
||||
|
|
@ -27,10 +25,8 @@ class AbstractAjaxPromises extends AbstractBasicPromises
|
|||
}
|
||||
|
||||
abort(sAction, bClearOnly) {
|
||||
if (this.oRequests[sAction])
|
||||
{
|
||||
if (!bClearOnly && this.oRequests[sAction].abort)
|
||||
{
|
||||
if (this.oRequests[sAction]) {
|
||||
if (!bClearOnly && this.oRequests[sAction].abort) {
|
||||
this.oRequests[sAction].__aborted__ = true;
|
||||
this.oRequests[sAction].abort();
|
||||
}
|
||||
|
|
@ -43,16 +39,13 @@ class AbstractAjaxPromises extends AbstractBasicPromises
|
|||
}
|
||||
|
||||
ajaxRequest(action, isPost, timeOut, params, additionalGetString, fTrigger) {
|
||||
|
||||
return new window.Promise((resolve, reject) => {
|
||||
|
||||
const start = microtime();
|
||||
|
||||
timeOut = isNormal(timeOut) ? timeOut : DEFAULT_AJAX_TIMEOUT;
|
||||
additionalGetString = isUnd(additionalGetString) ? '' : pString(additionalGetString);
|
||||
|
||||
if (isPost)
|
||||
{
|
||||
if (isPost) {
|
||||
params.XToken = Settings.appSettingsGet('token');
|
||||
}
|
||||
|
||||
|
|
@ -65,24 +58,20 @@ class AbstractAjaxPromises extends AbstractBasicPromises
|
|||
url: ajax(additionalGetString),
|
||||
async: true,
|
||||
dataType: 'json',
|
||||
data: isPost ? (params || {}) : {},
|
||||
data: isPost ? params || {} : {},
|
||||
timeout: timeOut,
|
||||
global: true
|
||||
}).always((data, textStatus) => {
|
||||
|
||||
let
|
||||
isCached = false,
|
||||
let isCached = false,
|
||||
errorData = null;
|
||||
|
||||
if (data && data.Time)
|
||||
{
|
||||
if (data && data.Time) {
|
||||
isCached = pInt(data.Time) > microtime() - start;
|
||||
}
|
||||
|
||||
// backward capability
|
||||
let type = '';
|
||||
switch (true)
|
||||
{
|
||||
switch (true) {
|
||||
case 'success' === textStatus && data && data.Result && action === data.Action:
|
||||
type = StorageResultType.Success;
|
||||
break;
|
||||
|
|
@ -95,97 +84,84 @@ class AbstractAjaxPromises extends AbstractBasicPromises
|
|||
}
|
||||
|
||||
Plugins.runHook('ajax-default-response', [
|
||||
action, StorageResultType.Success === type ? data : null, type, isCached, params
|
||||
action,
|
||||
StorageResultType.Success === type ? data : null,
|
||||
type,
|
||||
isCached,
|
||||
params
|
||||
]);
|
||||
|
||||
if ('success' === textStatus)
|
||||
{
|
||||
if (data && data.Result && action === data.Action)
|
||||
{
|
||||
if ('success' === textStatus) {
|
||||
if (data && data.Result && action === data.Action) {
|
||||
data.__cached__ = isCached;
|
||||
resolve(data);
|
||||
}
|
||||
else if (data && data.Action)
|
||||
{
|
||||
} else if (data && data.Action) {
|
||||
errorData = data;
|
||||
reject(data.ErrorCode ? data.ErrorCode : Notification.AjaxFalse);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
errorData = data;
|
||||
reject(Notification.AjaxParse);
|
||||
}
|
||||
}
|
||||
else if ('timeout' === textStatus)
|
||||
{
|
||||
} else if ('timeout' === textStatus) {
|
||||
errorData = data;
|
||||
reject(Notification.AjaxTimeout);
|
||||
}
|
||||
else if ('abort' === textStatus)
|
||||
{
|
||||
if (!data || !data.__aborted__)
|
||||
{
|
||||
} else if ('abort' === textStatus) {
|
||||
if (!data || !data.__aborted__) {
|
||||
reject(Notification.AjaxAbort);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
errorData = data;
|
||||
reject(Notification.AjaxParse);
|
||||
}
|
||||
|
||||
if (this.oRequests[action])
|
||||
{
|
||||
if (this.oRequests[action]) {
|
||||
this.oRequests[action] = null;
|
||||
delete this.oRequests[action];
|
||||
}
|
||||
|
||||
this.setTrigger(fTrigger, false);
|
||||
|
||||
if (errorData)
|
||||
{
|
||||
if (-1 < inArray(errorData.ErrorCode, [
|
||||
Notification.AuthError, Notification.AccessError,
|
||||
Notification.ConnectionError, Notification.DomainNotAllowed, Notification.AccountNotAllowed,
|
||||
Notification.MailServerError, Notification.UnknownNotification, Notification.UnknownError
|
||||
]))
|
||||
{
|
||||
if (errorData) {
|
||||
if (
|
||||
-1 <
|
||||
inArray(errorData.ErrorCode, [
|
||||
Notification.AuthError,
|
||||
Notification.AccessError,
|
||||
Notification.ConnectionError,
|
||||
Notification.DomainNotAllowed,
|
||||
Notification.AccountNotAllowed,
|
||||
Notification.MailServerError,
|
||||
Notification.UnknownNotification,
|
||||
Notification.UnknownError
|
||||
])
|
||||
) {
|
||||
GlobalsData.iAjaxErrorCount += 1;
|
||||
}
|
||||
|
||||
if (Notification.InvalidToken === errorData.ErrorCode)
|
||||
{
|
||||
if (Notification.InvalidToken === errorData.ErrorCode) {
|
||||
GlobalsData.iTokenErrorCount += 1;
|
||||
}
|
||||
|
||||
if (TOKEN_ERROR_LIMIT < GlobalsData.iTokenErrorCount)
|
||||
{
|
||||
if (GlobalsData.__APP__ && GlobalsData.__APP__.loginAndLogoutReload)
|
||||
{
|
||||
if (TOKEN_ERROR_LIMIT < GlobalsData.iTokenErrorCount) {
|
||||
if (GlobalsData.__APP__ && GlobalsData.__APP__.loginAndLogoutReload) {
|
||||
GlobalsData.__APP__.loginAndLogoutReload(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (errorData.ClearAuth || errorData.Logout || AJAX_ERROR_LIMIT < GlobalsData.iAjaxErrorCount)
|
||||
{
|
||||
if (GlobalsData.__APP__ && GlobalsData.__APP__.clearClientSideToken)
|
||||
{
|
||||
if (errorData.ClearAuth || errorData.Logout || AJAX_ERROR_LIMIT < GlobalsData.iAjaxErrorCount) {
|
||||
if (GlobalsData.__APP__ && GlobalsData.__APP__.clearClientSideToken) {
|
||||
GlobalsData.__APP__.clearClientSideToken();
|
||||
}
|
||||
|
||||
if (GlobalsData.__APP__ && !errorData.ClearAuth && GlobalsData.__APP__.loginAndLogoutReload)
|
||||
{
|
||||
if (GlobalsData.__APP__ && !errorData.ClearAuth && GlobalsData.__APP__.loginAndLogoutReload) {
|
||||
GlobalsData.__APP__.loginAndLogoutReload(false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (oH)
|
||||
{
|
||||
if (this.oRequests[action])
|
||||
{
|
||||
if (oH) {
|
||||
if (this.oRequests[action]) {
|
||||
this.oRequests[action] = null;
|
||||
delete this.oRequests[action];
|
||||
}
|
||||
|
|
@ -196,7 +172,6 @@ class AbstractAjaxPromises extends AbstractBasicPromises
|
|||
}
|
||||
|
||||
getRequest(sAction, fTrigger, sAdditionalGetString, iTimeOut) {
|
||||
|
||||
sAdditionalGetString = isUnd(sAdditionalGetString) ? '' : pString(sAdditionalGetString);
|
||||
sAdditionalGetString = sAction + '/' + sAdditionalGetString;
|
||||
|
||||
|
|
@ -204,7 +179,6 @@ class AbstractAjaxPromises extends AbstractBasicPromises
|
|||
}
|
||||
|
||||
postRequest(action, fTrigger, params, timeOut) {
|
||||
|
||||
params = params || {};
|
||||
params.Action = action;
|
||||
|
||||
|
|
@ -212,4 +186,4 @@ class AbstractAjaxPromises extends AbstractBasicPromises
|
|||
}
|
||||
}
|
||||
|
||||
export {AbstractAjaxPromises, AbstractAjaxPromises as default};
|
||||
export { AbstractAjaxPromises, AbstractAjaxPromises as default };
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
|
||||
import window from 'window';
|
||||
import {isArray} from 'Common/Utils';
|
||||
import { isArray } from 'Common/Utils';
|
||||
|
||||
export class AbstractBasicPromises
|
||||
{
|
||||
export class AbstractBasicPromises {
|
||||
oPromisesStack = {};
|
||||
|
||||
func(fFunc) {
|
||||
|
|
@ -20,12 +18,10 @@ export class AbstractBasicPromises
|
|||
}
|
||||
|
||||
setTrigger(trigger, value) {
|
||||
if (trigger)
|
||||
{
|
||||
if (trigger) {
|
||||
value = !!value;
|
||||
(isArray(trigger) ? trigger : [trigger]).forEach((fTrigger) => {
|
||||
if (fTrigger)
|
||||
{
|
||||
if (fTrigger) {
|
||||
fTrigger(value);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
|
||||
import window from 'window';
|
||||
|
||||
import PromisesPopulator from 'Promises/User/Populator';
|
||||
import {AbstractAjaxPromises} from 'Promises/AbstractAjax';
|
||||
import { AbstractAjaxPromises } from 'Promises/AbstractAjax';
|
||||
|
||||
class UserAjaxUserPromises extends AbstractAjaxPromises
|
||||
{
|
||||
class UserAjaxUserPromises extends AbstractAjaxPromises {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
|
@ -13,11 +11,13 @@ class UserAjaxUserPromises extends AbstractAjaxPromises
|
|||
}
|
||||
|
||||
foldersReload(fTrigger) {
|
||||
return this.abort('Folders').postRequest('Folders', fTrigger).then((data) => {
|
||||
PromisesPopulator.foldersList(data.Result);
|
||||
PromisesPopulator.foldersAdditionalParameters(data.Result);
|
||||
return true;
|
||||
});
|
||||
return this.abort('Folders')
|
||||
.postRequest('Folders', fTrigger)
|
||||
.then((data) => {
|
||||
PromisesPopulator.foldersList(data.Result);
|
||||
PromisesPopulator.foldersAdditionalParameters(data.Result);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
foldersReloadWithTimeout(fTrigger) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
import _ from '_';
|
||||
|
||||
import {UNUSED_OPTION_VALUE} from 'Common/Consts';
|
||||
import {isArray, isNormal, pInt, isUnd, noop} from 'Common/Utils';
|
||||
import {ClientSideKeyName, ServerFolderType} from 'Common/Enums';
|
||||
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
||||
import { isArray, isNormal, pInt, isUnd, noop } from 'Common/Utils';
|
||||
import { ClientSideKeyName, ServerFolderType } from 'Common/Enums';
|
||||
import * as Cache from 'Common/Cache';
|
||||
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
|
@ -14,11 +13,10 @@ import FolderStore from 'Stores/User/Folder';
|
|||
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
import {FolderModel} from 'Model/Folder';
|
||||
import {AbstractBasicPromises} from 'Promises/AbstractBasic';
|
||||
import { FolderModel } from 'Model/Folder';
|
||||
import { AbstractBasicPromises } from 'Promises/AbstractBasic';
|
||||
|
||||
class PromisesUserPopulator extends AbstractBasicPromises
|
||||
{
|
||||
class PromisesUserPopulator extends AbstractBasicPromises {
|
||||
/**
|
||||
* @param {string} sFullNameHash
|
||||
* @param {Array?} expandedFolders
|
||||
|
|
@ -33,8 +31,11 @@ class PromisesUserPopulator extends AbstractBasicPromises
|
|||
* @returns {string}
|
||||
*/
|
||||
normalizeFolder(sFolderFullNameRaw) {
|
||||
return ('' === sFolderFullNameRaw || UNUSED_OPTION_VALUE === sFolderFullNameRaw ||
|
||||
null !== Cache.getFolderFromCacheList(sFolderFullNameRaw)) ? sFolderFullNameRaw : '';
|
||||
return '' === sFolderFullNameRaw ||
|
||||
UNUSED_OPTION_VALUE === sFolderFullNameRaw ||
|
||||
null !== Cache.getFolderFromCacheList(sFolderFullNameRaw)
|
||||
? sFolderFullNameRaw
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -44,61 +45,52 @@ class PromisesUserPopulator extends AbstractBasicPromises
|
|||
* @returns {Array}
|
||||
*/
|
||||
folderResponseParseRec(sNamespace, aFolders, expandedFolders) {
|
||||
|
||||
const
|
||||
bDisplaySpecSetting = FolderStore.displaySpecSetting(),
|
||||
const bDisplaySpecSetting = FolderStore.displaySpecSetting(),
|
||||
aList = [];
|
||||
|
||||
_.each(aFolders, (oFolder) => {
|
||||
if (oFolder)
|
||||
{
|
||||
if (oFolder) {
|
||||
let oCacheFolder = Cache.getFolderFromCacheList(oFolder.FullNameRaw);
|
||||
if (!oCacheFolder)
|
||||
{
|
||||
if (!oCacheFolder) {
|
||||
oCacheFolder = FolderModel.newInstanceFromJson(oFolder);
|
||||
if (oCacheFolder)
|
||||
{
|
||||
if (oCacheFolder) {
|
||||
Cache.setFolderToCacheList(oFolder.FullNameRaw, oCacheFolder);
|
||||
Cache.setFolderFullNameRaw(oCacheFolder.fullNameHash, oFolder.FullNameRaw, oCacheFolder);
|
||||
}
|
||||
}
|
||||
|
||||
if (oCacheFolder)
|
||||
{
|
||||
if (bDisplaySpecSetting)
|
||||
{
|
||||
if (oCacheFolder) {
|
||||
if (bDisplaySpecSetting) {
|
||||
oCacheFolder.checkable(!!oFolder.Checkable);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
oCacheFolder.checkable(true);
|
||||
}
|
||||
|
||||
oCacheFolder.collapsed(!this.isFolderExpanded(oCacheFolder.fullNameHash, expandedFolders));
|
||||
|
||||
if (oFolder.Extended)
|
||||
{
|
||||
if (oFolder.Extended.Hash)
|
||||
{
|
||||
if (oFolder.Extended) {
|
||||
if (oFolder.Extended.Hash) {
|
||||
Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash);
|
||||
}
|
||||
|
||||
if (isNormal(oFolder.Extended.MessageCount))
|
||||
{
|
||||
if (isNormal(oFolder.Extended.MessageCount)) {
|
||||
oCacheFolder.messageCountAll(oFolder.Extended.MessageCount);
|
||||
}
|
||||
|
||||
if (isNormal(oFolder.Extended.MessageUnseenCount))
|
||||
{
|
||||
if (isNormal(oFolder.Extended.MessageUnseenCount)) {
|
||||
oCacheFolder.messageCountUnread(oFolder.Extended.MessageUnseenCount);
|
||||
}
|
||||
}
|
||||
|
||||
if (oFolder.SubFolders && 'Collection/FolderCollection' === oFolder.SubFolders['@Object'] &&
|
||||
oFolder.SubFolders['@Collection'] && isArray(oFolder.SubFolders['@Collection']))
|
||||
{
|
||||
if (
|
||||
oFolder.SubFolders &&
|
||||
'Collection/FolderCollection' === oFolder.SubFolders['@Object'] &&
|
||||
oFolder.SubFolders['@Collection'] &&
|
||||
isArray(oFolder.SubFolders['@Collection'])
|
||||
) {
|
||||
oCacheFolder.subFolders(
|
||||
this.folderResponseParseRec(sNamespace, oFolder.SubFolders['@Collection'], expandedFolders));
|
||||
this.folderResponseParseRec(sNamespace, oFolder.SubFolders['@Collection'], expandedFolders)
|
||||
);
|
||||
}
|
||||
|
||||
aList.push(oCacheFolder);
|
||||
|
|
@ -110,29 +102,39 @@ class PromisesUserPopulator extends AbstractBasicPromises
|
|||
}
|
||||
|
||||
foldersList(oData) {
|
||||
if (oData && 'Collection/FolderCollection' === oData['@Object'] &&
|
||||
oData['@Collection'] && isArray(oData['@Collection']))
|
||||
{
|
||||
const
|
||||
expandedFolders = Local.get(ClientSideKeyName.ExpandedFolders),
|
||||
if (
|
||||
oData &&
|
||||
'Collection/FolderCollection' === oData['@Object'] &&
|
||||
oData['@Collection'] &&
|
||||
isArray(oData['@Collection'])
|
||||
) {
|
||||
const expandedFolders = Local.get(ClientSideKeyName.ExpandedFolders),
|
||||
cnt = pInt(oData.CountRec);
|
||||
|
||||
let limit = pInt(Settings.appSettingsGet('folderSpecLimit'));
|
||||
limit = 100 < limit ? 100 : (10 > limit ? 10 : limit);
|
||||
limit = 100 < limit ? 100 : 10 > limit ? 10 : limit;
|
||||
|
||||
FolderStore.displaySpecSetting(0 >= cnt || limit < cnt);
|
||||
|
||||
FolderStore.folderList(this.folderResponseParseRec(
|
||||
isUnd(oData.Namespace) ? '' : oData.Namespace, oData['@Collection'], expandedFolders)); // @todo optimization required
|
||||
FolderStore.folderList(
|
||||
this.folderResponseParseRec(
|
||||
isUnd(oData.Namespace) ? '' : oData.Namespace,
|
||||
oData['@Collection'],
|
||||
expandedFolders
|
||||
)
|
||||
); // @todo optimization required
|
||||
}
|
||||
}
|
||||
|
||||
foldersAdditionalParameters(oData) {
|
||||
if (oData && oData && 'Collection/FolderCollection' === oData['@Object'] &&
|
||||
oData['@Collection'] && isArray(oData['@Collection']))
|
||||
{
|
||||
if (!isUnd(oData.Namespace))
|
||||
{
|
||||
if (
|
||||
oData &&
|
||||
oData &&
|
||||
'Collection/FolderCollection' === oData['@Object'] &&
|
||||
oData['@Collection'] &&
|
||||
isArray(oData['@Collection'])
|
||||
) {
|
||||
if (!isUnd(oData.Namespace)) {
|
||||
FolderStore.namespace = oData.Namespace;
|
||||
}
|
||||
|
||||
|
|
@ -142,14 +144,17 @@ class PromisesUserPopulator extends AbstractBasicPromises
|
|||
|
||||
let update = false;
|
||||
|
||||
if (oData.SystemFolders && '' === '' +
|
||||
Settings.settingsGet('SentFolder') +
|
||||
Settings.settingsGet('DraftFolder') +
|
||||
Settings.settingsGet('SpamFolder') +
|
||||
Settings.settingsGet('TrashFolder') +
|
||||
Settings.settingsGet('ArchiveFolder') +
|
||||
Settings.settingsGet('NullFolder'))
|
||||
{
|
||||
if (
|
||||
oData.SystemFolders &&
|
||||
'' ===
|
||||
'' +
|
||||
Settings.settingsGet('SentFolder') +
|
||||
Settings.settingsGet('DraftFolder') +
|
||||
Settings.settingsGet('SpamFolder') +
|
||||
Settings.settingsGet('TrashFolder') +
|
||||
Settings.settingsGet('ArchiveFolder') +
|
||||
Settings.settingsGet('NullFolder')
|
||||
) {
|
||||
Settings.settingsSet('SentFolder', oData.SystemFolders[ServerFolderType.SENT] || null);
|
||||
Settings.settingsSet('DraftFolder', oData.SystemFolders[ServerFolderType.DRAFTS] || null);
|
||||
Settings.settingsSet('SpamFolder', oData.SystemFolders[ServerFolderType.JUNK] || null);
|
||||
|
|
@ -165,8 +170,7 @@ class PromisesUserPopulator extends AbstractBasicPromises
|
|||
FolderStore.trashFolder(this.normalizeFolder(Settings.settingsGet('TrashFolder')));
|
||||
FolderStore.archiveFolder(this.normalizeFolder(Settings.settingsGet('ArchiveFolder')));
|
||||
|
||||
if (update)
|
||||
{
|
||||
if (update) {
|
||||
Remote.saveSystemFolders(noop, {
|
||||
SentFolder: FolderStore.sentFolder(),
|
||||
DraftFolder: FolderStore.draftFolder(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue