snappymail/dev/App/User.jsx

1465 lines
38 KiB
React
Raw Normal View History

2015-11-19 01:32:29 +08:00
import {window, _, $} from 'common';
import progressJs from 'progressJs';
import Tinycon from 'Tinycon';
import * as Enums from 'Common/Enums';
import * as Consts from 'Common/Consts';
import Globals from 'Common/Globals';
import Plugins from 'Common/Plugins';
import Utils from 'Common/Utils';
import Links from 'Common/Links';
import Events from 'Common/Events';
import Translator from 'Common/Translator';
import Momentor from 'Common/Momentor';
import Cache from 'Common/Cache';
import SocialStore from 'Stores/Social';
import SettingsStore from 'Stores/User/Settings';
import AccountStore from 'Stores/User/Account';
import IdentityStore from 'Stores/User/Identity';
import TemplateStore from 'Stores/User/Template';
import FolderStore from 'Stores/User/Folder';
import PgpStore from 'Stores/User/Pgp';
import MessageStore from 'Stores/User/Message';
import ContactStore from 'Stores/User/Contact';
import Local from 'Storage/Client';
2015-11-19 01:32:29 +08:00
import Settings from 'Storage/Settings';
import Remote from 'Remote/User/Ajax';
import Promises from 'Promises/User/Ajax';
import EmailModel from 'Model/Email';
import AccountModel from 'Model/Account';
import IdentityModel from 'Model/Identity';
import TemplateModel from 'Model/Template';
import OpenPgpKeyModel from 'Model/OpenPgpKey';
import kn from 'Knoin/Knoin';
import {AbstractApp} from 'App/Abstract';
class AppUser extends AbstractApp
{
oMoveCache = {};
constructor()
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
super(Remote);
2014-08-20 23:03:12 +08:00
this.quotaDebounce = _.debounce(this.quota, 1000 * 30);
this.moveOrDeleteResponseHelper = _.bind(this.moveOrDeleteResponseHelper, this);
2014-08-20 23:03:12 +08:00
this.messagesMoveTrigger = _.debounce(this.messagesMoveTrigger, 500);
2015-11-19 01:32:29 +08:00
window.setInterval(() => Events.pub('interval.30s'), 30000);
window.setInterval(() => Events.pub('interval.1m'), 60000);
window.setInterval(() => Events.pub('interval.2m'), 60000 * 2);
window.setInterval(() => Events.pub('interval.3m'), 60000 * 3);
window.setInterval(() => Events.pub('interval.5m'), 60000 * 5);
window.setInterval(() => Events.pub('interval.10m'), 60000 * 10);
window.setInterval(() => Events.pub('interval.15m'), 60000 * 15);
window.setInterval(() => Events.pub('interval.20m'), 60000 * 15);
window.setTimeout(() => window.setInterval(() => Events.pub('interval.2m-after5m'), 60000 * 2), 60000 * 5);
window.setTimeout(() => window.setInterval(() => Events.pub('interval.5m-after5m'), 60000 * 5), 60000 * 5);
window.setTimeout(() => window.setInterval(() => Events.pub('interval.10m-after5m'), 60000 * 10), 60000 * 5);
$.wakeUp(() => {
Remote.jsVersion((sResult, oData) => {
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Success === sResult && oData && !oData.Result)
{
2016-04-30 07:42:18 +08:00
if (window.parent && !!Settings.appSettingsGet('inIframe'))
2014-08-20 23:03:12 +08:00
{
window.parent.location.reload();
}
else
{
window.location.reload();
}
}
2016-04-30 07:42:18 +08:00
}, Settings.appSettingsGet('version'));
2014-08-20 23:03:12 +08:00
}, {}, 60 * 60 * 1000);
2014-08-22 23:08:56 +08:00
if (Settings.settingsGet('UserBackgroundHash'))
{
2015-11-19 01:32:29 +08:00
_.delay(() => {
2016-04-21 01:12:51 +08:00
$('#rl-bg')
.attr('style', 'background-image: none !important;')
.backstretch(Links.userBackground(Settings.settingsGet('UserBackgroundHash')), {
fade: Globals.bAnimationSupported ? 1000 : 0,
centeredX: true,
centeredY: true
})
.removeAttr('style')
;
2015-02-05 13:14:13 +08:00
}, 1000);
}
2014-08-22 23:08:56 +08:00
this.socialUsers = _.bind(this.socialUsers, this);
}
2015-11-19 01:32:29 +08:00
remote() {
2014-08-22 23:08:56 +08:00
return Remote;
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
reloadFlagsCurrentMessageListAndMessageFromCache() {
_.each(MessageStore.messageList(), (message) => {
Cache.initMessageFlagsFromCache(message);
2014-08-20 23:03:12 +08:00
});
2015-02-22 06:00:51 +08:00
Cache.initMessageFlagsFromCache(MessageStore.message());
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
/**
* @param {boolean=} bDropPagePosition = false
* @param {boolean=} bDropCurrenFolderCache = false
*/
2015-11-19 01:32:29 +08:00
reloadMessageList(bDropPagePosition = false, bDropCurrenFolderCache = false) {
let
2015-02-22 06:00:51 +08:00
iOffset = (MessageStore.messageListPage() - 1) * SettingsStore.messagesPerPage()
2014-08-20 23:03:12 +08:00
;
2015-11-19 01:32:29 +08:00
if (bDropCurrenFolderCache)
{
2015-02-22 06:00:51 +08:00
Cache.setFolderHash(FolderStore.currentFolderFullNameRaw(), '');
}
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
if (bDropPagePosition)
{
2015-02-22 06:00:51 +08:00
MessageStore.messageListPage(1);
2015-04-22 05:01:29 +08:00
MessageStore.messageListPageBeforeThread(1);
2014-08-20 23:03:12 +08:00
iOffset = 0;
2015-04-22 05:01:29 +08:00
kn.setHash(Links.mailBox(
FolderStore.currentFolderFullNameHash(),
MessageStore.messageListPage(),
MessageStore.messageListSearch(),
MessageStore.messageListThreadUid()
), true, true);
}
2015-02-22 06:00:51 +08:00
MessageStore.messageListLoading(true);
2015-11-19 01:32:29 +08:00
Remote.messageList((sResult, oData, bCached) => {
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
2015-02-22 06:00:51 +08:00
MessageStore.messageListError('');
MessageStore.messageListLoading(false);
MessageStore.setMessageList(oData, bCached);
2014-08-20 23:03:12 +08:00
}
else if (Enums.StorageResultType.Unload === sResult)
{
2015-02-22 06:00:51 +08:00
MessageStore.messageListError('');
MessageStore.messageListLoading(false);
2014-08-20 23:03:12 +08:00
}
else if (Enums.StorageResultType.Abort !== sResult)
{
2015-02-22 06:00:51 +08:00
MessageStore.messageList([]);
MessageStore.messageListLoading(false);
MessageStore.messageListError(oData && oData.ErrorCode ?
Translator.getNotification(oData.ErrorCode) : Translator.i18n('NOTIFICATIONS/CANT_GET_MESSAGE_LIST')
2014-08-20 23:03:12 +08:00
);
}
2015-04-21 03:49:51 +08:00
}, FolderStore.currentFolderFullNameRaw(), iOffset, SettingsStore.messagesPerPage(),
MessageStore.messageListSearch(), MessageStore.messageListThreadUid());
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
recacheInboxMessageList() {
2015-04-21 03:49:51 +08:00
Remote.messageList(Utils.emptyFunction, Cache.getFolderInboxName(), 0, SettingsStore.messagesPerPage(), '', '', true);
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
/**
* @param {Function} fResultFunc
2015-04-14 02:45:09 +08:00
* @return {boolean}
2014-08-20 23:03:12 +08:00
*/
2015-11-19 01:32:29 +08:00
contactsSync(fResultFunc) {
const oContacts = ContactStore.contacts;
2015-02-22 06:00:51 +08:00
if (oContacts.importing() || oContacts.syncing() || !ContactStore.enableContactsSync() || !ContactStore.allowContactsSync())
{
2014-08-20 23:03:12 +08:00
return false;
}
2014-08-20 23:03:12 +08:00
oContacts.syncing(true);
2015-11-19 01:32:29 +08:00
Remote.contactsSync((sResult, oData) => {
2014-08-20 23:03:12 +08:00
oContacts.syncing(false);
2014-08-20 23:03:12 +08:00
if (fResultFunc)
{
fResultFunc(sResult, oData);
}
});
2014-08-20 23:03:12 +08:00
return true;
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
messagesMoveTrigger() {
const
2015-06-05 02:02:31 +08:00
sTrashFolder = FolderStore.trashFolder(),
2015-02-03 07:58:58 +08:00
sSpamFolder = FolderStore.spamFolder()
2014-08-20 23:03:12 +08:00
;
2015-11-19 01:32:29 +08:00
_.each(this.oMoveCache, (oItem) => {
2014-08-20 23:03:12 +08:00
var
2016-04-21 01:12:51 +08:00
bSpam = sSpamFolder === oItem.To,
bTrash = sTrashFolder === oItem.To,
bHam = !bSpam && sSpamFolder === oItem.From && Cache.getFolderInboxName() === oItem.To
2014-08-20 23:03:12 +08:00
;
2014-03-20 00:18:28 +08:00
2016-04-21 01:12:51 +08:00
Remote.messagesMove(this.moveOrDeleteResponseHelper, oItem.From, oItem.To, oItem.Uid,
2015-06-05 02:02:31 +08:00
bSpam ? 'SPAM' : (bHam ? 'HAM' : ''), bSpam || bTrash);
2014-08-20 23:03:12 +08:00
});
2014-03-20 00:18:28 +08:00
2014-08-20 23:03:12 +08:00
this.oMoveCache = {};
2015-11-19 01:32:29 +08:00
}
messagesMoveHelper(sFromFolderFullNameRaw, sToFolderFullNameRaw, aUidForMove) {
2014-08-20 23:03:12 +08:00
var sH = '$$' + sFromFolderFullNameRaw + '$$' + sToFolderFullNameRaw + '$$';
if (!this.oMoveCache[sH])
2014-03-20 00:18:28 +08:00
{
2014-08-20 23:03:12 +08:00
this.oMoveCache[sH] = {
2016-04-21 01:12:51 +08:00
From: sFromFolderFullNameRaw,
To: sToFolderFullNameRaw,
Uid: []
2014-08-20 23:03:12 +08:00
};
2014-03-20 00:18:28 +08:00
}
2016-04-21 01:12:51 +08:00
this.oMoveCache[sH].Uid = _.union(this.oMoveCache[sH].Uid, aUidForMove);
2014-08-20 23:03:12 +08:00
this.messagesMoveTrigger();
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
messagesCopyHelper(sFromFolderFullNameRaw, sToFolderFullNameRaw, aUidForCopy) {
2014-08-21 23:08:34 +08:00
Remote.messagesCopy(
2014-08-20 23:03:12 +08:00
this.moveOrDeleteResponseHelper,
sFromFolderFullNameRaw,
sToFolderFullNameRaw,
aUidForCopy
);
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
messagesDeleteHelper(sFromFolderFullNameRaw, aUidForRemove) {
2014-08-21 23:08:34 +08:00
Remote.messagesDelete(
2014-08-20 23:03:12 +08:00
this.moveOrDeleteResponseHelper,
sFromFolderFullNameRaw,
aUidForRemove
);
2015-11-19 01:32:29 +08:00
}
moveOrDeleteResponseHelper(sResult, oData) {
2014-08-20 23:03:12 +08:00
2015-02-22 06:00:51 +08:00
if (Enums.StorageResultType.Success === sResult && FolderStore.currentFolder())
2014-03-20 00:18:28 +08:00
{
2014-08-20 23:03:12 +08:00
if (oData && Utils.isArray(oData.Result) && 2 === oData.Result.length)
{
2014-08-21 23:08:34 +08:00
Cache.setFolderHash(oData.Result[0], oData.Result[1]);
}
else
{
2015-02-22 06:00:51 +08:00
Cache.setFolderHash(FolderStore.currentFolderFullNameRaw(), '');
2014-08-20 23:03:12 +08:00
if (oData && -1 < Utils.inArray(oData.ErrorCode,
[Enums.Notification.CantMoveMessage, Enums.Notification.CantCopyMessage]))
{
window.alert(Translator.getNotification(oData.ErrorCode));
2014-08-20 23:03:12 +08:00
}
}
2014-03-20 00:18:28 +08:00
2015-04-07 03:32:19 +08:00
this.reloadMessageList(0 === MessageStore.messageList().length);
2014-08-22 23:08:56 +08:00
this.quotaDebounce();
2014-03-20 00:18:28 +08:00
}
2015-11-19 01:32:29 +08:00
}
2014-03-20 00:18:28 +08:00
2014-08-20 23:03:12 +08:00
/**
* @param {string} sFromFolderFullNameRaw
* @param {Array} aUidForRemove
*/
2015-11-19 01:32:29 +08:00
deleteMessagesFromFolderWithoutCheck(sFromFolderFullNameRaw, aUidForRemove) {
2014-08-20 23:03:12 +08:00
this.messagesDeleteHelper(sFromFolderFullNameRaw, aUidForRemove);
2015-02-22 06:00:51 +08:00
MessageStore.removeMessagesFromList(sFromFolderFullNameRaw, aUidForRemove);
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
/**
* @param {number} iDeleteType
* @param {string} sFromFolderFullNameRaw
* @param {Array} aUidForRemove
* @param {boolean=} bUseFolder = true
*/
2015-11-19 01:32:29 +08:00
deleteMessagesFromFolder(iDeleteType, sFromFolderFullNameRaw, aUidForRemove, bUseFolder) {
let
2014-08-20 23:03:12 +08:00
oMoveFolder = null,
nSetSystemFoldersNotification = null
;
2014-03-20 00:18:28 +08:00
2014-08-20 23:03:12 +08:00
switch (iDeleteType)
{
case Enums.FolderType.Spam:
2015-02-03 07:58:58 +08:00
oMoveFolder = Cache.getFolderFromCacheList(FolderStore.spamFolder());
2014-08-20 23:03:12 +08:00
nSetSystemFoldersNotification = Enums.SetSystemFoldersNotification.Spam;
break;
case Enums.FolderType.NotSpam:
oMoveFolder = Cache.getFolderFromCacheList(Cache.getFolderInboxName());
2014-08-20 23:03:12 +08:00
break;
case Enums.FolderType.Trash:
2015-02-03 07:58:58 +08:00
oMoveFolder = Cache.getFolderFromCacheList(FolderStore.trashFolder());
2014-08-20 23:03:12 +08:00
nSetSystemFoldersNotification = Enums.SetSystemFoldersNotification.Trash;
break;
case Enums.FolderType.Archive:
2015-02-03 07:58:58 +08:00
oMoveFolder = Cache.getFolderFromCacheList(FolderStore.archiveFolder());
2014-08-20 23:03:12 +08:00
nSetSystemFoldersNotification = Enums.SetSystemFoldersNotification.Archive;
break;
}
2014-08-20 23:03:12 +08:00
bUseFolder = Utils.isUnd(bUseFolder) ? true : !!bUseFolder;
if (bUseFolder)
{
2015-11-15 08:23:16 +08:00
if ((Enums.FolderType.Spam === iDeleteType && Consts.UNUSED_OPTION_VALUE === FolderStore.spamFolder()) ||
(Enums.FolderType.Trash === iDeleteType && Consts.UNUSED_OPTION_VALUE === FolderStore.trashFolder()) ||
(Enums.FolderType.Archive === iDeleteType && Consts.UNUSED_OPTION_VALUE === FolderStore.archiveFolder()))
{
2014-08-20 23:03:12 +08:00
bUseFolder = false;
}
}
2014-08-20 23:03:12 +08:00
if (!oMoveFolder && bUseFolder)
{
kn.showScreenPopup(require('View/Popup/FolderSystem'), [nSetSystemFoldersNotification]);
}
2014-08-20 23:03:12 +08:00
else if (!bUseFolder || (Enums.FolderType.Trash === iDeleteType &&
2015-02-03 07:58:58 +08:00
(sFromFolderFullNameRaw === FolderStore.spamFolder() || sFromFolderFullNameRaw === FolderStore.trashFolder())))
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
kn.showScreenPopup(require('View/Popup/Ask'), [Translator.i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'), () => {
this.messagesDeleteHelper(sFromFolderFullNameRaw, aUidForRemove);
2015-02-22 06:00:51 +08:00
MessageStore.removeMessagesFromList(sFromFolderFullNameRaw, aUidForRemove);
2014-08-20 23:03:12 +08:00
}]);
}
else if (oMoveFolder)
{
this.messagesMoveHelper(sFromFolderFullNameRaw, oMoveFolder.fullNameRaw, aUidForRemove);
2015-02-22 06:00:51 +08:00
MessageStore.removeMessagesFromList(sFromFolderFullNameRaw, aUidForRemove, oMoveFolder.fullNameRaw);
2014-08-20 23:03:12 +08:00
}
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
/**
* @param {string} sFromFolderFullNameRaw
* @param {Array} aUidForMove
* @param {string} sToFolderFullNameRaw
* @param {boolean=} bCopy = false
*/
2015-11-19 01:32:29 +08:00
moveMessagesToFolder(sFromFolderFullNameRaw, aUidForMove, sToFolderFullNameRaw, bCopy) {
2014-08-20 23:03:12 +08:00
if (sFromFolderFullNameRaw !== sToFolderFullNameRaw && Utils.isArray(aUidForMove) && 0 < aUidForMove.length)
{
2015-11-19 01:32:29 +08:00
const
2014-08-21 23:08:34 +08:00
oFromFolder = Cache.getFolderFromCacheList(sFromFolderFullNameRaw),
oToFolder = Cache.getFolderFromCacheList(sToFolderFullNameRaw)
2014-08-20 23:03:12 +08:00
;
2014-08-20 23:03:12 +08:00
if (oFromFolder && oToFolder)
{
2014-08-20 23:03:12 +08:00
if (Utils.isUnd(bCopy) ? false : !!bCopy)
2014-03-21 07:47:13 +08:00
{
2014-08-20 23:03:12 +08:00
this.messagesCopyHelper(oFromFolder.fullNameRaw, oToFolder.fullNameRaw, aUidForMove);
}
else
{
this.messagesMoveHelper(oFromFolder.fullNameRaw, oToFolder.fullNameRaw, aUidForMove);
2014-03-21 07:47:13 +08:00
}
2015-02-22 06:00:51 +08:00
MessageStore.removeMessagesFromList(oFromFolder.fullNameRaw, aUidForMove, oToFolder.fullNameRaw, bCopy);
2014-08-20 23:03:12 +08:00
return true;
}
}
2014-08-20 23:03:12 +08:00
return false;
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
/**
2015-11-19 01:32:29 +08:00
* @param {Function=} callback = null
2014-08-20 23:03:12 +08:00
*/
2015-11-19 01:32:29 +08:00
foldersReload(callback = null) {
Promises.foldersReload(FolderStore.foldersLoading).then((value) => {
if (callback)
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
callback(!!value);
2014-08-20 23:03:12 +08:00
}
2015-11-19 01:32:29 +08:00
}).fail(() => {
if (callback)
2014-08-20 23:03:12 +08:00
{
2016-05-01 09:07:10 +08:00
_.delay(() => callback(false), 1);
2014-08-20 23:03:12 +08:00
}
});
2015-11-19 01:32:29 +08:00
}
foldersPromisesActionHelper(promise, errorDefCode) {
Promises
.abort('Folders')
.fastResolve(true)
2015-11-19 01:32:29 +08:00
.then(() => promise)
.fail((errorCode) => {
FolderStore.folderList.error(Translator.getNotification(errorCode, '', errorDefCode));
}).fin(() => {
Promises.foldersReloadWithTimeout(FolderStore.foldersLoading);
}).done()
;
2015-11-19 01:32:29 +08:00
}
reloadOpenPgpKeys() {
2015-02-03 07:58:58 +08:00
if (PgpStore.capaOpenPGP())
{
var
2014-08-20 23:03:12 +08:00
aKeys = [],
oEmail = new EmailModel(),
2015-02-03 07:58:58 +08:00
oOpenpgpKeyring = PgpStore.openpgpKeyring,
2014-08-20 23:03:12 +08:00
oOpenpgpKeys = oOpenpgpKeyring ? oOpenpgpKeyring.getAllKeys() : []
;
2015-11-19 01:32:29 +08:00
_.each(oOpenpgpKeys, (oItem, iIndex) => {
2014-08-20 23:03:12 +08:00
if (oItem && oItem.primaryKey)
{
var
aEmails = [],
aUsers = [],
2014-08-20 23:03:12 +08:00
oPrimaryUser = oItem.getPrimaryUser(),
sUser = (oPrimaryUser && oPrimaryUser.user) ? oPrimaryUser.user.userId.userid
: (oItem.users && oItem.users[0] ? oItem.users[0].userId.userid : '')
;
if (oItem.users) {
2016-04-21 01:12:51 +08:00
_.each(oItem.users, (item) => {
oEmail.clear();
2016-04-21 01:12:51 +08:00
oEmail.mailsoParse(item.userId.userid);
if (oEmail.validate())
{
aEmails.push(oEmail.email);
2016-04-21 01:12:51 +08:00
aUsers.push(item.userId.userid);
}
});
}
if (aEmails.length)
2014-08-20 23:03:12 +08:00
{
aKeys.push(new OpenPgpKeyModel(
iIndex,
oItem.primaryKey.getFingerprint(),
oItem.primaryKey.getKeyId().toHex().toLowerCase(),
_.uniq(_.compact(_.map(oItem.getKeyIds(), (item) => item && item.toHex ? item.toHex() : null))),
aUsers,
aEmails,
2014-08-20 23:03:12 +08:00
oItem.isPrivate(),
oItem.armor(),
sUser)
2014-08-20 23:03:12 +08:00
);
}
}
});
2015-02-03 07:58:58 +08:00
Utils.delegateRunOnDestroy(PgpStore.openpgpkeys());
PgpStore.openpgpkeys(aKeys);
}
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
accountsCounts() {
2015-02-03 07:58:58 +08:00
return false;
// AccountStore.accounts.loading(true);
//
2015-11-19 01:32:29 +08:00
// Remote.accountsCounts((sResult, oData) => {
2015-02-03 07:58:58 +08:00
//
// AccountStore.accounts.loading(false);
//
// if (Enums.StorageResultType.Success === sResult && oData.Result && oData.Result['Counts'])
// {
// var
// sEmail = AccountStore.email(),
// aAcounts = AccountStore.accounts()
// ;
//
2015-11-19 01:32:29 +08:00
// _.each(oData.Result['Counts'], (oItem) => {
2015-02-03 07:58:58 +08:00
//
2015-11-19 01:32:29 +08:00
// var oAccount = _.find(aAcounts, (oAccount) => {
2015-02-03 07:58:58 +08:00
// return oAccount && oItem[0] === oAccount.email && sEmail !== oAccount.email;
// });
//
// if (oAccount)
// {
// oAccount.count(Utils.pInt(oItem[1]));
// }
// });
// }
// });
2016-04-21 01:12:51 +08:00
}
2015-11-19 01:32:29 +08:00
accountsAndIdentities(bBoot) {
AccountStore.accounts.loading(true);
2015-01-29 05:24:58 +08:00
IdentityStore.identities.loading(true);
2015-11-19 01:32:29 +08:00
Remote.accountsAndIdentities((sResult, oData) => {
AccountStore.accounts.loading(false);
2015-01-29 05:24:58 +08:00
IdentityStore.identities.loading(false);
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Success === sResult && oData.Result)
{
var
aCounts = {},
2014-08-27 23:59:44 +08:00
sParentEmail = Settings.settingsGet('ParentEmail'),
2015-02-03 07:58:58 +08:00
sAccountEmail = AccountStore.email()
2014-08-20 23:03:12 +08:00
;
2013-12-07 06:45:46 +08:00
2014-08-20 23:03:12 +08:00
sParentEmail = '' === sParentEmail ? sAccountEmail : sParentEmail;
2016-04-21 01:12:51 +08:00
if (Utils.isArray(oData.Result.Accounts))
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
_.each(AccountStore.accounts(), (oAccount) => {
aCounts[oAccount.email] = oAccount.count();
});
Utils.delegateRunOnDestroy(AccountStore.accounts());
2016-04-21 01:12:51 +08:00
AccountStore.accounts(_.map(oData.Result.Accounts,
2015-11-19 01:32:29 +08:00
(sValue) => new AccountModel(sValue, sValue !== sParentEmail, aCounts[sValue] || 0)));
2014-08-20 23:03:12 +08:00
}
if (Utils.isUnd(bBoot) ? false : !!bBoot)
{
2015-11-19 01:32:29 +08:00
_.delay(() => this.accountsCounts(), 1000 * 5);
Events.sub('interval.10m-after5m', () => this.accountsCounts());
}
2016-04-21 01:12:51 +08:00
if (Utils.isArray(oData.Result.Identities))
2014-08-20 23:03:12 +08:00
{
2015-01-29 05:24:58 +08:00
Utils.delegateRunOnDestroy(IdentityStore.identities());
2016-04-21 01:12:51 +08:00
IdentityStore.identities(_.map(oData.Result.Identities, (oIdentityData) => {
2013-12-07 06:45:46 +08:00
2015-11-19 01:32:29 +08:00
const
2016-04-21 01:12:51 +08:00
sId = Utils.pString(oIdentityData.Id),
sEmail = Utils.pString(oIdentityData.Email),
oIdentity = new IdentityModel(sId, sEmail)
2014-08-20 23:03:12 +08:00
;
2013-12-07 06:45:46 +08:00
2016-04-21 01:12:51 +08:00
oIdentity.name(Utils.pString(oIdentityData.Name));
oIdentity.replyTo(Utils.pString(oIdentityData.ReplyTo));
oIdentity.bcc(Utils.pString(oIdentityData.Bcc));
oIdentity.signature(Utils.pString(oIdentityData.Signature));
oIdentity.signatureInsertBefore(!!oIdentityData.SignatureInsertBefore);
2013-12-07 06:45:46 +08:00
2014-08-20 23:03:12 +08:00
return oIdentity;
}));
}
}
2014-08-20 23:03:12 +08:00
});
2015-11-19 01:32:29 +08:00
}
templates() {
TemplateStore.templates.loading(true);
2015-11-19 01:32:29 +08:00
Remote.templates((result, data) => {
TemplateStore.templates.loading(false);
2015-11-19 01:32:29 +08:00
if (Enums.StorageResultType.Success === result && data.Result &&
2016-04-21 01:12:51 +08:00
Utils.isArray(data.Result.Templates))
{
Utils.delegateRunOnDestroy(TemplateStore.templates());
2016-04-21 01:12:51 +08:00
TemplateStore.templates(_.compact(_.map(data.Result.Templates, (templateData) => {
2015-11-19 01:32:29 +08:00
const template = new TemplateModel();
return template.parse(templateData) ? template : null;
})));
}
});
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
quota() {
Remote.quota((result, data) => {
if (Enums.StorageResultType.Success === result && data && data.Result &&
Utils.isArray(data.Result) && 1 < data.Result.length &&
Utils.isPosNumeric(data.Result[0], true) && Utils.isPosNumeric(data.Result[1], true))
{
require('Stores/User/Quota').populateData(
2015-11-19 01:32:29 +08:00
Utils.pInt(data.Result[1]), Utils.pInt(data.Result[0]));
2014-08-20 23:03:12 +08:00
}
});
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
/**
2015-11-19 01:32:29 +08:00
* @param {string} folder
* @param {Array=} list = []
2014-08-20 23:03:12 +08:00
*/
2015-11-19 01:32:29 +08:00
folderInformation(folder, list) {
if ('' !== Utils.trim(folder))
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
Remote.folderInformation((result, data) => {
if (Enums.StorageResultType.Success === result)
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
if (data && data.Result && data.Result.Hash && data.Result.Folder)
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
let
uid = '',
check = false,
unreadCountChange = false
;
2016-04-21 01:12:51 +08:00
const folderFromCache = Cache.getFolderFromCacheList(data.Result.Folder);
if (folderFromCache)
{
2016-04-21 01:12:51 +08:00
folderFromCache.interval = Momentor.momentNowUnix();
2015-11-19 01:32:29 +08:00
if (data.Result.Hash)
{
2015-11-19 01:32:29 +08:00
Cache.setFolderHash(data.Result.Folder, data.Result.Hash);
}
2015-11-19 01:32:29 +08:00
if (Utils.isNormal(data.Result.MessageCount))
{
2016-04-21 01:12:51 +08:00
folderFromCache.messageCountAll(data.Result.MessageCount);
}
2015-11-19 01:32:29 +08:00
if (Utils.isNormal(data.Result.MessageUnseenCount))
{
2016-04-21 01:12:51 +08:00
if (Utils.pInt(folderFromCache.messageCountUnread()) !== Utils.pInt(data.Result.MessageUnseenCount))
{
2015-11-19 01:32:29 +08:00
unreadCountChange = true;
}
2016-04-21 01:12:51 +08:00
folderFromCache.messageCountUnread(data.Result.MessageUnseenCount);
}
2015-11-19 01:32:29 +08:00
if (unreadCountChange)
{
2016-04-21 01:12:51 +08:00
Cache.clearMessageFlagsFromCacheByFolder(folderFromCache.fullNameRaw);
}
2015-11-19 01:32:29 +08:00
if (data.Result.Flags)
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
for (uid in data.Result.Flags)
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
if (data.Result.Flags.hasOwnProperty(uid))
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
check = true;
const flags = data.Result.Flags[uid];
2016-04-21 01:12:51 +08:00
Cache.storeMessageFlagsToCacheByFolderAndUid(folderFromCache.fullNameRaw, uid.toString(), [
!flags.IsSeen, !!flags.IsFlagged, !!flags.IsAnswered, !!flags.IsForwarded, !!flags.IsReadReceipt
2014-08-20 23:03:12 +08:00
]);
}
}
2015-11-19 01:32:29 +08:00
if (check)
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
this.reloadFlagsCurrentMessageListAndMessageFromCache();
2014-08-20 23:03:12 +08:00
}
}
2016-04-21 01:12:51 +08:00
MessageStore.initUidNextAndNewMessages(folderFromCache.fullNameRaw, data.Result.UidNext, data.Result.NewMessages);
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
const hash = Cache.getFolderHash(data.Result.Folder);
2016-01-05 00:47:02 +08:00
if (data.Result.Hash !== hash || '' === hash || unreadCountChange)
{
2016-04-21 01:12:51 +08:00
if (folderFromCache.fullNameRaw === FolderStore.currentFolderFullNameRaw())
{
2015-11-19 01:32:29 +08:00
this.reloadMessageList();
}
2016-04-21 01:12:51 +08:00
else if (Cache.getFolderInboxName() === folderFromCache.fullNameRaw)
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
this.recacheInboxMessageList();
2014-08-20 23:03:12 +08:00
}
}
}
}
}
2015-11-19 01:32:29 +08:00
}, folder, list);
2014-08-20 23:03:12 +08:00
}
2016-04-21 01:12:51 +08:00
}
2014-08-20 23:03:12 +08:00
/**
2015-11-19 01:32:29 +08:00
* @param {boolean=} boot = false
2014-08-20 23:03:12 +08:00
*/
2015-11-19 01:32:29 +08:00
folderInformationMultiply(boot = false) {
2015-11-19 01:32:29 +08:00
const folders = FolderStore.getNextFolderNames();
if (Utils.isNonEmptyArray(folders))
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
Remote.folderInformationMultiply((sResult, oData) => {
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Success === sResult)
{
if (oData && oData.Result && oData.Result.List && Utils.isNonEmptyArray(oData.Result.List))
{
2015-11-19 01:32:29 +08:00
const utc = Momentor.momentNowUnix();
_.each(oData.Result.List, (oItem) => {
2014-08-20 23:03:12 +08:00
var
2014-08-21 23:08:34 +08:00
sHash = Cache.getFolderHash(oItem.Folder),
oFolder = Cache.getFolderFromCacheList(oItem.Folder),
2014-08-20 23:03:12 +08:00
bUnreadCountChange = false
;
2014-08-20 23:03:12 +08:00
if (oFolder)
{
2015-11-19 01:32:29 +08:00
oFolder.interval = utc;
2014-08-20 23:03:12 +08:00
if (oItem.Hash)
{
2014-08-21 23:08:34 +08:00
Cache.setFolderHash(oItem.Folder, oItem.Hash);
2014-08-20 23:03:12 +08:00
}
2014-08-20 23:03:12 +08:00
if (Utils.isNormal(oItem.MessageCount))
{
oFolder.messageCountAll(oItem.MessageCount);
}
2014-08-20 23:03:12 +08:00
if (Utils.isNormal(oItem.MessageUnseenCount))
{
if (Utils.pInt(oFolder.messageCountUnread()) !== Utils.pInt(oItem.MessageUnseenCount))
{
bUnreadCountChange = true;
}
2014-08-20 23:03:12 +08:00
oFolder.messageCountUnread(oItem.MessageUnseenCount);
}
2014-08-20 23:03:12 +08:00
if (bUnreadCountChange)
{
2014-08-21 23:08:34 +08:00
Cache.clearMessageFlagsFromCacheByFolder(oFolder.fullNameRaw);
2014-08-20 23:03:12 +08:00
}
2014-08-20 23:03:12 +08:00
if (oItem.Hash !== sHash || '' === sHash)
{
2015-02-22 06:00:51 +08:00
if (oFolder.fullNameRaw === FolderStore.currentFolderFullNameRaw())
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
this.reloadMessageList();
2014-08-20 23:03:12 +08:00
}
}
else if (bUnreadCountChange)
{
2015-02-22 06:00:51 +08:00
if (oFolder.fullNameRaw === FolderStore.currentFolderFullNameRaw())
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
const aList = MessageStore.messageList();
2014-08-20 23:03:12 +08:00
if (Utils.isNonEmptyArray(aList))
{
2015-11-19 01:32:29 +08:00
this.folderInformation(oFolder.fullNameRaw, aList);
2014-08-20 23:03:12 +08:00
}
}
}
}
});
2015-11-19 01:32:29 +08:00
if (boot)
2015-04-26 06:01:56 +08:00
{
2015-11-19 01:32:29 +08:00
_.delay(() => this.folderInformationMultiply(true), 2000);
2014-08-20 23:03:12 +08:00
}
}
}
2015-11-19 01:32:29 +08:00
}, folders);
}
2016-04-21 01:12:51 +08:00
}
2014-08-20 23:03:12 +08:00
2015-03-06 08:42:40 +08:00
/**
* @param {string} sFolderFullNameRaw
* @param {string|bool} mUid
* @param {number} iSetAction
* @param {Array=} aMessages = null
*/
2015-11-19 01:32:29 +08:00
messageListAction(sFolderFullNameRaw, mUid, iSetAction, aMessages) {
2015-03-06 08:42:40 +08:00
var
oFolder = null,
2015-04-22 05:01:29 +08:00
aRootUids = [],
2015-03-06 08:42:40 +08:00
iAlreadyUnread = 0
;
if (Utils.isUnd(aMessages))
{
2015-03-06 08:42:40 +08:00
aMessages = MessageStore.messageListChecked();
}
2015-11-19 01:32:29 +08:00
aRootUids = _.uniq(_.compact(_.map(aMessages, (oMessage) => (oMessage && oMessage.uid) ? oMessage.uid : null)));
2015-03-06 08:42:40 +08:00
2015-04-22 05:01:29 +08:00
if ('' !== sFolderFullNameRaw && 0 < aRootUids.length)
2015-03-06 08:42:40 +08:00
{
switch (iSetAction) {
case Enums.MessageSetAction.SetSeen:
2015-11-19 01:32:29 +08:00
_.each(aRootUids, (sSubUid) => {
2015-03-06 08:42:40 +08:00
iAlreadyUnread += Cache.storeMessageFlagsToCacheBySetAction(
sFolderFullNameRaw, sSubUid, iSetAction);
});
oFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw);
if (oFolder)
{
oFolder.messageCountUnread(oFolder.messageCountUnread() - iAlreadyUnread);
}
2015-04-22 05:01:29 +08:00
Remote.messageSetSeen(Utils.emptyFunction, sFolderFullNameRaw, aRootUids, true);
2015-03-06 08:42:40 +08:00
break;
case Enums.MessageSetAction.UnsetSeen:
2015-11-19 01:32:29 +08:00
_.each(aRootUids, (sSubUid) => {
2015-03-06 08:42:40 +08:00
iAlreadyUnread += Cache.storeMessageFlagsToCacheBySetAction(
sFolderFullNameRaw, sSubUid, iSetAction);
});
oFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw);
if (oFolder)
{
oFolder.messageCountUnread(oFolder.messageCountUnread() - iAlreadyUnread + aRootUids.length);
}
Remote.messageSetSeen(Utils.emptyFunction, sFolderFullNameRaw, aRootUids, false);
break;
case Enums.MessageSetAction.SetFlag:
2015-11-19 01:32:29 +08:00
_.each(aRootUids, (sSubUid) => {
2015-03-06 08:42:40 +08:00
Cache.storeMessageFlagsToCacheBySetAction(
sFolderFullNameRaw, sSubUid, iSetAction);
});
Remote.messageSetFlagged(Utils.emptyFunction, sFolderFullNameRaw, aRootUids, true);
break;
case Enums.MessageSetAction.UnsetFlag:
2015-11-19 01:32:29 +08:00
_.each(aRootUids, (sSubUid) => {
2015-03-06 08:42:40 +08:00
Cache.storeMessageFlagsToCacheBySetAction(
sFolderFullNameRaw, sSubUid, iSetAction);
});
2015-04-15 06:27:10 +08:00
Remote.messageSetFlagged(Utils.emptyFunction, sFolderFullNameRaw, aRootUids, false);
2015-03-06 08:42:40 +08:00
break;
2014-08-20 23:03:12 +08:00
}
2014-08-22 23:08:56 +08:00
this.reloadFlagsCurrentMessageListAndMessageFromCache();
2015-03-06 08:42:40 +08:00
MessageStore.message.viewTrigger(!MessageStore.message.viewTrigger());
2014-08-20 23:03:12 +08:00
}
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
googleConnect() {
2014-10-06 02:37:31 +08:00
window.open(Links.socialGoogle(), 'Google', 'left=200,top=100,width=650,height=600,menubar=no,status=no,resizable=yes,scrollbars=yes');
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
twitterConnect() {
2014-10-06 02:37:31 +08:00
window.open(Links.socialTwitter(), 'Twitter', 'left=200,top=100,width=650,height=350,menubar=no,status=no,resizable=yes,scrollbars=yes');
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
facebookConnect() {
2014-10-06 02:37:31 +08:00
window.open(Links.socialFacebook(), 'Facebook', 'left=200,top=100,width=650,height=335,menubar=no,status=no,resizable=yes,scrollbars=yes');
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
/**
2015-11-19 01:32:29 +08:00
* @param {boolean=} fireAllActions = false
2014-08-20 23:03:12 +08:00
*/
2015-11-19 01:32:29 +08:00
socialUsers(fireAllActions = false) {
if (true === fireAllActions)
{
SocialStore.google.loading(true);
SocialStore.facebook.loading(true);
SocialStore.twitter.loading(true);
2014-08-20 23:03:12 +08:00
}
2015-11-19 01:32:29 +08:00
Remote.socialUsers((result, data) => {
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
if (Enums.StorageResultType.Success === result && data && data.Result)
2014-04-27 05:53:37 +08:00
{
2016-04-21 01:12:51 +08:00
SocialStore.google.userName(data.Result.Google || '');
SocialStore.facebook.userName(data.Result.Facebook || '');
SocialStore.twitter.userName(data.Result.Twitter || '');
2014-04-27 05:53:37 +08:00
}
2014-08-20 23:03:12 +08:00
else
{
SocialStore.google.userName('');
SocialStore.facebook.userName('');
SocialStore.twitter.userName('');
2014-08-20 23:03:12 +08:00
}
SocialStore.google.loading(false);
SocialStore.facebook.loading(false);
SocialStore.twitter.loading(false);
2014-08-20 23:03:12 +08:00
});
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
googleDisconnect() {
SocialStore.google.loading(true);
2014-08-22 23:08:56 +08:00
Remote.googleDisconnect(this.socialUsers);
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
facebookDisconnect() {
SocialStore.facebook.loading(true);
2014-08-22 23:08:56 +08:00
Remote.facebookDisconnect(this.socialUsers);
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
twitterDisconnect() {
SocialStore.twitter.loading(true);
2014-08-22 23:08:56 +08:00
Remote.twitterDisconnect(this.socialUsers);
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
/**
2015-11-19 01:32:29 +08:00
* @param {string} query
* @param {Function} callback
2014-08-20 23:03:12 +08:00
*/
2015-11-19 01:32:29 +08:00
getAutocomplete(query, callback) {
Remote.suggestions((result, data) => {
if (Enums.StorageResultType.Success === result && data && Utils.isArray(data.Result))
2014-08-22 23:08:56 +08:00
{
callback(_.compact(_.map(data.Result,
2015-11-19 01:32:29 +08:00
(item) => item && item[0] ? new EmailModel(item[0], item[1]) : null)));
2014-08-22 23:08:56 +08:00
}
2015-11-19 01:32:29 +08:00
else if (Enums.StorageResultType.Abort !== result)
2014-08-22 23:08:56 +08:00
{
2015-11-19 01:32:29 +08:00
callback([]);
2014-08-22 23:08:56 +08:00
}
2015-11-19 01:32:29 +08:00
}, query);
}
2014-08-20 23:03:12 +08:00
2014-08-22 23:08:56 +08:00
/**
* @param {string} sFullNameHash
* @param {boolean} bExpanded
*/
2015-11-19 01:32:29 +08:00
setExpandedFolder(sFullNameHash, bExpanded) {
let aExpandedList = Local.get(Enums.ClientSideKeyName.ExpandedFolders);
2014-09-02 19:34:17 +08:00
if (!Utils.isArray(aExpandedList))
2014-08-22 23:08:56 +08:00
{
aExpandedList = [];
}
if (bExpanded)
{
aExpandedList.push(sFullNameHash);
aExpandedList = _.uniq(aExpandedList);
}
else
{
aExpandedList = _.without(aExpandedList, sFullNameHash);
}
2014-09-02 19:34:17 +08:00
Local.set(Enums.ClientSideKeyName.ExpandedFolders, aExpandedList);
2015-11-19 01:32:29 +08:00
}
initHorizontalLayoutResizer(sClientSideKeyName) {
2014-08-22 23:08:56 +08:00
2015-01-09 07:31:31 +08:00
var
iMinHeight = 200,
iMaxHeight = 500,
oTop = null,
oBottom = null,
2016-04-21 01:12:51 +08:00
fSetHeight = (height) => {
if (height)
{
if (oTop)
{
oTop.attr('style', 'height:' + height + 'px');
}
if (oBottom)
{
oBottom.attr('style', 'top:' + (55 /* top toolbar */ + height) + 'px');
}
}
},
2015-11-19 01:32:29 +08:00
fResizeCreateFunction = (event) => {
if (event && event.target)
{
2015-11-19 01:32:29 +08:00
var oResizableHandle = $(event.target).find('.ui-resizable-handle');
oResizableHandle
2015-11-19 01:32:29 +08:00
.on('mousedown', () => {
Globals.$html.addClass('rl-resizer');
})
2015-11-19 01:32:29 +08:00
.on('mouseup', () => {
Globals.$html.removeClass('rl-resizer');
})
;
}
},
2015-11-19 01:32:29 +08:00
fResizeStartFunction = () => {
Globals.$html.addClass('rl-resizer');
},
2015-11-19 01:32:29 +08:00
fResizeResizeFunction = _.debounce(() => {
Globals.$html.addClass('rl-resizer');
}, 500, true),
2015-11-19 01:32:29 +08:00
fResizeStopFunction = (oEvent, oObject) => {
Globals.$html.removeClass('rl-resizer');
2015-01-09 07:31:31 +08:00
if (oObject && oObject.size && oObject.size.height)
{
Local.set(sClientSideKeyName, oObject.size.height);
fSetHeight(oObject.size.height);
Utils.windowResize();
}
},
oOptions = {
2016-04-21 01:12:51 +08:00
helper: 'ui-resizable-helper-h',
minHeight: iMinHeight,
maxHeight: iMaxHeight,
handles: 's',
create: fResizeCreateFunction,
resize: fResizeResizeFunction,
start: fResizeStartFunction,
stop: fResizeStopFunction
2015-01-09 07:31:31 +08:00
},
2015-11-19 01:32:29 +08:00
fDisable = (bDisable) => {
2015-01-09 07:31:31 +08:00
if (bDisable)
{
if (oTop && oTop.hasClass('ui-resizable'))
{
oTop
.resizable('destroy')
.removeAttr('style')
;
}
if (oBottom)
{
oBottom.removeAttr('style');
}
}
else if (Globals.$html.hasClass('rl-bottom-preview-pane'))
{
oTop = $('.b-message-list-wrapper');
oBottom = $('.b-message-view-wrapper');
if (!oTop.hasClass('ui-resizable'))
{
oTop.resizable(oOptions);
}
2015-11-19 01:32:29 +08:00
const iHeight = Utils.pInt(Local.get(sClientSideKeyName)) || 300;
2015-01-09 07:31:31 +08:00
fSetHeight(iHeight > iMinHeight ? iHeight : iMinHeight);
}
}
;
fDisable(false);
2015-11-19 01:32:29 +08:00
Events.sub('layout', (layout) => {
fDisable(Enums.Layout.BottomPreview !== layout);
2015-01-09 07:31:31 +08:00
});
2016-04-21 01:12:51 +08:00
}
2015-01-09 07:31:31 +08:00
2015-11-19 01:32:29 +08:00
initVerticalLayoutResizer(sClientSideKeyName) {
2014-08-22 23:08:56 +08:00
var
iDisabledWidth = 60,
iMinWidth = 155,
2015-01-09 07:31:31 +08:00
oLeft = $('#rl-left'),
oRight = $('#rl-right'),
2014-08-22 23:08:56 +08:00
2014-09-02 19:34:17 +08:00
mLeftWidth = Local.get(sClientSideKeyName) || null,
2014-08-22 23:08:56 +08:00
2015-11-19 01:32:29 +08:00
fSetWidth = (iWidth) => {
2014-08-22 23:08:56 +08:00
if (iWidth)
{
2016-04-29 04:32:54 +08:00
Globals.leftPanelWidth(iWidth);
Globals.$html.removeClass('rl-resizer');
2014-08-22 23:08:56 +08:00
oLeft.css({
2016-04-21 01:12:51 +08:00
width: '' + iWidth + 'px'
2014-08-22 23:08:56 +08:00
});
oRight.css({
2016-04-21 01:12:51 +08:00
left: '' + iWidth + 'px'
2014-08-22 23:08:56 +08:00
});
}
},
2015-11-19 01:32:29 +08:00
fDisable = (bDisable) => {
2014-08-22 23:08:56 +08:00
if (bDisable)
{
oLeft.resizable('disable');
fSetWidth(iDisabledWidth);
}
else
{
oLeft.resizable('enable');
2014-09-02 19:34:17 +08:00
var iWidth = Utils.pInt(Local.get(sClientSideKeyName)) || iMinWidth;
2014-08-22 23:08:56 +08:00
fSetWidth(iWidth > iMinWidth ? iWidth : iMinWidth);
}
},
2016-04-29 04:32:54 +08:00
2015-11-19 01:32:29 +08:00
fResizeCreateFunction = (oEvent) => {
if (oEvent && oEvent.target)
{
2015-11-19 01:32:29 +08:00
$(oEvent.target).find('.ui-resizable-handle')
.on('mousedown', () => {
Globals.$html.addClass('rl-resizer');
})
2015-11-19 01:32:29 +08:00
.on('mouseup', () => {
Globals.$html.removeClass('rl-resizer');
})
;
}
},
2015-11-19 01:32:29 +08:00
fResizeResizeFunction = _.debounce(() => {
Globals.$html.addClass('rl-resizer');
}, 500, true),
2015-11-19 01:32:29 +08:00
fResizeStartFunction = () => {
Globals.$html.addClass('rl-resizer');
},
2015-11-19 01:32:29 +08:00
fResizeStopFunction = (oEvent, oObject) => {
Globals.$html.removeClass('rl-resizer');
2014-08-22 23:08:56 +08:00
if (oObject && oObject.size && oObject.size.width)
{
2014-09-02 19:34:17 +08:00
Local.set(sClientSideKeyName, oObject.size.width);
2014-08-22 23:08:56 +08:00
2016-04-29 04:32:54 +08:00
Globals.leftPanelWidth(oObject.size.width);
2014-08-22 23:08:56 +08:00
oRight.css({
2016-04-21 01:12:51 +08:00
left: '' + oObject.size.width + 'px'
2014-08-22 23:08:56 +08:00
});
2016-04-29 04:32:54 +08:00
oLeft.css({
position: '',
top: '',
left: '',
height: ''
});
2014-08-22 23:08:56 +08:00
}
}
;
if (null !== mLeftWidth)
{
fSetWidth(mLeftWidth > iMinWidth ? mLeftWidth : iMinWidth);
}
oLeft.resizable({
2016-04-21 01:12:51 +08:00
helper: 'ui-resizable-helper-w',
minWidth: iMinWidth,
maxWidth: 350,
handles: 'e',
create: fResizeCreateFunction,
resize: fResizeResizeFunction,
start: fResizeStartFunction,
stop: fResizeStopFunction
2014-08-22 23:08:56 +08:00
});
2015-11-19 01:32:29 +08:00
Events.sub('left-panel.off', () => {
2014-08-22 23:08:56 +08:00
fDisable(true);
});
2015-11-19 01:32:29 +08:00
Events.sub('left-panel.on', () => {
2014-08-22 23:08:56 +08:00
fDisable(false);
});
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
logout() {
Remote.logout(() => {
this.loginAndLogoutReload(false, true,
2015-02-19 03:52:52 +08:00
Settings.settingsGet('ParentEmail') && 0 < Settings.settingsGet('ParentEmail').length);
});
2016-04-21 01:12:51 +08:00
}
2015-02-19 03:52:52 +08:00
2015-11-19 01:32:29 +08:00
bootstartTwoFactorScreen() {
kn.showScreenPopup(require('View/Popup/TwoFactorConfiguration'), [true]);
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
bootstartWelcomePopup(url) {
kn.showScreenPopup(require('View/Popup/WelcomePage'), [url]);
}
bootstartLoginScreen() {
2015-04-10 06:05:49 +08:00
Globals.$html.removeClass('rl-user-auth').addClass('rl-user-no-auth');
2016-04-30 07:42:18 +08:00
const customLoginLink = Utils.pString(Settings.appSettingsGet('customLoginLink'));
2015-11-19 01:32:29 +08:00
if (!customLoginLink)
2014-08-27 23:59:44 +08:00
{
kn.startScreens([
2014-10-18 21:43:44 +08:00
require('Screen/User/Login')
2014-08-27 23:59:44 +08:00
]);
Plugins.runHook('rl-start-login-screens');
Events.pub('rl.bootstart-login-screens');
}
else
{
kn.routeOff();
2014-10-06 02:37:31 +08:00
kn.setHash(Links.root(), true);
2014-08-27 23:59:44 +08:00
kn.routeOff();
_.defer(function () {
2015-11-19 01:32:29 +08:00
window.location.href = customLoginLink;
2014-08-27 23:59:44 +08:00
});
}
2015-11-19 01:32:29 +08:00
}
2014-08-27 23:59:44 +08:00
2015-11-19 01:32:29 +08:00
bootend() {
2015-06-05 02:02:31 +08:00
if (progressJs)
{
kn.hideLoading();
progressJs.set(100).end();
}
else
{
kn.hideLoading();
}
2016-04-21 01:12:51 +08:00
}
2015-11-19 01:32:29 +08:00
bootstart() {
super.bootstart();
require('Stores/User/App').populate();
require('Stores/User/Settings').populate();
require('Stores/User/Notification').populate();
2015-02-03 07:58:58 +08:00
require('Stores/User/Account').populate();
require('Stores/User/Contact').populate();
2014-08-20 23:03:12 +08:00
var
2016-04-30 07:42:18 +08:00
sJsHash = Settings.appSettingsGet('jsHash'),
sStartupUrl = Utils.pString(Settings.settingsGet('StartupUrl')),
2014-08-27 23:59:44 +08:00
iContactsSyncInterval = Utils.pInt(Settings.settingsGet('ContactsSyncInterval')),
bGoogle = Settings.settingsGet('AllowGoogleSocial'),
bFacebook = Settings.settingsGet('AllowFacebookSocial'),
bTwitter = Settings.settingsGet('AllowTwitterSocial')
2014-08-20 23:03:12 +08:00
;
2015-06-05 02:02:31 +08:00
if (progressJs)
2014-08-20 23:03:12 +08:00
{
progressJs.set(90);
2014-08-20 23:03:12 +08:00
}
2015-11-19 01:32:29 +08:00
Globals.leftPanelDisabled.subscribe((value) => {
Events.pub('left-panel.' + (value ? 'off' : 'on'));
2014-08-22 23:08:56 +08:00
});
this.setWindowTitle('');
2016-04-21 01:12:51 +08:00
if (Settings.settingsGet('Auth'))
2014-08-20 23:03:12 +08:00
{
Globals.$html.addClass('rl-user-auth');
if (Settings.capa(Enums.Capa.TwoFactor) &&
Settings.capa(Enums.Capa.TwoFactorForce) &&
Settings.settingsGet('RequireTwoFactor'))
{
this.bootend();
this.bootstartTwoFactorScreen();
}
else
{
this.setWindowTitle(Translator.i18n('TITLES/LOADING'));
2014-08-20 23:03:12 +08:00
2016-04-21 01:12:51 +08:00
// require.ensure([], function() { // require code splitting
2015-11-19 01:32:29 +08:00
this.foldersReload((value) => {
2014-01-28 05:34:54 +08:00
this.bootend();
2015-11-19 01:32:29 +08:00
if (value)
{
if ('' !== sStartupUrl)
{
kn.routeOff();
kn.setHash(Links.root(sStartupUrl), true);
kn.routeOn();
}
2016-05-21 06:46:56 +08:00
if (window.jassl && window.crypto && window.crypto.getRandomValues && Settings.capa(Enums.Capa.OpenPGP))
{
2015-11-19 01:32:29 +08:00
const openpgpCallback = (openpgp) => {
2015-07-06 02:06:19 +08:00
PgpStore.openpgp = openpgp;
2015-07-06 02:06:19 +08:00
if (window.Worker)
{
try
{
2016-05-20 08:04:15 +08:00
PgpStore.openpgp.initWorker({path: Links.openPgpWorkerJs()});
}
catch (e)
{
Utils.log(e);
2015-09-01 04:13:59 +08:00
}
2015-07-06 02:06:19 +08:00
}
2015-07-24 01:57:46 +08:00
PgpStore.openpgpKeyring = new openpgp.Keyring();
PgpStore.capaOpenPGP(true);
Events.pub('openpgp.init');
2015-11-19 01:32:29 +08:00
this.reloadOpenPgpKeys();
};
if (window.openpgp)
{
2015-11-19 01:32:29 +08:00
openpgpCallback(window.openpgp);
}
else
{
2016-05-21 06:46:56 +08:00
window.jassl(Links.openPgpJs()).then(() => {
if (window.openpgp)
{
2015-11-19 01:32:29 +08:00
openpgpCallback(window.openpgp);
}
});
}
}
else
{
PgpStore.capaOpenPGP(false);
}
kn.startScreens([
require('Screen/User/MailBox'),
2016-04-21 01:12:51 +08:00
Settings.capa(Enums.Capa.Settings) ? require('Screen/User/Settings') : null
// false ? require('Screen/User/About') : null
]);
if (bGoogle || bFacebook || bTwitter)
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
this.socialUsers(true);
2014-08-20 23:03:12 +08:00
}
2015-11-19 01:32:29 +08:00
Events.sub('interval.2m', () => this.folderInformation(Cache.getFolderInboxName()));
Events.sub('interval.3m', () => {
const sF = FolderStore.currentFolderFullNameRaw();
if (Cache.getFolderInboxName() !== sF)
{
2015-11-19 01:32:29 +08:00
this.folderInformation(sF);
}
});
2014-10-29 06:05:50 +08:00
2015-11-19 01:32:29 +08:00
Events.sub('interval.2m-after5m', () => this.folderInformationMultiply());
Events.sub('interval.15m', () => this.quota());
Events.sub('interval.20m', () => this.foldersReload());
2014-10-29 06:05:50 +08:00
iContactsSyncInterval = 5 <= iContactsSyncInterval ? iContactsSyncInterval : 20;
iContactsSyncInterval = 320 >= iContactsSyncInterval ? iContactsSyncInterval : 320;
2014-10-29 06:05:50 +08:00
2015-11-19 01:32:29 +08:00
_.delay(() => this.contactsSync(), 10000);
_.delay(() => this.folderInformationMultiply(true), 2000);
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
window.setInterval(() => this.contactsSync(), iContactsSyncInterval * 60000 + 5000);
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
this.accountsAndIdentities(true);
2015-02-19 03:52:52 +08:00
2015-11-19 01:32:29 +08:00
_.delay(() => {
const sF = FolderStore.currentFolderFullNameRaw();
if (Cache.getFolderInboxName() !== sF)
{
2015-11-19 01:32:29 +08:00
this.folderInformation(sF);
}
}, 1000);
2014-08-20 23:03:12 +08:00
2015-11-19 01:32:29 +08:00
_.delay(() => this.quota(), 5000);
_.delay(() => Remote.appDelayStart(Utils.emptyFunction), 35000);
2015-11-19 01:32:29 +08:00
Events.sub('rl.auto-logout', () => this.logout());
Plugins.runHook('rl-start-user-screens');
Events.pub('rl.bootstart-user-screens');
2015-04-10 06:05:49 +08:00
if (Settings.settingsGet('WelcomePageUrl'))
{
2015-11-19 01:32:29 +08:00
_.delay(() => this.bootstartWelcomePopup(Settings.settingsGet('WelcomePageUrl')), 1000);
2015-04-10 06:05:49 +08:00
}
if (!!Settings.settingsGet('AccountSignMe') &&
window.navigator.registerProtocolHandler &&
Settings.capa(Enums.Capa.Composer))
{
2015-11-19 01:32:29 +08:00
_.delay(() => {
try {
window.navigator.registerProtocolHandler('mailto',
window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
'' + (Settings.settingsGet('Title') || 'RainLoop'));
2016-04-21 01:12:51 +08:00
} catch (e) {/* eslint-disable-line no-empty */}
if (Settings.settingsGet('MailToEmail'))
{
Utils.mailToHelper(Settings.settingsGet('MailToEmail'), require('View/Popup/Compose'));
}
}, 500);
}
if (!Globals.bMobileDevice)
{
2015-11-19 01:32:29 +08:00
_.defer(() => this.initVerticalLayoutResizer(Enums.ClientSideKeyName.FolderListSize));
2016-04-30 07:42:18 +08:00
if (Tinycon && Settings.appSettingsGet('faviconStatus') && !Settings.appSettingsGet('listPermanentFiltered'))
{
Tinycon.setOptions({
fallback: false
});
Events.sub('mailbox.inbox-unread-count',
2015-11-19 01:32:29 +08:00
(iCount) => Tinycon.setBubble(0 < iCount ? (99 < iCount ? 99 : iCount) : 0));
}
}
}
else
{
2015-05-08 00:44:41 +08:00
this.logout();
}
2015-11-19 01:32:29 +08:00
});
2016-04-21 01:12:51 +08:00
// }); // require code splitting
}
2014-08-20 23:03:12 +08:00
}
else
{
this.bootend();
2014-08-27 23:59:44 +08:00
this.bootstartLoginScreen();
2014-08-20 23:03:12 +08:00
}
2014-08-20 23:03:12 +08:00
if (bGoogle)
{
2015-11-19 01:32:29 +08:00
window['rl_' + sJsHash + '_google_service'] = () => {
SocialStore.google.loading(true);
2015-11-19 01:32:29 +08:00
this.socialUsers();
2014-08-20 23:03:12 +08:00
};
}
2014-08-20 23:03:12 +08:00
if (bFacebook)
{
2015-11-19 01:32:29 +08:00
window['rl_' + sJsHash + '_facebook_service'] = () => {
SocialStore.facebook.loading(true);
2015-11-19 01:32:29 +08:00
this.socialUsers();
2014-08-20 23:03:12 +08:00
};
}
2014-08-20 23:03:12 +08:00
if (bTwitter)
{
2015-11-19 01:32:29 +08:00
window['rl_' + sJsHash + '_twitter_service'] = () => {
SocialStore.twitter.loading(true);
2015-11-19 01:32:29 +08:00
this.socialUsers();
2014-08-20 23:03:12 +08:00
};
}
2015-11-19 01:32:29 +08:00
Events.sub('interval.1m', () => Momentor.reload());
2014-08-20 23:03:12 +08:00
Plugins.runHook('rl-start-screens');
2014-08-22 23:08:56 +08:00
Events.pub('rl.bootstart-end');
2015-11-19 01:32:29 +08:00
}
}
2015-11-19 01:32:29 +08:00
export default new AppUser();