snappymail/dev/App/User.js

1489 lines
37 KiB
JavaScript
Raw Normal View History

2016-07-02 06:49:59 +08:00
import window from 'window';
import _ from '_';
import $ from '$';
2015-11-19 01:32:29 +08:00
import progressJs from 'progressJs';
2016-06-07 05:57:52 +08:00
import {
2016-07-02 06:49:59 +08:00
noop, trim, log, has, isArray, inArray, isUnd, isNormal, isPosNumeric, isNonEmptyArray,
pInt, pString, delegateRunOnDestroy, mailToHelper, windowResize, jassl
2016-06-07 05:57:52 +08:00
} from 'Common/Utils';
import {
Layout, Capa, StorageResultType, Notification, FolderType,
2016-08-24 06:17:50 +08:00
SetSystemFoldersNotification, MessageSetAction, ClientSideKeyName, Magics
2016-06-07 05:57:52 +08:00
} from 'Common/Enums';
import {
$html,
leftPanelWidth, leftPanelDisabled,
bAnimationSupported, bMobileDevice
} from 'Common/Globals';
import {UNUSED_OPTION_VALUE} from 'Common/Consts';
2016-08-22 05:30:34 +08:00
import {runHook} from 'Common/Plugins';
import {momentNowUnix, reload as momentReload} from 'Common/Momentor';
import {
initMessageFlagsFromCache, setFolderHash, getFolderHash, getFolderInboxName,
getFolderFromCacheList, clearMessageFlagsFromCacheByFolder,
storeMessageFlagsToCacheBySetAction,
storeMessageFlagsToCacheByFolderAndUid
} from 'Common/Cache';
import {
userBackground, mailBox, root,
openPgpWorkerJs, openPgpJs,
socialGoogle, socialTwitter, socialFacebook
} from 'Common/Links';
2016-06-16 07:36:44 +08:00
import * as Events from 'Common/Events';
2016-08-22 05:30:34 +08:00
2016-06-17 07:23:49 +08:00
import {getNotification, i18n} from 'Common/Translator';
2015-11-19 01:32:29 +08:00
import SocialStore from 'Stores/Social';
import AppStore from 'Stores/User/App';
2015-11-19 01:32:29 +08:00
import SettingsStore from 'Stores/User/Settings';
import NotificationStore from 'Stores/User/Notification';
2015-11-19 01:32:29 +08:00
import AccountStore from 'Stores/User/Account';
import ContactStore from 'Stores/User/Contact';
2015-11-19 01:32:29 +08:00
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';
2016-08-24 06:17:50 +08:00
import QuotaStore from 'Stores/User/Quota';
2015-11-19 01:32:29 +08:00
2016-06-17 07:23:49 +08:00
import * as Local from 'Storage/Client';
2016-06-16 07:36:44 +08:00
import * as Settings from 'Storage/Settings';
2016-06-17 07:23:49 +08:00
import {checkTimestamp} from 'Storage/RainLoop';
2015-11-19 01:32:29 +08:00
import Remote from 'Remote/User/Ajax';
import Promises from 'Promises/User/Ajax';
2016-07-07 05:03:30 +08:00
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';
2015-11-19 01:32:29 +08:00
2016-07-07 07:11:13 +08:00
// import {AboutUserScreen} from 'Screen/User/About';
import {LoginUserScreen} from 'Screen/User/Login';
import {MailBoxUserScreen} from 'Screen/User/MailBox';
import {SettingsUserScreen} from 'Screen/User/Settings';
2016-07-08 07:22:58 +08:00
import {
hideLoading, routeOff, routeOn, setHash,
startScreens, showScreenPopup
} from 'Knoin/Knoin';
2015-11-19 01:32:29 +08:00
import {AbstractApp} from 'App/Abstract';
class AppUser extends AbstractApp
{
2016-07-16 05:29:42 +08:00
constructor() {
2015-11-19 01:32:29 +08:00
super(Remote);
2016-06-28 04:54:38 +08:00
this.moveCache = {};
2016-08-24 06:17:50 +08:00
this.quotaDebounce = _.debounce(this.quota, Magics.Time30s);
2014-08-20 23:03:12 +08:00
this.moveOrDeleteResponseHelper = _.bind(this.moveOrDeleteResponseHelper, this);
2014-08-20 23:03:12 +08:00
this.messagesMoveTrigger = _.debounce(this.messagesMoveTrigger, 500);
2016-08-24 06:17:50 +08:00
window.setInterval(() => Events.pub('interval.30s'), Magics.Time30s);
window.setInterval(() => Events.pub('interval.1m'), Magics.Time1m);
window.setInterval(() => Events.pub('interval.2m'), Magics.Time2m);
window.setInterval(() => Events.pub('interval.3m'), Magics.Time3m);
window.setInterval(() => Events.pub('interval.5m'), Magics.Time5m);
window.setInterval(() => Events.pub('interval.10m'), Magics.Time10m);
window.setInterval(() => Events.pub('interval.15m'), Magics.Time15m);
window.setInterval(() => Events.pub('interval.20m'), Magics.Time20m);
2015-11-19 01:32:29 +08:00
2016-08-24 06:17:50 +08:00
window.setTimeout(() => window.setInterval(() => Events.pub('interval.2m-after5m'), Magics.Time2m), Magics.Time5m);
window.setTimeout(() => window.setInterval(() => Events.pub('interval.5m-after5m'), Magics.Time5m), Magics.Time5m);
window.setTimeout(() => window.setInterval(() => Events.pub('interval.10m-after5m'), Magics.Time10m), Magics.Time5m);
2015-11-19 01:32:29 +08:00
$.wakeUp(() => {
2016-06-17 07:23:49 +08:00
if (checkTimestamp())
2016-05-22 20:27:50 +08:00
{
this.reload();
}
2015-11-19 01:32:29 +08:00
Remote.jsVersion((sResult, oData) => {
2016-06-07 05:57:52 +08:00
if (StorageResultType.Success === sResult && oData && !oData.Result)
{
2016-05-22 20:27:50 +08:00
this.reload();
}
2016-04-30 07:42:18 +08:00
}, Settings.appSettingsGet('version'));
2016-05-22 20:27:50 +08:00
2016-08-24 06:17:50 +08:00
}, {}, Magics.Time60m);
2014-08-22 23:08:56 +08:00
2016-06-17 07:23:49 +08:00
if (checkTimestamp())
2016-05-22 20:27:50 +08:00
{
this.reload();
}
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;')
2016-08-22 05:30:34 +08:00
.backstretch(userBackground(Settings.settingsGet('UserBackgroundHash')), {
2016-08-24 06:17:50 +08:00
fade: bAnimationSupported ? Magics.Time1s : 0,
2016-04-21 01:12:51 +08:00
centeredX: true,
centeredY: true
})
2016-06-30 08:02:45 +08:00
.removeAttr('style');
2016-08-24 06:17:50 +08:00
}, Magics.Time1s);
}
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
}
2016-05-22 20:27:50 +08:00
reload() {
if (window.parent && !!Settings.appSettingsGet('inIframe'))
{
window.parent.location.reload();
}
else
{
window.location.reload();
}
}
2015-11-19 01:32:29 +08:00
reloadFlagsCurrentMessageListAndMessageFromCache() {
_.each(MessageStore.messageList(), (message) => {
2016-08-22 05:30:34 +08:00
initMessageFlagsFromCache(message);
2014-08-20 23:03:12 +08:00
});
2016-08-22 05:30:34 +08:00
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
2016-06-30 08:02:45 +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)
{
2016-08-22 05:30:34 +08:00
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
2016-08-22 05:30:34 +08:00
setHash(mailBox(
2015-04-22 05:01:29 +08:00
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) => {
2016-06-07 05:57:52 +08:00
if (StorageResultType.Success === sResult && oData && oData.Result)
2014-08-20 23:03:12 +08:00
{
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
}
2016-06-07 05:57:52 +08:00
else if (StorageResultType.Unload === sResult)
2014-08-20 23:03:12 +08:00
{
2015-02-22 06:00:51 +08:00
MessageStore.messageListError('');
MessageStore.messageListLoading(false);
2014-08-20 23:03:12 +08:00
}
2016-06-07 05:57:52 +08:00
else if (StorageResultType.Abort !== sResult)
2014-08-20 23:03:12 +08:00
{
2015-02-22 06:00:51 +08:00
MessageStore.messageList([]);
MessageStore.messageListLoading(false);
MessageStore.messageListError(oData && oData.ErrorCode ?
2016-06-17 07:23:49 +08:00
getNotification(oData.ErrorCode) : 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() {
2016-08-22 05:30:34 +08:00
Remote.messageList(noop, getFolderInboxName(), 0, SettingsStore.messagesPerPage(), '', '', true);
2015-11-19 01:32:29 +08:00
}
2014-08-20 23:03:12 +08:00
/**
* @param {Function} fResultFunc
2016-06-30 08:02:45 +08:00
* @returns {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(),
2016-06-30 08:02:45 +08:00
sSpamFolder = FolderStore.spamFolder();
_.each(this.moveCache, (item) => {
const
isSpam = sSpamFolder === item.To,
isTrash = sTrashFolder === item.To,
2016-08-22 05:30:34 +08:00
isHam = !isSpam && sSpamFolder === item.From && getFolderInboxName() === item.To;
2014-03-20 00:18:28 +08:00
Remote.messagesMove(this.moveOrDeleteResponseHelper, item.From, item.To, item.Uid,
isSpam ? 'SPAM' : (isHam ? 'HAM' : ''), isSpam || isTrash);
2014-08-20 23:03:12 +08:00
});
2014-03-20 00:18:28 +08:00
2016-06-28 04:54:38 +08:00
this.moveCache = {};
2015-11-19 01:32:29 +08:00
}
messagesMoveHelper(fromFolderFullNameRaw, toFolderFullNameRaw, uidsForMove) {
const hash = '$$' + fromFolderFullNameRaw + '$$' + toFolderFullNameRaw + '$$';
if (!this.moveCache[hash])
2014-03-20 00:18:28 +08:00
{
this.moveCache[hash] = {
From: fromFolderFullNameRaw,
To: toFolderFullNameRaw,
2016-04-21 01:12:51 +08:00
Uid: []
2014-08-20 23:03:12 +08:00
};
2014-03-20 00:18:28 +08:00
}
this.moveCache[hash].Uid = _.union(this.moveCache[hash].Uid, uidsForMove);
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
2016-06-07 05:57:52 +08:00
if (StorageResultType.Success === sResult && FolderStore.currentFolder())
2014-03-20 00:18:28 +08:00
{
2016-06-07 05:57:52 +08:00
if (oData && isArray(oData.Result) && 2 === oData.Result.length)
{
2016-08-22 05:30:34 +08:00
setFolderHash(oData.Result[0], oData.Result[1]);
}
else
{
2016-08-22 05:30:34 +08:00
setFolderHash(FolderStore.currentFolderFullNameRaw(), '');
2014-08-20 23:03:12 +08:00
2016-06-07 05:57:52 +08:00
if (oData && -1 < inArray(oData.ErrorCode,
[Notification.CantMoveMessage, Notification.CantCopyMessage]))
2014-08-20 23:03:12 +08:00
{
2016-06-17 07:23:49 +08:00
window.alert(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,
2016-06-30 08:02:45 +08:00
nSetSystemFoldersNotification = null;
2014-03-20 00:18:28 +08:00
2014-08-20 23:03:12 +08:00
switch (iDeleteType)
{
2016-06-07 05:57:52 +08:00
case FolderType.Spam:
2016-08-22 05:30:34 +08:00
oMoveFolder = getFolderFromCacheList(FolderStore.spamFolder());
2016-06-07 05:57:52 +08:00
nSetSystemFoldersNotification = SetSystemFoldersNotification.Spam;
2014-08-20 23:03:12 +08:00
break;
2016-06-07 05:57:52 +08:00
case FolderType.NotSpam:
2016-08-22 05:30:34 +08:00
oMoveFolder = getFolderFromCacheList(getFolderInboxName());
2014-08-20 23:03:12 +08:00
break;
2016-06-07 05:57:52 +08:00
case FolderType.Trash:
2016-08-22 05:30:34 +08:00
oMoveFolder = getFolderFromCacheList(FolderStore.trashFolder());
2016-06-07 05:57:52 +08:00
nSetSystemFoldersNotification = SetSystemFoldersNotification.Trash;
2014-08-20 23:03:12 +08:00
break;
2016-06-07 05:57:52 +08:00
case FolderType.Archive:
2016-08-22 05:30:34 +08:00
oMoveFolder = getFolderFromCacheList(FolderStore.archiveFolder());
2016-06-07 05:57:52 +08:00
nSetSystemFoldersNotification = SetSystemFoldersNotification.Archive;
2014-08-20 23:03:12 +08:00
break;
2016-06-30 08:02:45 +08:00
// no default
2014-08-20 23:03:12 +08:00
}
2016-06-07 05:57:52 +08:00
bUseFolder = isUnd(bUseFolder) ? true : !!bUseFolder;
2014-08-20 23:03:12 +08:00
if (bUseFolder)
{
2016-06-07 05:57:52 +08:00
if ((FolderType.Spam === iDeleteType && UNUSED_OPTION_VALUE === FolderStore.spamFolder()) ||
(FolderType.Trash === iDeleteType && UNUSED_OPTION_VALUE === FolderStore.trashFolder()) ||
(FolderType.Archive === iDeleteType && 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)
{
2016-07-08 07:22:58 +08:00
showScreenPopup(require('View/Popup/FolderSystem'), [nSetSystemFoldersNotification]);
}
2016-06-07 05:57:52 +08:00
else if (!bUseFolder || (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
{
2016-07-08 07:22:58 +08:00
showScreenPopup(require('View/Popup/Ask'), [i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'), () => {
2015-11-19 01:32:29 +08:00
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) {
2016-06-07 05:57:52 +08:00
if (sFromFolderFullNameRaw !== sToFolderFullNameRaw && isArray(aUidForMove) && 0 < aUidForMove.length)
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
const
2016-08-22 05:30:34 +08:00
oFromFolder = getFolderFromCacheList(sFromFolderFullNameRaw),
oToFolder = getFolderFromCacheList(sToFolderFullNameRaw);
2014-08-20 23:03:12 +08:00
if (oFromFolder && oToFolder)
{
2016-06-07 05:57:52 +08:00
if (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) {
2016-07-02 06:49:59 +08:00
const prom = Promises.foldersReload(FolderStore.foldersLoading);
if (callback)
{
2016-09-10 06:38:16 +08:00
prom.then((value) => !!value).then(callback).catch(() => {
2016-07-02 06:49:59 +08:00
_.delay(() => {
2016-09-10 06:38:16 +08:00
if (callback)
{
callback(false); // eslint-disable-line callback-return
}
2016-07-02 06:49:59 +08:00
}, 1);
});
}
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)
.then(() => {
Promises.foldersReloadWithTimeout(FolderStore.foldersLoading);
}, (errorCode) => {
2016-06-17 07:23:49 +08:00
FolderStore.folderList.error(getNotification(errorCode, '', errorDefCode));
Promises.foldersReloadWithTimeout(FolderStore.foldersLoading);
2016-06-30 08:02:45 +08:00
});
2015-11-19 01:32:29 +08:00
}
reloadOpenPgpKeys() {
2015-02-03 07:58:58 +08:00
if (PgpStore.capaOpenPGP())
{
const
keys = [],
email = new EmailModel(),
openpgpKeyring = PgpStore.openpgpKeyring,
openpgpKeys = openpgpKeyring ? openpgpKeyring.getAllKeys() : [];
_.each(openpgpKeys, (oItem, iIndex) => {
2014-08-20 23:03:12 +08:00
if (oItem && oItem.primaryKey)
{
const
aEmails = [],
aUsers = [],
primaryUser = oItem.getPrimaryUser(),
user = (primaryUser && primaryUser.user) ? primaryUser.user.userId.userid :
2016-06-30 08:02:45 +08:00
(oItem.users && oItem.users[0] ? oItem.users[0].userId.userid : '');
2016-05-24 01:33:01 +08:00
if (oItem.users)
{
2016-04-21 01:12:51 +08:00
_.each(oItem.users, (item) => {
2016-05-24 01:33:01 +08:00
if (item.userId)
{
email.clear();
email.mailsoParse(item.userId.userid);
if (email.validate())
2016-05-24 01:33:01 +08:00
{
aEmails.push(email.email);
2016-05-24 01:33:01 +08:00
aUsers.push(item.userId.userid);
}
}
});
}
if (aEmails.length)
2014-08-20 23:03:12 +08:00
{
keys.push(new OpenPgpKeyModel(
2014-08-20 23:03:12 +08:00
iIndex,
oItem.primaryKey.getFingerprint(),
oItem.primaryKey.getKeyId().toHex().toLowerCase(),
2016-07-02 06:49:59 +08:00
_.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(),
user)
2014-08-20 23:03:12 +08:00
);
}
}
});
2016-06-07 05:57:52 +08:00
delegateRunOnDestroy(PgpStore.openpgpkeys());
PgpStore.openpgpkeys(keys);
}
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);
//
2016-06-07 05:57:52 +08:00
// if (StorageResultType.Success === sResult && oData.Result && oData.Result['Counts'])
2015-02-03 07:58:58 +08:00
// {
// 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)
// {
2016-06-07 05:57:52 +08:00
// oAccount.count(pInt(oItem[1]));
2015-02-03 07:58:58 +08:00
// }
// });
// }
// });
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);
2016-06-07 05:57:52 +08:00
if (StorageResultType.Success === sResult && oData.Result)
2014-08-20 23:03:12 +08:00
{
const
2016-08-24 06:17:50 +08:00
counts = {},
2016-06-30 08:02:45 +08:00
sAccountEmail = AccountStore.email();
let
2016-08-24 06:17:50 +08:00
parentEmail = Settings.settingsGet('ParentEmail');
2013-12-07 06:45:46 +08:00
2016-08-24 06:17:50 +08:00
parentEmail = '' === parentEmail ? sAccountEmail : parentEmail;
2016-06-07 05:57:52 +08:00
if (isArray(oData.Result.Accounts))
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
_.each(AccountStore.accounts(), (oAccount) => {
2016-08-24 06:17:50 +08:00
counts[oAccount.email] = oAccount.count();
});
2016-06-07 05:57:52 +08:00
delegateRunOnDestroy(AccountStore.accounts());
2016-04-21 01:12:51 +08:00
AccountStore.accounts(_.map(oData.Result.Accounts,
2016-08-24 06:17:50 +08:00
(sValue) => new AccountModel(sValue, sValue !== parentEmail, counts[sValue] || 0)));
2014-08-20 23:03:12 +08:00
}
2016-06-07 05:57:52 +08:00
if (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-06-07 05:57:52 +08:00
if (isArray(oData.Result.Identities))
2014-08-20 23:03:12 +08:00
{
2016-06-07 05:57:52 +08:00
delegateRunOnDestroy(IdentityStore.identities());
2015-01-29 05:24:58 +08:00
2016-08-24 06:17:50 +08:00
IdentityStore.identities(_.map(oData.Result.Identities, (identityData) => {
2013-12-07 06:45:46 +08:00
2015-11-19 01:32:29 +08:00
const
2016-08-24 06:17:50 +08:00
id = pString(identityData.Id),
email = pString(identityData.Email),
identity = new IdentityModel(id, email);
2013-12-07 06:45:46 +08:00
2016-08-24 06:17:50 +08:00
identity.name(pString(identityData.Name));
identity.replyTo(pString(identityData.ReplyTo));
identity.bcc(pString(identityData.Bcc));
identity.signature(pString(identityData.Signature));
identity.signatureInsertBefore(!!identityData.SignatureInsertBefore);
2013-12-07 06:45:46 +08:00
2016-08-24 06:17:50 +08:00
return identity;
2014-08-20 23:03:12 +08:00
}));
}
}
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);
2016-06-07 05:57:52 +08:00
if (StorageResultType.Success === result && data.Result &&
isArray(data.Result.Templates))
{
2016-06-07 05:57:52 +08:00
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) => {
2016-06-07 05:57:52 +08:00
if (StorageResultType.Success === result && data && data.Result &&
isArray(data.Result) && 1 < data.Result.length &&
isPosNumeric(data.Result[0], true) && isPosNumeric(data.Result[1], true))
{
2016-08-24 06:17:50 +08:00
QuotaStore.populateData(pInt(data.Result[1]), 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) {
2016-06-07 05:57:52 +08:00
if ('' !== trim(folder))
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
Remote.folderInformation((result, data) => {
2016-06-07 05:57:52 +08:00
if (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,
2016-06-30 08:02:45 +08:00
unreadCountChange = false;
2016-08-22 05:30:34 +08:00
const folderFromCache = getFolderFromCacheList(data.Result.Folder);
2016-04-21 01:12:51 +08:00
if (folderFromCache)
{
2016-08-22 05:30:34 +08:00
folderFromCache.interval = momentNowUnix();
2015-11-19 01:32:29 +08:00
if (data.Result.Hash)
{
2016-08-22 05:30:34 +08:00
setFolderHash(data.Result.Folder, data.Result.Hash);
}
2016-06-07 05:57:52 +08:00
if (isNormal(data.Result.MessageCount))
{
2016-04-21 01:12:51 +08:00
folderFromCache.messageCountAll(data.Result.MessageCount);
}
2016-06-07 05:57:52 +08:00
if (isNormal(data.Result.MessageUnseenCount))
{
2016-06-07 05:57:52 +08:00
if (pInt(folderFromCache.messageCountUnread()) !== 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-08-22 05:30:34 +08:00
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
{
2016-07-02 06:49:59 +08:00
if (has(data.Result.Flags, 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-08-22 05:30:34 +08:00
storeMessageFlagsToCacheByFolderAndUid(folderFromCache.fullNameRaw, uid.toString(), [
2016-04-21 01:12:51 +08:00
!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
2016-08-22 05:30:34 +08:00
const hash = 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-08-22 05:30:34 +08:00
else if (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();
2016-06-07 05:57:52 +08:00
if (isNonEmptyArray(folders))
2014-08-20 23:03:12 +08:00
{
2015-11-19 01:32:29 +08:00
Remote.folderInformationMultiply((sResult, oData) => {
2016-06-07 05:57:52 +08:00
if (StorageResultType.Success === sResult)
2014-08-20 23:03:12 +08:00
{
2016-06-07 05:57:52 +08:00
if (oData && oData.Result && oData.Result.List && isNonEmptyArray(oData.Result.List))
2014-08-20 23:03:12 +08:00
{
2016-08-22 05:30:34 +08:00
const utc = momentNowUnix();
2016-08-24 06:17:50 +08:00
_.each(oData.Result.List, (item) => {
const
2016-08-24 06:17:50 +08:00
hash = getFolderHash(item.Folder),
folder = getFolderFromCacheList(item.Folder);
let
unreadCountChange = false;
if (folder)
2014-08-20 23:03:12 +08:00
{
folder.interval = utc;
2016-08-24 06:17:50 +08:00
if (item.Hash)
2014-08-20 23:03:12 +08:00
{
2016-08-24 06:17:50 +08:00
setFolderHash(item.Folder, item.Hash);
2014-08-20 23:03:12 +08:00
}
2016-08-24 06:17:50 +08:00
if (isNormal(item.MessageCount))
2014-08-20 23:03:12 +08:00
{
2016-08-24 06:17:50 +08:00
folder.messageCountAll(item.MessageCount);
2014-08-20 23:03:12 +08:00
}
2016-08-24 06:17:50 +08:00
if (isNormal(item.MessageUnseenCount))
2014-08-20 23:03:12 +08:00
{
2016-08-24 06:17:50 +08:00
if (pInt(folder.messageCountUnread()) !== pInt(item.MessageUnseenCount))
2014-08-20 23:03:12 +08:00
{
unreadCountChange = true;
2014-08-20 23:03:12 +08:00
}
2016-08-24 06:17:50 +08:00
folder.messageCountUnread(item.MessageUnseenCount);
2014-08-20 23:03:12 +08:00
}
if (unreadCountChange)
2014-08-20 23:03:12 +08:00
{
2016-08-22 05:30:34 +08:00
clearMessageFlagsFromCacheByFolder(folder.fullNameRaw);
2014-08-20 23:03:12 +08:00
}
2016-08-24 06:17:50 +08:00
if (item.Hash !== hash || '' === hash)
2014-08-20 23:03:12 +08:00
{
if (folder.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 (unreadCountChange)
2014-08-20 23:03:12 +08:00
{
if (folder.fullNameRaw === FolderStore.currentFolderFullNameRaw())
2014-08-20 23:03:12 +08:00
{
2016-08-24 06:17:50 +08:00
const list = MessageStore.messageList();
if (isNonEmptyArray(list))
2014-08-20 23:03:12 +08:00
{
2016-08-24 06:17:50 +08:00
this.folderInformation(folder.fullNameRaw, list);
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 {number} iSetAction
* @param {Array=} messages = null
2015-03-06 08:42:40 +08:00
*/
2016-12-15 05:56:17 +08:00
messageListAction(sFolderFullNameRaw, iSetAction, messages) {
2015-11-19 01:32:29 +08:00
let
folder = null,
alreadyUnread = 0,
rootUids = [];
2015-03-06 08:42:40 +08:00
if (isUnd(messages) || !messages)
{
messages = MessageStore.messageListChecked();
2015-03-06 08:42:40 +08:00
}
rootUids = _.uniq(_.compact(_.map(messages, (oMessage) => (oMessage && oMessage.uid ? oMessage.uid : null))));
2015-03-06 08:42:40 +08:00
if ('' !== sFolderFullNameRaw && 0 < rootUids.length)
2015-03-06 08:42:40 +08:00
{
2016-06-30 08:02:45 +08:00
switch (iSetAction)
{
2016-06-07 05:57:52 +08:00
case MessageSetAction.SetSeen:
2015-03-06 08:42:40 +08:00
_.each(rootUids, (sSubUid) => {
2016-08-22 05:30:34 +08:00
alreadyUnread += storeMessageFlagsToCacheBySetAction(sFolderFullNameRaw, sSubUid, iSetAction);
2015-03-06 08:42:40 +08:00
});
2016-08-22 05:30:34 +08:00
folder = getFolderFromCacheList(sFolderFullNameRaw);
if (folder)
2015-03-06 08:42:40 +08:00
{
folder.messageCountUnread(folder.messageCountUnread() - alreadyUnread);
2015-03-06 08:42:40 +08:00
}
Remote.messageSetSeen(noop, sFolderFullNameRaw, rootUids, true);
2015-03-06 08:42:40 +08:00
break;
2016-06-07 05:57:52 +08:00
case MessageSetAction.UnsetSeen:
2015-03-06 08:42:40 +08:00
_.each(rootUids, (sSubUid) => {
2016-08-22 05:30:34 +08:00
alreadyUnread += storeMessageFlagsToCacheBySetAction(
2015-03-06 08:42:40 +08:00
sFolderFullNameRaw, sSubUid, iSetAction);
});
2016-08-22 05:30:34 +08:00
folder = getFolderFromCacheList(sFolderFullNameRaw);
if (folder)
2015-03-06 08:42:40 +08:00
{
folder.messageCountUnread(folder.messageCountUnread() - alreadyUnread + rootUids.length);
2015-03-06 08:42:40 +08:00
}
Remote.messageSetSeen(noop, sFolderFullNameRaw, rootUids, false);
2015-03-06 08:42:40 +08:00
break;
2016-06-07 05:57:52 +08:00
case MessageSetAction.SetFlag:
2015-03-06 08:42:40 +08:00
_.each(rootUids, (sSubUid) => {
2016-08-22 05:30:34 +08:00
storeMessageFlagsToCacheBySetAction(sFolderFullNameRaw, sSubUid, iSetAction);
2015-03-06 08:42:40 +08:00
});
Remote.messageSetFlagged(noop, sFolderFullNameRaw, rootUids, true);
2015-03-06 08:42:40 +08:00
break;
2016-06-07 05:57:52 +08:00
case MessageSetAction.UnsetFlag:
2015-03-06 08:42:40 +08:00
_.each(rootUids, (sSubUid) => {
2016-08-22 05:30:34 +08:00
storeMessageFlagsToCacheBySetAction(sFolderFullNameRaw, sSubUid, iSetAction);
2015-03-06 08:42:40 +08:00
});
Remote.messageSetFlagged(noop, sFolderFullNameRaw, rootUids, false);
2015-03-06 08:42:40 +08:00
break;
2016-06-30 08:02:45 +08:00
// no default
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() {
2016-08-22 05:30:34 +08:00
window.open(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() {
2016-08-22 05:30:34 +08:00
window.open(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() {
2016-08-22 05:30:34 +08:00
window.open(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
2016-06-07 05:57:52 +08:00
if (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
2016-07-02 06:49:59 +08:00
* @param {Function} autocompleteCallback
2014-08-20 23:03:12 +08:00
*/
2016-07-02 06:49:59 +08:00
getAutocomplete(query, autocompleteCallback) {
2015-11-19 01:32:29 +08:00
Remote.suggestions((result, data) => {
2016-06-07 05:57:52 +08:00
if (StorageResultType.Success === result && data && isArray(data.Result))
2014-08-22 23:08:56 +08:00
{
2016-07-02 06:49:59 +08:00
autocompleteCallback(_.compact(_.map(data.Result, (item) => (item && item[0] ? new EmailModel(item[0], item[1]) : null))));
2014-08-22 23:08:56 +08:00
}
2016-06-07 05:57:52 +08:00
else if (StorageResultType.Abort !== result)
2014-08-22 23:08:56 +08:00
{
2016-07-02 06:49:59 +08:00
autocompleteCallback([]);
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) {
2016-06-07 05:57:52 +08:00
let aExpandedList = Local.get(ClientSideKeyName.ExpandedFolders);
if (!isArray(aExpandedList))
2014-08-22 23:08:56 +08:00
{
aExpandedList = [];
}
if (bExpanded)
{
aExpandedList.push(sFullNameHash);
aExpandedList = _.uniq(aExpandedList);
}
else
{
aExpandedList = _.without(aExpandedList, sFullNameHash);
}
2016-06-07 05:57:52 +08:00
Local.set(ClientSideKeyName.ExpandedFolders, aExpandedList);
2015-11-19 01:32:29 +08:00
}
initHorizontalLayoutResizer(sClientSideKeyName) {
2014-08-22 23:08:56 +08:00
let
2016-08-24 06:17:50 +08:00
top = null,
bottom = null;
2015-01-09 07:31:31 +08:00
const
minHeight = 200,
maxHeight = 500,
2016-04-21 01:12:51 +08:00
fSetHeight = (height) => {
if (height)
{
2016-08-24 06:17:50 +08:00
if (top)
2016-04-21 01:12:51 +08:00
{
2016-08-24 06:17:50 +08:00
top.attr('style', 'height:' + height + 'px');
2016-04-21 01:12:51 +08:00
}
2016-08-24 06:17:50 +08:00
if (bottom)
2016-04-21 01:12:51 +08:00
{
2016-08-24 06:17:50 +08:00
bottom.attr('style', 'top:' + (55 /* top toolbar */ + height) + 'px');
2016-04-21 01:12:51 +08:00
}
}
},
2015-11-19 01:32:29 +08:00
fResizeCreateFunction = (event) => {
if (event && event.target)
{
$(event.target).find('.ui-resizable-handle')
2015-11-19 01:32:29 +08:00
.on('mousedown', () => {
2016-06-07 05:57:52 +08:00
$html.addClass('rl-resizer');
})
2015-11-19 01:32:29 +08:00
.on('mouseup', () => {
2016-06-07 05:57:52 +08:00
$html.removeClass('rl-resizer');
2016-06-30 08:02:45 +08:00
});
}
},
2015-11-19 01:32:29 +08:00
fResizeStartFunction = () => {
2016-06-07 05:57:52 +08:00
$html.addClass('rl-resizer');
},
2015-11-19 01:32:29 +08:00
fResizeResizeFunction = _.debounce(() => {
2016-06-07 05:57:52 +08:00
$html.addClass('rl-resizer');
}, 500, true),
2015-11-19 01:32:29 +08:00
fResizeStopFunction = (oEvent, oObject) => {
2016-06-07 05:57:52 +08:00
$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);
2016-06-07 05:57:52 +08:00
windowResize();
2015-01-09 07:31:31 +08:00
}
},
oOptions = {
2016-04-21 01:12:51 +08:00
helper: 'ui-resizable-helper-h',
minHeight: minHeight,
maxHeight: maxHeight,
2016-04-21 01:12:51 +08:00
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)
{
2016-08-24 06:17:50 +08:00
if (top && top.hasClass('ui-resizable'))
2015-01-09 07:31:31 +08:00
{
2016-08-24 06:17:50 +08:00
top
2015-01-09 07:31:31 +08:00
.resizable('destroy')
2016-06-30 08:02:45 +08:00
.removeAttr('style');
2015-01-09 07:31:31 +08:00
}
2016-08-24 06:17:50 +08:00
if (bottom)
2015-01-09 07:31:31 +08:00
{
2016-08-24 06:17:50 +08:00
bottom.removeAttr('style');
2015-01-09 07:31:31 +08:00
}
}
2016-06-07 05:57:52 +08:00
else if ($html.hasClass('rl-bottom-preview-pane'))
2015-01-09 07:31:31 +08:00
{
2016-08-24 06:17:50 +08:00
top = $('.b-message-list-wrapper');
bottom = $('.b-message-view-wrapper');
2015-01-09 07:31:31 +08:00
2016-08-24 06:17:50 +08:00
if (!top.hasClass('ui-resizable'))
2015-01-09 07:31:31 +08:00
{
2016-08-24 06:17:50 +08:00
top.resizable(oOptions);
2015-01-09 07:31:31 +08:00
}
2016-06-07 05:57:52 +08:00
const iHeight = pInt(Local.get(sClientSideKeyName)) || 300;
fSetHeight(iHeight > minHeight ? iHeight : minHeight);
2015-01-09 07:31:31 +08:00
}
2016-06-30 08:02:45 +08:00
};
2015-01-09 07:31:31 +08:00
fDisable(false);
2015-11-19 01:32:29 +08:00
Events.sub('layout', (layout) => {
2016-06-07 05:57:52 +08:00
fDisable(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) {
const
disabledWidth = 60,
minWidth = 155,
lLeft = $('#rl-left'),
right = $('#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-06-07 05:57:52 +08:00
leftPanelWidth(iWidth);
2016-04-29 04:32:54 +08:00
2016-06-07 05:57:52 +08:00
$html.removeClass('rl-resizer');
2016-04-29 04:32:54 +08:00
lLeft.css({
2016-04-21 01:12:51 +08:00
width: '' + iWidth + 'px'
2014-08-22 23:08:56 +08:00
});
right.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)
{
lLeft.resizable('disable');
fSetWidth(disabledWidth);
2014-08-22 23:08:56 +08:00
}
else
{
lLeft.resizable('enable');
const width = pInt(Local.get(sClientSideKeyName)) || minWidth;
fSetWidth(width > minWidth ? width : minWidth);
2014-08-22 23:08:56 +08:00
}
},
2016-04-29 04:32:54 +08:00
2016-08-24 06:17:50 +08:00
fResizeCreateFunction = (event) => {
if (event && event.target)
{
2016-08-24 06:17:50 +08:00
$(event.target).find('.ui-resizable-handle')
2015-11-19 01:32:29 +08:00
.on('mousedown', () => {
2016-06-07 05:57:52 +08:00
$html.addClass('rl-resizer');
})
2015-11-19 01:32:29 +08:00
.on('mouseup', () => {
2016-06-07 05:57:52 +08:00
$html.removeClass('rl-resizer');
2016-06-30 08:02:45 +08:00
});
}
},
2015-11-19 01:32:29 +08:00
fResizeResizeFunction = _.debounce(() => {
2016-06-07 05:57:52 +08:00
$html.addClass('rl-resizer');
}, 500, true),
2015-11-19 01:32:29 +08:00
fResizeStartFunction = () => {
2016-06-07 05:57:52 +08:00
$html.addClass('rl-resizer');
},
2016-08-24 06:17:50 +08:00
fResizeStopFunction = (event, obj) => {
2016-06-07 05:57:52 +08:00
$html.removeClass('rl-resizer');
2016-08-24 06:17:50 +08:00
if (obj && obj.size && obj.size.width)
2014-08-22 23:08:56 +08:00
{
2016-08-24 06:17:50 +08:00
Local.set(sClientSideKeyName, obj.size.width);
2014-08-22 23:08:56 +08:00
2016-08-24 06:17:50 +08:00
leftPanelWidth(obj.size.width);
2016-04-29 04:32:54 +08:00
right.css({
2016-08-24 06:17:50 +08:00
left: '' + obj.size.width + 'px'
2014-08-22 23:08:56 +08:00
});
2016-04-29 04:32:54 +08:00
lLeft.css({
2016-04-29 04:32:54 +08:00
position: '',
top: '',
left: '',
height: ''
});
2014-08-22 23:08:56 +08:00
}
2016-06-30 08:02:45 +08:00
};
2014-08-22 23:08:56 +08:00
if (null !== mLeftWidth)
{
fSetWidth(mLeftWidth > minWidth ? mLeftWidth : minWidth);
2014-08-22 23:08:56 +08:00
}
lLeft.resizable({
2016-04-21 01:12:51 +08:00
helper: 'ui-resizable-helper-w',
minWidth: minWidth,
2016-08-24 06:17:50 +08:00
maxWidth: Magics.Size350px,
2016-04-21 01:12:51 +08:00
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() {
2016-07-08 07:22:58 +08:00
showScreenPopup(require('View/Popup/TwoFactorConfiguration'), [true]);
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
bootstartWelcomePopup(url) {
2016-07-08 07:22:58 +08:00
showScreenPopup(require('View/Popup/WelcomePage'), [url]);
2015-11-19 01:32:29 +08:00
}
bootstartLoginScreen() {
2015-04-10 06:05:49 +08:00
2016-06-07 05:57:52 +08:00
$html.removeClass('rl-user-auth').addClass('rl-user-no-auth');
2016-06-07 05:57:52 +08:00
const customLoginLink = pString(Settings.appSettingsGet('customLoginLink'));
2015-11-19 01:32:29 +08:00
if (!customLoginLink)
2014-08-27 23:59:44 +08:00
{
2016-07-08 07:22:58 +08:00
startScreens([
2016-07-07 07:11:13 +08:00
LoginUserScreen
2014-08-27 23:59:44 +08:00
]);
2016-08-22 05:30:34 +08:00
runHook('rl-start-login-screens');
2014-08-27 23:59:44 +08:00
Events.pub('rl.bootstart-login-screens');
}
else
{
2016-07-08 07:22:58 +08:00
routeOff();
2016-08-22 05:30:34 +08:00
setHash(root(), true);
2016-07-08 07:22:58 +08:00
routeOff();
2014-08-27 23:59:44 +08:00
_.defer(() => {
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)
{
progressJs.set(100).end();
}
2016-07-08 07:22:58 +08:00
hideLoading();
2016-04-21 01:12:51 +08:00
}
2015-11-19 01:32:29 +08:00
bootstart() {
super.bootstart();
AppStore.populate();
SettingsStore.populate();
NotificationStore.populate();
AccountStore.populate();
ContactStore.populate();
let
contactsSyncInterval = pInt(Settings.settingsGet('ContactsSyncInterval'));
const
jsHash = Settings.appSettingsGet('jsHash'),
startupUrl = pString(Settings.settingsGet('StartupUrl')),
allowGoogle = Settings.settingsGet('AllowGoogleSocial'),
allowFacebook = Settings.settingsGet('AllowFacebookSocial'),
allowTwitter = Settings.settingsGet('AllowTwitterSocial');
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
}
2016-06-07 05:57:52 +08:00
leftPanelDisabled.subscribe((value) => {
2015-11-19 01:32:29 +08:00
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
{
2016-06-07 05:57:52 +08:00
$html.addClass('rl-user-auth');
2016-06-07 05:57:52 +08:00
if (Settings.capa(Capa.TwoFactor) &&
Settings.capa(Capa.TwoFactorForce) &&
Settings.settingsGet('RequireTwoFactor'))
{
this.bootend();
this.bootstartTwoFactorScreen();
}
else
{
2016-06-17 07:23:49 +08:00
this.setWindowTitle(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 ('' !== startupUrl)
{
2016-07-08 07:22:58 +08:00
routeOff();
2016-08-22 05:30:34 +08:00
setHash(root(startupUrl), true);
2016-07-08 07:22:58 +08:00
routeOn();
}
if (jassl && window.crypto && window.crypto.getRandomValues && Settings.capa(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-08-22 05:30:34 +08:00
PgpStore.openpgp.initWorker({path: openPgpWorkerJs()});
}
catch (e)
{
2016-06-07 05:57:52 +08:00
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-08-22 05:30:34 +08:00
jassl(openPgpJs()).then(() => {
if (window.openpgp)
{
2015-11-19 01:32:29 +08:00
openpgpCallback(window.openpgp);
}
});
}
}
else
{
PgpStore.capaOpenPGP(false);
}
2016-07-08 07:22:58 +08:00
startScreens([
2016-07-07 07:11:13 +08:00
MailBoxUserScreen,
Settings.capa(Capa.Settings) ? SettingsUserScreen : null
// false ? AboutUserScreen : null
]);
if (allowGoogle || allowFacebook || allowTwitter)
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
}
2016-08-22 05:30:34 +08:00
Events.sub('interval.2m', () => this.folderInformation(getFolderInboxName()));
2015-11-19 01:32:29 +08:00
Events.sub('interval.3m', () => {
const sF = FolderStore.currentFolderFullNameRaw();
2016-08-22 05:30:34 +08:00
if (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
contactsSyncInterval = 5 <= contactsSyncInterval ? contactsSyncInterval : 20;
contactsSyncInterval = 320 >= contactsSyncInterval ? contactsSyncInterval : 320;
2014-10-29 06:05:50 +08:00
2016-08-24 06:17:50 +08:00
_.delay(() => this.contactsSync(), Magics.Time10s);
_.delay(() => this.folderInformationMultiply(true), Magics.Time2s);
2014-08-20 23:03:12 +08:00
window.setInterval(() => this.contactsSync(), contactsSyncInterval * 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();
2016-08-22 05:30:34 +08:00
if (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);
2016-06-07 05:57:52 +08:00
_.delay(() => Remote.appDelayStart(noop), 35000);
2015-11-19 01:32:29 +08:00
Events.sub('rl.auto-logout', () => this.logout());
2016-08-22 05:30:34 +08:00
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 &&
2016-06-07 05:57:52 +08:00
Settings.capa(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-06-30 08:02:45 +08:00
}
2016-07-02 06:49:59 +08:00
catch (e) {} // eslint-disable-line no-empty
if (Settings.settingsGet('MailToEmail'))
{
2016-06-07 05:57:52 +08:00
mailToHelper(Settings.settingsGet('MailToEmail'), require('View/Popup/Compose'));
}
}, 500);
}
2016-06-07 05:57:52 +08:00
if (!bMobileDevice)
{
2016-06-07 05:57:52 +08:00
_.defer(() => this.initVerticalLayoutResizer(ClientSideKeyName.FolderListSize));
}
}
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
}
if (allowGoogle)
{
window['rl_' + jsHash + '_google_service'] = () => {
SocialStore.google.loading(true);
2015-11-19 01:32:29 +08:00
this.socialUsers();
2014-08-20 23:03:12 +08:00
};
}
if (allowFacebook)
2014-08-20 23:03:12 +08:00
{
window['rl_' + jsHash + '_facebook_service'] = () => {
SocialStore.facebook.loading(true);
2015-11-19 01:32:29 +08:00
this.socialUsers();
2014-08-20 23:03:12 +08:00
};
}
if (allowTwitter)
2014-08-20 23:03:12 +08:00
{
window['rl_' + jsHash + '_twitter_service'] = () => {
SocialStore.twitter.loading(true);
2015-11-19 01:32:29 +08:00
this.socialUsers();
2014-08-20 23:03:12 +08:00
};
}
2016-08-22 05:30:34 +08:00
Events.sub('interval.1m', () => momentReload());
2016-08-22 05:30:34 +08:00
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();