mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Code refactoring
This commit is contained in:
parent
bf56821c2d
commit
31860420cb
32 changed files with 1342 additions and 1282 deletions
|
|
@ -4,10 +4,14 @@
|
|||
'use strict';
|
||||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
moment = require('moment'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Consts = require('Common/Consts'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
|
||||
Cache = require('Storage/User/Cache')
|
||||
;
|
||||
|
|
@ -23,6 +27,25 @@
|
|||
this.trashFolder = ko.observable('');
|
||||
this.archiveFolder = ko.observable('');
|
||||
|
||||
this.namespace = '';
|
||||
|
||||
this.folderList = ko.observableArray([]);
|
||||
this.folderList.focused = ko.observable(false);
|
||||
this.folderList.optimized = ko.observable(false);
|
||||
this.folderList.error = ko.observable('');
|
||||
|
||||
this.foldersLoading = ko.observable(false);
|
||||
this.foldersCreating = ko.observable(false);
|
||||
this.foldersDeleting = ko.observable(false);
|
||||
this.foldersRenaming = ko.observable(false);
|
||||
|
||||
this.foldersInboxUnreadCount = ko.observable(0);
|
||||
|
||||
this.currentFolder = ko.observable(null).extend({'toggleSubscribe': [null,
|
||||
function (oPrev) { if (oPrev) { oPrev.selected(false); }},
|
||||
function (oNext) { if (oNext) { oNext.selected(true); }}
|
||||
]});
|
||||
|
||||
this.computers();
|
||||
this.subscribers();
|
||||
}
|
||||
|
|
@ -32,6 +55,96 @@
|
|||
this.draftFolderNotEnabled = ko.computed(function () {
|
||||
return '' === this.draftFolder() || Consts.Values.UnuseOptionValue === this.draftFolder();
|
||||
}, this);
|
||||
|
||||
this.foldersListWithSingleInboxRootFolder = ko.computed(function () {
|
||||
return !_.find(this.folderList(), function (oFolder) {
|
||||
return oFolder && !oFolder.isSystemFolder() && oFolder.visible();
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.currentFolderFullNameRaw = ko.computed(function () {
|
||||
return this.currentFolder() ? this.currentFolder().fullNameRaw : '';
|
||||
}, this);
|
||||
|
||||
this.currentFolderFullName = ko.computed(function () {
|
||||
return this.currentFolder() ? this.currentFolder().fullName : '';
|
||||
}, this);
|
||||
|
||||
this.currentFolderFullNameHash = ko.computed(function () {
|
||||
return this.currentFolder() ? this.currentFolder().fullNameHash : '';
|
||||
}, this);
|
||||
|
||||
this.foldersChanging = ko.computed(function () {
|
||||
var
|
||||
bLoading = this.foldersLoading(),
|
||||
bCreating = this.foldersCreating(),
|
||||
bDeleting = this.foldersDeleting(),
|
||||
bRenaming = this.foldersRenaming()
|
||||
;
|
||||
return bLoading || bCreating || bDeleting || bRenaming;
|
||||
}, this);
|
||||
|
||||
this.folderListSystemNames = ko.computed(function () {
|
||||
|
||||
var
|
||||
aList = [Cache.getFolderInboxName()],
|
||||
aFolders = this.folderList(),
|
||||
sSentFolder = this.sentFolder(),
|
||||
sDraftFolder = this.draftFolder(),
|
||||
sSpamFolder = this.spamFolder(),
|
||||
sTrashFolder = this.trashFolder(),
|
||||
sArchiveFolder = this.archiveFolder()
|
||||
;
|
||||
|
||||
if (Utils.isArray(aFolders) && 0 < aFolders.length)
|
||||
{
|
||||
if ('' !== sSentFolder && Consts.Values.UnuseOptionValue !== sSentFolder)
|
||||
{
|
||||
aList.push(sSentFolder);
|
||||
}
|
||||
if ('' !== sDraftFolder && Consts.Values.UnuseOptionValue !== sDraftFolder)
|
||||
{
|
||||
aList.push(sDraftFolder);
|
||||
}
|
||||
if ('' !== sSpamFolder && Consts.Values.UnuseOptionValue !== sSpamFolder)
|
||||
{
|
||||
aList.push(sSpamFolder);
|
||||
}
|
||||
if ('' !== sTrashFolder && Consts.Values.UnuseOptionValue !== sTrashFolder)
|
||||
{
|
||||
aList.push(sTrashFolder);
|
||||
}
|
||||
if ('' !== sArchiveFolder && Consts.Values.UnuseOptionValue !== sArchiveFolder)
|
||||
{
|
||||
aList.push(sArchiveFolder);
|
||||
}
|
||||
}
|
||||
|
||||
return aList;
|
||||
|
||||
}, this);
|
||||
|
||||
this.folderListSystem = ko.computed(function () {
|
||||
return _.compact(_.map(this.folderListSystemNames(), function (sName) {
|
||||
return Cache.getFolderFromCacheList(sName);
|
||||
}));
|
||||
}, this);
|
||||
|
||||
this.folderMenuForMove = ko.computed(function () {
|
||||
return Utils.folderListOptionsBuilder(this.folderListSystem(), this.folderList(), [
|
||||
this.currentFolderFullNameRaw()
|
||||
], null, null, null, null, function (oItem) {
|
||||
return oItem ? oItem.localName() : '';
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.folderMenuForFilters = ko.computed(function () {
|
||||
return Utils.folderListOptionsBuilder(this.folderListSystem(), this.folderList(),
|
||||
['INBOX'], [['', '']], null, null, null, function (oItem) {
|
||||
return oItem ? oItem.localName() : '';
|
||||
}
|
||||
);
|
||||
}, this);
|
||||
};
|
||||
|
||||
FolderUserStore.prototype.subscribers = function ()
|
||||
|
|
@ -68,6 +181,76 @@
|
|||
this.spamFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Spam), this);
|
||||
this.trashFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Trash), this);
|
||||
this.archiveFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Archive), this);
|
||||
|
||||
this.folderList.focused.subscribe(function (bValue) {
|
||||
if (bValue)
|
||||
{
|
||||
Globals.keyScope(Enums.KeyState.FolderList);
|
||||
}
|
||||
else if (Enums.KeyState.FolderList === Globals.keyScope())
|
||||
{
|
||||
Globals.keyScope(Enums.KeyState.MessageList);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean=} bBoot = false
|
||||
* @returns {Array}
|
||||
*/
|
||||
FolderUserStore.prototype.getNextFolderNames = function (bBoot)
|
||||
{
|
||||
bBoot = Utils.isUnd(bBoot) ? false : !!bBoot;
|
||||
|
||||
var
|
||||
aResult = [],
|
||||
iLimit = 5,
|
||||
iUtc = moment().unix(),
|
||||
iTimeout = iUtc - 60 * 5,
|
||||
aTimeouts = [],
|
||||
sInboxFolderName = Cache.getFolderInboxName(),
|
||||
fSearchFunction = function (aList) {
|
||||
_.each(aList, function (oFolder) {
|
||||
if (oFolder && sInboxFolderName !== oFolder.fullNameRaw &&
|
||||
oFolder.selectable && oFolder.existen &&
|
||||
iTimeout > oFolder.interval &&
|
||||
(!bBoot || oFolder.subScribed()))
|
||||
{
|
||||
aTimeouts.push([oFolder.interval, oFolder.fullNameRaw]);
|
||||
}
|
||||
|
||||
if (oFolder && 0 < oFolder.subFolders().length)
|
||||
{
|
||||
fSearchFunction(oFolder.subFolders());
|
||||
}
|
||||
});
|
||||
}
|
||||
;
|
||||
|
||||
fSearchFunction(this.folderList());
|
||||
|
||||
aTimeouts.sort(function(a, b) {
|
||||
if (a[0] < b[0]) {
|
||||
return -1;
|
||||
} else if (a[0] > b[0]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
_.find(aTimeouts, function (aItem) {
|
||||
var oFolder = Cache.getFolderFromCacheList(aItem[1]);
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.interval = iUtc;
|
||||
aResult.push(aItem[1]);
|
||||
}
|
||||
|
||||
return iLimit <= aResult.length;
|
||||
});
|
||||
|
||||
return _.uniq(aResult);
|
||||
};
|
||||
|
||||
module.exports = new FolderUserStore();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue