snappymail/dev/App/User.js

1215 lines
34 KiB
JavaScript
Raw Normal View History

2016-07-02 06:49:59 +08:00
import window from 'window';
import _ from '_';
2015-11-19 01:32:29 +08:00
import progressJs from 'progressJs';
2016-06-07 05:57:52 +08:00
import {
2019-07-05 03:19:24 +08:00
noop,
trim,
log,
isArray,
isUnd,
isNormal,
isPosNumeric,
isNonEmptyArray,
pInt,
pString,
delegateRunOnDestroy,
mailToHelper,
jassl
2016-06-07 05:57:52 +08:00
} from 'Common/Utils';
import {
2019-07-05 03:19:24 +08:00
Layout,
Capa,
StorageResultType,
Notification,
FolderType,
SetSystemFoldersNotification,
MessageSetAction,
ClientSideKeyName,
Magics
2016-06-07 05:57:52 +08:00
} from 'Common/Enums';
import { $htmlCL, leftPanelDisabled, bMobileDevice } from 'Common/Globals';
2016-06-07 05:57:52 +08:00
2019-07-05 03:19:24 +08:00
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { runHook } from 'Common/Plugins';
import { momentNowUnix, reload as momentReload } from 'Common/Momentor';
2016-08-22 05:30:34 +08:00
import {
2019-07-05 03:19:24 +08:00
initMessageFlagsFromCache,
setFolderHash,
getFolderHash,
getFolderInboxName,
getFolderFromCacheList,
clearMessageFlagsFromCacheByFolder,
2016-08-22 05:30:34 +08:00
storeMessageFlagsToCacheBySetAction,
storeMessageFlagsToCacheByFolderAndUid
} from 'Common/Cache';
import {
2019-07-05 03:19:24 +08:00
userBackground,
mailBox,
root,
openPgpWorkerJs,
openPgpJs
2016-08-22 05:30:34 +08:00
} 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
2019-07-05 03:19:24 +08:00
import { getNotification, i18n } from 'Common/Translator';
2015-11-19 01:32:29 +08:00
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';
2019-07-05 03:19:24 +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';
2019-07-05 03:19:24 +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';
2019-07-05 03:19:24 +08:00
import { LoginUserScreen } from 'Screen/User/Login';
import { MailBoxUserScreen } from 'Screen/User/MailBox';
import { SettingsUserScreen } from 'Screen/User/Settings';
2016-07-07 07:11:13 +08:00
2019-07-05 03:19:24 +08:00
import { hideLoading, routeOff, routeOn, setHash, startScreens, showScreenPopup } from 'Knoin/Knoin';
2015-11-19 01:32:29 +08:00
2019-07-05 03:19:24 +08:00
import { AbstractApp } from 'App/Abstract';
2015-11-19 01:32:29 +08:00
if (!window.ResizeObserver) {
window.ResizeObserver = class {
constructor(callback) {
this.observer = new window.MutationObserver(mutations => {
let entries = [];
mutations.forEach(mutation => {
if ('style' == mutation.attributeName) {
entries.push({
contentRect: {
width: mutation.target.offsetWidth,
height: mutation.target.offsetHeight
},
target: mutation.target
});
}
});
callback(entries);
});
}
disconnect() {
this.observer.disconnect();
}
observe(target) {
this.observer.observe(target, { attributes: true });
}
};
}
2019-07-05 03:19:24 +08:00
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);
this.moveOrDeleteResponseHelper = this.moveOrDeleteResponseHelper.bind(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);
2019-07-05 03:19:24 +08:00
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
);
2016-05-22 20:27:50 +08:00
// wakeUp
const interval = Magics.Time60m;
var lastTime = (new Date()).getTime();
setInterval(() => {
const currentTime = (new Date()).getTime();
if (currentTime > (lastTime + interval + 1000)) {
2019-07-05 03:19:24 +08:00
if (checkTimestamp()) {
2016-05-22 20:27:50 +08:00
this.reload();
}
2019-07-05 03:19:24 +08:00
Remote.jsVersion((sResult, oData) => {
if (StorageResultType.Success === sResult && oData && !oData.Result) {
this.reload();
}
}, Settings.appSettingsGet('version'));
}
lastTime = currentTime;
}, interval);
2014-08-22 23:08:56 +08:00
2019-07-05 03:19:24 +08:00
if (checkTimestamp()) {
2016-05-22 20:27:50 +08:00
this.reload();
}
2019-07-05 03:19:24 +08:00
if (Settings.settingsGet('UserBackgroundHash')) {
setTimeout(() => {
const img = userBackground(Settings.settingsGet('UserBackgroundHash'));
if (img) {
$htmlCL.add('UserBackground');
window.document.body.style.backgroundImage = "url("+img+")";
}
2016-08-24 06:17:50 +08:00
}, Magics.Time1s);
}
}
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() {
2019-07-05 03:19:24 +08:00
if (window.parent && !!Settings.appSettingsGet('inIframe')) {
2016-05-22 20:27:50 +08:00
window.parent.location.reload();
2019-07-05 03:19:24 +08:00
} else {
2016-05-22 20:27:50 +08:00
window.location.reload();
}
}
2015-11-19 01:32:29 +08:00
reloadFlagsCurrentMessageListAndMessageFromCache() {
MessageStore.messageList().forEach(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) {
2019-07-05 03:19:24 +08:00
let iOffset = (MessageStore.messageListPage() - 1) * SettingsStore.messagesPerPage();
2015-11-19 01:32:29 +08:00
2019-07-05 03:19:24 +08:00
if (bDropCurrenFolderCache) {
2016-08-22 05:30:34 +08:00
setFolderHash(FolderStore.currentFolderFullNameRaw(), '');
}
2014-08-20 23:03:12 +08:00
2019-07-05 03:19:24 +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
2019-07-05 03:19:24 +08:00
setHash(
mailBox(
FolderStore.currentFolderFullNameHash(),
MessageStore.messageListPage(),
MessageStore.messageListSearch(),
MessageStore.messageListThreadUid()
),
true,
true
);
}
2015-02-22 06:00:51 +08:00
MessageStore.messageListLoading(true);
Remote.messageList(
(sResult, oData, bCached) => {
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === sResult && oData && oData.Result) {
MessageStore.messageListError('');
MessageStore.messageListLoading(false);
2015-02-22 06:00:51 +08:00
MessageStore.setMessageList(oData, bCached);
2019-07-05 03:19:24 +08:00
} else if (StorageResultType.Unload === sResult) {
MessageStore.messageListError('');
MessageStore.messageListLoading(false);
2019-07-05 03:19:24 +08:00
} else if (StorageResultType.Abort !== sResult) {
MessageStore.messageList([]);
MessageStore.messageListLoading(false);
2019-07-05 03:19:24 +08:00
MessageStore.messageListError(
oData && oData.ErrorCode ? getNotification(oData.ErrorCode) : i18n('NOTIFICATIONS/CANT_GET_MESSAGE_LIST')
);
}
},
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;
2019-07-05 03:19:24 +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);
2019-07-05 03:19:24 +08:00
if (fResultFunc) {
2014-08-20 23:03:12 +08:00
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() {
2019-07-05 03:19:24 +08:00
const sTrashFolder = FolderStore.trashFolder(),
2016-06-30 08:02:45 +08:00
sSpamFolder = FolderStore.spamFolder();
Object.values(this.moveCache).forEach(item => {
2019-07-05 03:19:24 +08:00
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
2019-07-05 03:19:24 +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 + '$$';
2019-07-05 03:19:24 +08:00
if (!this.moveCache[hash]) {
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 = this.moveCache[hash].Uid.concat(uidsForMove)
.filter((value, index, self) => self.indexOf(value) == index);
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) {
2019-07-05 03:19:24 +08:00
Remote.messagesCopy(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) {
2019-07-05 03:19:24 +08:00
Remote.messagesDelete(this.moveOrDeleteResponseHelper, sFromFolderFullNameRaw, aUidForRemove);
2015-11-19 01:32:29 +08:00
}
moveOrDeleteResponseHelper(sResult, oData) {
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === sResult && FolderStore.currentFolder()) {
if (oData && isArray(oData.Result) && 2 === oData.Result.length) {
2016-08-22 05:30:34 +08:00
setFolderHash(oData.Result[0], oData.Result[1]);
2019-07-05 03:19:24 +08:00
} else {
2016-08-22 05:30:34 +08:00
setFolderHash(FolderStore.currentFolderFullNameRaw(), '');
2014-08-20 23:03:12 +08:00
if (oData && [Notification.CantMoveMessage, Notification.CantCopyMessage].includes(oData.ErrorCode)) {
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
this.reloadMessageList(!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) {
2019-07-05 03:19:24 +08:00
let oMoveFolder = null,
2016-06-30 08:02:45 +08:00
nSetSystemFoldersNotification = null;
2014-03-20 00:18:28 +08:00
2019-07-05 03:19:24 +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;
2019-07-05 03:19:24 +08:00
if (bUseFolder) {
if (
(FolderType.Spam === iDeleteType && UNUSED_OPTION_VALUE === FolderStore.spamFolder()) ||
2016-06-07 05:57:52 +08:00
(FolderType.Trash === iDeleteType && UNUSED_OPTION_VALUE === FolderStore.trashFolder()) ||
2019-07-05 03:19:24 +08:00
(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
2019-07-05 03:19:24 +08:00
if (!oMoveFolder && bUseFolder) {
2016-07-08 07:22:58 +08:00
showScreenPopup(require('View/Popup/FolderSystem'), [nSetSystemFoldersNotification]);
2019-07-05 03:19:24 +08:00
} else if (
!bUseFolder ||
(FolderType.Trash === iDeleteType &&
(sFromFolderFullNameRaw === FolderStore.spamFolder() || sFromFolderFullNameRaw === FolderStore.trashFolder()))
) {
showScreenPopup(require('View/Popup/Ask'), [
i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'),
() => {
this.messagesDeleteHelper(sFromFolderFullNameRaw, aUidForRemove);
MessageStore.removeMessagesFromList(sFromFolderFullNameRaw, aUidForRemove);
}
]);
} else if (oMoveFolder) {
2014-08-20 23:03:12 +08:00
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) {
if (sFromFolderFullNameRaw !== sToFolderFullNameRaw && isArray(aUidForMove) && aUidForMove.length) {
2019-07-05 03:19:24 +08:00
const oFromFolder = getFolderFromCacheList(sFromFolderFullNameRaw),
2016-08-22 05:30:34 +08:00
oToFolder = getFolderFromCacheList(sToFolderFullNameRaw);
2019-07-05 03:19:24 +08:00
if (oFromFolder && oToFolder) {
if (isUnd(bCopy) ? false : !!bCopy) {
2014-08-20 23:03:12 +08:00
this.messagesCopyHelper(oFromFolder.fullNameRaw, oToFolder.fullNameRaw, aUidForMove);
2019-07-05 03:19:24 +08:00
} else {
2014-08-20 23:03:12 +08:00
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);
2019-07-05 03:19:24 +08:00
if (callback) {
prom
.then((value) => !!value)
.then(callback)
.catch(() => {
setTimeout(() => {
2019-07-05 03:19:24 +08:00
if (callback) {
callback(false); // eslint-disable-line callback-return
}
}, 1);
});
2016-07-02 06:49:59 +08:00
}
2015-11-19 01:32:29 +08:00
}
foldersPromisesActionHelper(promise, errorDefCode) {
2019-07-05 03:19:24 +08:00
Promises.abort('Folders')
.fastResolve(true)
2015-11-19 01:32:29 +08:00
.then(() => promise)
2019-07-05 03:19:24 +08:00
.then(
() => {
Promises.foldersReloadWithTimeout(FolderStore.foldersLoading);
},
(errorCode) => {
FolderStore.folderList.error(getNotification(errorCode, '', errorDefCode));
Promises.foldersReloadWithTimeout(FolderStore.foldersLoading);
}
);
2015-11-19 01:32:29 +08:00
}
reloadOpenPgpKeys() {
2019-07-05 03:19:24 +08:00
if (PgpStore.capaOpenPGP()) {
const keys = [],
email = new EmailModel(),
openpgpKeyring = PgpStore.openpgpKeyring,
openpgpKeys = openpgpKeyring ? openpgpKeyring.getAllKeys() : [];
openpgpKeys.forEach((oItem, iIndex) => {
2019-07-05 03:19:24 +08:00
if (oItem && oItem.primaryKey) {
const aEmails = [],
aUsers = [],
primaryUser = oItem.getPrimaryUser(),
2019-07-05 03:19:24 +08:00
user =
primaryUser && primaryUser.user
? primaryUser.user.userId.userid
: oItem.users && oItem.users[0]
? oItem.users[0].userId.userid
: '';
if (oItem.users) {
oItem.users.forEach(item => {
2019-07-05 03:19:24 +08:00
if (item.userId) {
email.clear();
2017-09-28 01:58:15 +08:00
email.parse(item.userId.userid);
2019-07-05 03:19:24 +08:00
if (email.validate()) {
aEmails.push(email.email);
2016-05-24 01:33:01 +08:00
aUsers.push(item.userId.userid);
}
}
});
}
2019-07-05 03:19:24 +08:00
if (aEmails.length) {
keys.push(
new OpenPgpKeyModel(
iIndex,
oItem.primaryKey.getFingerprint(),
oItem.primaryKey
.getKeyId()
.toHex()
.toLowerCase(),
oItem.getKeyIds()
.map(item => (item && item.toHex ? item.toHex() : null))
.filter((value, index, self) => !!value && self.indexOf(value) == index),
2019-07-05 03:19:24 +08:00
aUsers,
aEmails,
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);
//
// Remote.accountsCounts((sResult, oData) => {
//
// AccountStore.accounts.loading(false);
//
// if (StorageResultType.Success === sResult && oData.Result && oData.Result['Counts'])
// {
// var
// sEmail = AccountStore.email(),
// aAcounts = AccountStore.accounts()
// ;
//
// oData.Result['Counts'].find(oItem => {
//
// var oAccount = aAcounts.find(oAccount => {
// return oAccount && oItem[0] === oAccount.email && sEmail !== oAccount.email;
// });
//
// if (oAccount)
// {
// oAccount.count(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);
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === sResult && oData.Result) {
const counts = {},
2016-06-30 08:02:45 +08:00
sAccountEmail = AccountStore.email();
2019-07-05 03:19:24 +08:00
let parentEmail = Settings.settingsGet('ParentEmail');
2013-12-07 06:45:46 +08:00
2016-08-24 06:17:50 +08:00
parentEmail = '' === parentEmail ? sAccountEmail : parentEmail;
2019-07-05 03:19:24 +08:00
if (isArray(oData.Result.Accounts)) {
AccountStore.accounts().forEach(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());
2019-07-05 03:19:24 +08:00
AccountStore.accounts(
oData.Result.Accounts.map(
sValue => new AccountModel(sValue, sValue !== parentEmail, counts[sValue] || 0)
2019-07-05 03:19:24 +08:00
)
);
2014-08-20 23:03:12 +08:00
}
2019-07-05 03:19:24 +08:00
if (isUnd(bBoot) ? false : !!bBoot) {
setTimeout(() => this.accountsCounts(), 1000 * 5);
2015-11-19 01:32:29 +08:00
Events.sub('interval.10m-after5m', () => this.accountsCounts());
}
2019-07-05 03:19:24 +08:00
if (isArray(oData.Result.Identities)) {
2016-06-07 05:57:52 +08:00
delegateRunOnDestroy(IdentityStore.identities());
2015-01-29 05:24:58 +08:00
2019-07-05 03:19:24 +08:00
IdentityStore.identities(
oData.Result.Identities.map(identityData => {
2019-07-05 03:19:24 +08:00
const id = pString(identityData.Id),
email = pString(identityData.Email),
identity = new IdentityModel(id, email);
2013-12-07 06:45:46 +08:00
2019-07-05 03:19:24 +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
2019-07-05 03:19:24 +08:00
return identity;
})
);
}
}
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);
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data.Result && isArray(data.Result.Templates)) {
2016-06-07 05:57:52 +08:00
delegateRunOnDestroy(TemplateStore.templates());
2019-07-05 03:19:24 +08:00
TemplateStore.templates(
data.Result.Templates.map(templateData => {
const template = new TemplateModel();
return template.parse(templateData) ? template : null;
}).filter(value => !!value)
2019-07-05 03:19:24 +08:00
);
}
});
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
quota() {
Remote.quota((result, data) => {
2019-07-05 03:19:24 +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) {
2019-07-05 03:19:24 +08:00
if ('' !== trim(folder)) {
Remote.folderInformation(
(result, data) => {
if (StorageResultType.Success === result) {
if (data && data.Result && data.Result.Hash && data.Result.Folder) {
let uid = '',
check = false,
unreadCountChange = false;
2019-07-05 03:19:24 +08:00
const folderFromCache = getFolderFromCacheList(data.Result.Folder);
if (folderFromCache) {
folderFromCache.interval = momentNowUnix();
2019-07-05 03:19:24 +08:00
if (data.Result.Hash) {
setFolderHash(data.Result.Folder, data.Result.Hash);
}
2019-07-05 03:19:24 +08:00
if (isNormal(data.Result.MessageCount)) {
folderFromCache.messageCountAll(data.Result.MessageCount);
}
2019-07-05 03:19:24 +08:00
if (isNormal(data.Result.MessageUnseenCount)) {
if (pInt(folderFromCache.messageCountUnread()) !== pInt(data.Result.MessageUnseenCount)) {
unreadCountChange = true;
2014-08-20 23:03:12 +08:00
}
2019-07-05 03:19:24 +08:00
folderFromCache.messageCountUnread(data.Result.MessageUnseenCount);
2014-08-20 23:03:12 +08:00
}
2019-07-05 03:19:24 +08:00
if (unreadCountChange) {
clearMessageFlagsFromCacheByFolder(folderFromCache.fullNameRaw);
2014-08-20 23:03:12 +08:00
}
2019-07-05 03:19:24 +08:00
if (data.Result.Flags) {
for (uid in data.Result.Flags) {
if (Object.prototype.hasOwnProperty.call(data.Result.Flags, uid)) {
2019-07-05 03:19:24 +08:00
check = true;
const flags = data.Result.Flags[uid];
storeMessageFlagsToCacheByFolderAndUid(folderFromCache.fullNameRaw, uid.toString(), [
!flags.IsSeen,
!!flags.IsFlagged,
!!flags.IsAnswered,
!!flags.IsForwarded,
!!flags.IsReadReceipt
]);
}
}
2014-08-20 23:03:12 +08:00
2019-07-05 03:19:24 +08:00
if (check) {
this.reloadFlagsCurrentMessageListAndMessageFromCache();
}
}
2019-07-05 03:19:24 +08:00
MessageStore.initUidNextAndNewMessages(
folderFromCache.fullNameRaw,
data.Result.UidNext,
data.Result.NewMessages
);
const hash = getFolderHash(data.Result.Folder);
if (data.Result.Hash !== hash || '' === hash || unreadCountChange) {
if (folderFromCache.fullNameRaw === FolderStore.currentFolderFullNameRaw()) {
this.reloadMessageList();
} else if (getFolderInboxName() === folderFromCache.fullNameRaw) {
this.recacheInboxMessageList();
}
2014-08-20 23:03:12 +08:00
}
}
}
}
2019-07-05 03:19:24 +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) {
const folders = FolderStore.getNextFolderNames();
2019-07-05 03:19:24 +08:00
if (isNonEmptyArray(folders)) {
2015-11-19 01:32:29 +08:00
Remote.folderInformationMultiply((sResult, oData) => {
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === sResult) {
if (oData && oData.Result && oData.Result.List && isNonEmptyArray(oData.Result.List)) {
2016-08-22 05:30:34 +08:00
const utc = momentNowUnix();
oData.Result.List.forEach(item => {
2019-07-05 03:19:24 +08:00
const hash = getFolderHash(item.Folder),
2016-08-24 06:17:50 +08:00
folder = getFolderFromCacheList(item.Folder);
2019-07-05 03:19:24 +08:00
let unreadCountChange = false;
2019-07-05 03:19:24 +08:00
if (folder) {
folder.interval = utc;
2019-07-05 03:19:24 +08:00
if (item.Hash) {
2016-08-24 06:17:50 +08:00
setFolderHash(item.Folder, item.Hash);
2014-08-20 23:03:12 +08:00
}
2019-07-05 03:19:24 +08:00
if (isNormal(item.MessageCount)) {
2016-08-24 06:17:50 +08:00
folder.messageCountAll(item.MessageCount);
2014-08-20 23:03:12 +08:00
}
2019-07-05 03:19:24 +08:00
if (isNormal(item.MessageUnseenCount)) {
if (pInt(folder.messageCountUnread()) !== pInt(item.MessageUnseenCount)) {
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
}
2019-07-05 03:19:24 +08:00
if (unreadCountChange) {
2016-08-22 05:30:34 +08:00
clearMessageFlagsFromCacheByFolder(folder.fullNameRaw);
2014-08-20 23:03:12 +08:00
}
2019-07-05 03:19:24 +08:00
if (item.Hash !== hash || '' === hash) {
if (folder.fullNameRaw === FolderStore.currentFolderFullNameRaw()) {
2015-11-19 01:32:29 +08:00
this.reloadMessageList();
2014-08-20 23:03:12 +08:00
}
2019-07-05 03:19:24 +08:00
} else if (unreadCountChange) {
if (folder.fullNameRaw === FolderStore.currentFolderFullNameRaw()) {
2016-08-24 06:17:50 +08:00
const list = MessageStore.messageList();
2019-07-05 03:19:24 +08:00
if (isNonEmptyArray(list)) {
2016-08-24 06:17:50 +08:00
this.folderInformation(folder.fullNameRaw, list);
2014-08-20 23:03:12 +08:00
}
}
}
}
});
2019-07-05 03:19:24 +08:00
if (boot) {
setTimeout(() => 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) {
2019-07-05 03:19:24 +08:00
let folder = null,
alreadyUnread = 0,
rootUids = [];
2015-03-06 08:42:40 +08:00
2019-07-05 03:19:24 +08:00
if (isUnd(messages) || !messages) {
messages = MessageStore.messageListChecked();
2015-03-06 08:42:40 +08:00
}
rootUids = messages.map(oMessage => oMessage && oMessage.uid ? oMessage.uid : null)
.filter((value, index, self) => !!value && self.indexOf(value) == index);
2015-03-06 08:42:40 +08:00
if ('' !== sFolderFullNameRaw && rootUids.length) {
2019-07-05 03:19:24 +08:00
switch (iSetAction) {
2016-06-07 05:57:52 +08:00
case MessageSetAction.SetSeen:
rootUids.forEach(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);
2019-07-05 03:19:24 +08:00
if (folder) {
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:
rootUids.forEach(sSubUid => {
2019-07-05 03:19:24 +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);
2019-07-05 03:19:24 +08:00
if (folder) {
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:
rootUids.forEach(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:
rootUids.forEach(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
}
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) => {
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data && isArray(data.Result)) {
autocompleteCallback(
data.Result.map(item => (item && item[0] ? new EmailModel(item[0], item[1]) : null)).filter(value => !!value)
2019-07-05 03:19:24 +08:00
);
} else if (StorageResultType.Abort !== result) {
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);
2019-07-05 03:19:24 +08:00
if (!isArray(aExpandedList)) {
2014-08-22 23:08:56 +08:00
aExpandedList = [];
}
2019-07-05 03:19:24 +08:00
if (bExpanded) {
if (!aExpandedList.includes(sFullNameHash))
aExpandedList.push(sFullNameHash);
2019-07-05 03:19:24 +08:00
} else {
aExpandedList = aExpandedList.filter(value => value !== sFullNameHash);
2014-08-22 23:08:56 +08:00
}
2016-06-07 05:57:52 +08:00
Local.set(ClientSideKeyName.ExpandedFolders, aExpandedList);
2015-11-19 01:32:29 +08:00
}
setLayoutResizer(source, target, sClientSideKeyName, mode) {
if (mode) {
source.classList.add('resizable');
if (!source.querySelector('.resizer')) {
const resizer = window.document.createElement('div'),
cssint = s => parseFloat(window.getComputedStyle(source, null).getPropertyValue(s).replace('px', ''));
resizer.className = 'resizer';
source.appendChild(resizer);
resizer.addEventListener('mousedown', {
source: source,
mode: mode,
handleEvent: function(e) {
if ('mousedown' == e.type) {
e.preventDefault();
this.pos = ('width' == this.mode) ? e.pageX : e.pageY;
this.min = cssint('min-'+this.mode);
this.max = cssint('max-'+this.mode);
this.org = cssint(this.mode);
window.addEventListener('mousemove', this);
window.addEventListener('mouseup', this);
} else if ('mousemove' == e.type) {
const length = this.org + (('width' == this.mode ? e.pageX : e.pageY) - this.pos);
if (length >= this.min && length <= this.max ) {
this.source.style[this.mode] = length + 'px';
}
} else if ('mouseup' == e.type) {
window.removeEventListener('mousemove', this);
window.removeEventListener('mouseup', this);
}
2015-01-09 07:31:31 +08:00
}
});
if ('width' == mode) {
2020-07-17 20:24:55 +08:00
source.observer = new window.ResizeObserver(() => {
target.style.left = source.offsetWidth + 'px';
Local.set(sClientSideKeyName, source.offsetWidth);
});
} else {
2020-07-17 20:24:55 +08:00
source.observer = new window.ResizeObserver(() => {
target.style.top = (4 + source.offsetTop + source.offsetHeight) + 'px';
Local.set(sClientSideKeyName, source.offsetHeight);
});
2015-01-09 07:31:31 +08:00
}
}
source.observer.observe(source, { box: 'border-box' });
const length = Local.get(sClientSideKeyName);
if (length) {
if ('width' == mode) {
source.style.width = length + 'px';
} else {
source.style.height = length + 'px';
}
}
} else {
source.observer && source.observer.disconnect();
source.classList.remove('resizable');
target.removeAttribute('style');
source.removeAttribute('style');
}
}
initHorizontalLayoutResizer(sClientSideKeyName) {
2020-07-17 20:24:55 +08:00
const top = window.document.querySelector('.b-message-list-wrapper'),
bottom = window.document.querySelector('.b-message-view-wrapper'),
fDisable = bDisable => {
this.setLayoutResizer(top, bottom, sClientSideKeyName,
(bDisable || !$htmlCL.contains('rl-bottom-preview-pane')) ? null : 'height');
2020-07-17 20:24:55 +08:00
};
if (top && bottom) {
fDisable(false);
Events.sub('layout', layout => fDisable(Layout.BottomPreview !== layout));
}
2016-04-21 01:12:51 +08:00
}
2015-01-09 07:31:31 +08:00
initVerticalLayoutResizer(sClientSideKeyName) {
2020-07-17 20:24:55 +08:00
const left = window.document.getElementById('rl-left'),
right = window.document.getElementById('rl-right'),
fDisable = bDisable => {
this.setLayoutResizer(left, right, sClientSideKeyName, bDisable ? null : 'width');
2020-07-17 20:24:55 +08:00
};
if (left && right) {
2014-08-22 23:08:56 +08:00
fDisable(false);
Events.sub('left-panel.off', () => fDisable(true));
Events.sub('left-panel.on', () => 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(() => {
2019-07-05 03:19:24 +08:00
this.loginAndLogoutReload(
false,
true,
0 < (Settings.settingsGet('ParentEmail')||{length:0}).length
2019-07-05 03:19:24 +08:00
);
2015-02-19 03:52:52 +08:00
});
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() {
$htmlCL.remove('rl-user-auth');
$htmlCL.add('rl-user-no-auth');
2016-06-07 05:57:52 +08:00
const customLoginLink = pString(Settings.appSettingsGet('customLoginLink'));
2019-07-05 03:19:24 +08:00
if (!customLoginLink) {
startScreens([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');
2019-07-05 03:19:24 +08:00
} 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() {
2019-07-05 03:19:24 +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();
2019-07-05 03:19:24 +08:00
let contactsSyncInterval = pInt(Settings.settingsGet('ContactsSyncInterval'));
2020-03-11 21:17:52 +08:00
const startupUrl = pString(Settings.settingsGet('StartupUrl'));
2019-07-05 03:19:24 +08:00
if (progressJs) {
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('');
2019-07-05 03:19:24 +08:00
if (Settings.settingsGet('Auth')) {
$htmlCL.add('rl-user-auth');
2019-07-05 03:19:24 +08:00
if (
Settings.capa(Capa.TwoFactor) &&
2016-06-07 05:57:52 +08:00
Settings.capa(Capa.TwoFactorForce) &&
2019-07-05 03:19:24 +08:00
Settings.settingsGet('RequireTwoFactor')
) {
this.bootend();
this.bootstartTwoFactorScreen();
2019-07-05 03:19:24 +08:00
} else {
2016-06-17 07:23:49 +08:00
this.setWindowTitle(i18n('TITLES/LOADING'));
2014-08-20 23:03:12 +08:00
// require.ensure([], function() { // require code splitting
2015-11-19 01:32:29 +08:00
this.foldersReload((value) => {
this.bootend();
2019-07-05 03:19:24 +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();
}
2019-07-05 03:19:24 +08:00
if (jassl && window.crypto && window.crypto.getRandomValues && Settings.capa(Capa.OpenPGP)) {
2015-11-19 01:32:29 +08:00
const openpgpCallback = (openpgp) => {
PgpStore.openpgp = openpgp;
2015-07-06 02:06:19 +08:00
2019-07-05 03:19:24 +08:00
if (window.Worker) {
try {
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();
};
2019-07-05 03:19:24 +08:00
if (window.openpgp) {
2015-11-19 01:32:29 +08:00
openpgpCallback(window.openpgp);
2019-07-05 03:19:24 +08:00
} else {
2016-08-22 05:30:34 +08:00
jassl(openPgpJs()).then(() => {
2019-07-05 03:19:24 +08:00
if (window.openpgp) {
2015-11-19 01:32:29 +08:00
openpgpCallback(window.openpgp);
}
});
}
2019-07-05 03:19:24 +08:00
} 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
]);
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();
2019-07-05 03:19:24 +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
setTimeout(() => this.contactsSync(), Magics.Time10s);
setTimeout(() => 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
setTimeout(() => {
2015-11-19 01:32:29 +08:00
const sF = FolderStore.currentFolderFullNameRaw();
2019-07-05 03:19:24 +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
setTimeout(() => this.quota(), 5000);
setTimeout(() => 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');
2019-07-05 03:19:24 +08:00
if (Settings.settingsGet('WelcomePageUrl')) {
setTimeout(() => this.bootstartWelcomePopup(Settings.settingsGet('WelcomePageUrl')), 1000);
2015-04-10 06:05:49 +08:00
}
2019-07-05 03:19:24 +08:00
if (
!!Settings.settingsGet('AccountSignMe') &&
window.navigator.registerProtocolHandler &&
2019-07-05 03:19:24 +08:00
Settings.capa(Capa.Composer)
) {
setTimeout(() => {
try {
2019-07-05 03:19:24 +08:00
window.navigator.registerProtocolHandler(
'mailto',
window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
2019-07-05 03:19:24 +08:00
'' + (Settings.settingsGet('Title') || 'RainLoop')
);
} catch (e) {} // eslint-disable-line no-empty
2019-07-05 03:19:24 +08:00
if (Settings.settingsGet('MailToEmail')) {
2016-06-07 05:57:52 +08:00
mailToHelper(Settings.settingsGet('MailToEmail'), require('View/Popup/Compose'));
}
}, 500);
}
2019-07-05 03:19:24 +08:00
if (!bMobileDevice) {
2016-06-07 05:57:52 +08:00
_.defer(() => this.initVerticalLayoutResizer(ClientSideKeyName.FolderListSize));
}
2019-07-05 03:19:24 +08:00
} else {
2015-05-08 00:44:41 +08:00
this.logout();
}
2015-11-19 01:32:29 +08:00
});
// }); // require code splitting
}
2019-07-05 03:19:24 +08:00
} else {
this.bootend();
2014-08-27 23:59:44 +08:00
this.bootstartLoginScreen();
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();