2021-01-26 18:46:30 +08:00
|
|
|
import 'External/User/ko';
|
2021-01-26 05:00:13 +08:00
|
|
|
|
2022-06-08 00:46:06 +08:00
|
|
|
import { SMAudio } from 'Common/Audio';
|
2024-02-11 23:40:35 +08:00
|
|
|
import { pInt } from 'Common/Utils';
|
|
|
|
import { mailToHelper, setLayoutResizer, dropdownsDetectVisibility, loadAccountsAndIdentities } from 'Common/UtilsUser';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-01-25 05:58:06 +08:00
|
|
|
import {
|
2019-07-05 03:19:24 +08:00
|
|
|
FolderType,
|
2022-03-14 22:42:05 +08:00
|
|
|
ClientSideKeyNameFolderListSize
|
2021-01-25 05:58:06 +08:00
|
|
|
} from 'Common/EnumsUser';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-02-17 03:12:23 +08:00
|
|
|
import {
|
|
|
|
doc,
|
|
|
|
elementById,
|
|
|
|
$htmlCL,
|
|
|
|
Settings,
|
2021-03-10 18:44:48 +08:00
|
|
|
SettingsGet,
|
2022-02-24 18:19:19 +08:00
|
|
|
leftPanelDisabled,
|
2022-03-09 22:08:22 +08:00
|
|
|
addEventsListener,
|
|
|
|
addShortcut
|
2021-02-17 03:12:23 +08:00
|
|
|
} 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';
|
2016-08-22 05:30:34 +08:00
|
|
|
|
|
|
|
import {
|
2019-07-05 03:19:24 +08:00
|
|
|
getFolderInboxName,
|
2020-10-25 20:50:26 +08:00
|
|
|
getFolderFromCacheList
|
2016-08-22 05:30:34 +08:00
|
|
|
} from 'Common/Cache';
|
|
|
|
|
2022-02-24 02:26:52 +08:00
|
|
|
import { i18n, reloadTime } from 'Common/Translator';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
|
|
|
import { NotificationUserStore } from 'Stores/User/Notification';
|
|
|
|
import { AccountUserStore } from 'Stores/User/Account';
|
|
|
|
import { ContactUserStore } from 'Stores/User/Contact';
|
|
|
|
import { FolderUserStore } from 'Stores/User/Folder';
|
|
|
|
import { PgpUserStore } from 'Stores/User/Pgp';
|
2024-02-21 01:29:35 +08:00
|
|
|
import { SMimeUserStore } from 'Stores/User/SMime';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { MessagelistUserStore } from 'Stores/User/Messagelist';
|
2023-03-18 06:20:42 +08:00
|
|
|
import { ThemeStore, initThemes } from 'Stores/Theme';
|
2022-03-31 23:39:53 +08:00
|
|
|
import { LanguageStore } from 'Stores/Language';
|
2022-09-14 14:53:30 +08:00
|
|
|
import { MessageUserStore } from 'Stores/User/Message';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
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
|
|
|
|
2021-08-31 22:17:20 +08:00
|
|
|
import { startScreens, showScreenPopup, arePopupsVisible } 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
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
import { ComposePopupView } from 'View/Popup/Compose';
|
|
|
|
import { FolderSystemPopupView } from 'View/Popup/FolderSystem';
|
|
|
|
import { AskPopupView } from 'View/Popup/Ask';
|
2020-09-17 06:02:35 +08:00
|
|
|
|
2022-02-24 06:11:12 +08:00
|
|
|
import {
|
2022-08-23 03:52:00 +08:00
|
|
|
folderInformation,
|
2022-02-24 06:11:12 +08:00
|
|
|
folderInformationMultiply,
|
2023-08-21 22:02:57 +08:00
|
|
|
setRefreshFoldersInterval
|
2022-02-24 06:11:12 +08:00
|
|
|
} from 'Common/Folders';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { loadFolders } from 'Model/FolderCollection';
|
2022-02-08 00:27:25 +08:00
|
|
|
|
2022-03-31 23:39:53 +08:00
|
|
|
export class AppUser extends AbstractApp {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2015-11-19 01:32:29 +08:00
|
|
|
super(Remote);
|
2014-04-09 00:08:16 +08:00
|
|
|
|
2020-07-17 01:49:56 +08:00
|
|
|
// wakeUp
|
2020-08-14 04:58:41 +08:00
|
|
|
const interval = 3600000; // 60m
|
2022-02-24 02:26:52 +08:00
|
|
|
let lastTime = Date.now();
|
2020-07-17 01:49:56 +08:00
|
|
|
setInterval(() => {
|
2020-09-04 23:07:35 +08:00
|
|
|
const currentTime = Date.now();
|
2022-10-10 19:52:56 +08:00
|
|
|
(currentTime > (lastTime + interval + 1000))
|
|
|
|
&& Remote.request('Version',
|
2022-09-30 20:01:57 +08:00
|
|
|
iError => (100 < iError) && location.reload(),
|
2023-01-26 17:41:55 +08:00
|
|
|
{ version: Settings.app('version') }
|
2021-12-03 06:15:24 +08:00
|
|
|
);
|
2020-07-17 01:49:56 +08:00
|
|
|
lastTime = currentTime;
|
|
|
|
}, interval);
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2022-09-28 05:55:29 +08:00
|
|
|
addEventsListener(doc, ['keydown','keyup'], (ev=>$htmlCL.toggle('rl-ctrl-key-pressed', ev.ctrlKey)).debounce(500));
|
2021-02-17 21:40:21 +08:00
|
|
|
|
2022-03-09 22:08:22 +08:00
|
|
|
addShortcut('escape,enter', '', dropdownsDetectVisibility);
|
2022-03-08 17:52:08 +08:00
|
|
|
addEventListener('click', dropdownsDetectVisibility);
|
2022-05-18 23:15:31 +08:00
|
|
|
|
|
|
|
this.folderList = FolderUserStore.folderList;
|
2023-04-04 17:57:52 +08:00
|
|
|
this.messageList = MessagelistUserStore;
|
2024-03-18 19:25:24 +08:00
|
|
|
|
|
|
|
this.ask = AskPopupView;
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2022-09-28 00:59:07 +08:00
|
|
|
* @param {number} iFolderType
|
2021-11-30 17:19:43 +08:00
|
|
|
* @param {string} sFromFolderFullName
|
2022-09-28 05:46:13 +08:00
|
|
|
* @param {Set} oUids
|
2022-09-28 00:59:07 +08:00
|
|
|
* @param {boolean=} bDelete = false
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2022-09-28 05:46:13 +08:00
|
|
|
moveMessagesToFolderType(iFolderType, sFromFolderFullName, oUids, bDelete) {
|
2019-07-05 03:19:24 +08:00
|
|
|
let oMoveFolder = null,
|
2022-12-15 20:49:39 +08:00
|
|
|
nSetSystemFoldersNotification = 0;
|
2014-03-20 00:18:28 +08:00
|
|
|
|
2022-09-28 00:59:07 +08:00
|
|
|
switch (iFolderType) {
|
2022-12-15 20:49:39 +08:00
|
|
|
case FolderType.Junk:
|
2021-03-11 05:41:35 +08:00
|
|
|
oMoveFolder = getFolderFromCacheList(FolderUserStore.spamFolder());
|
2022-12-15 20:49:39 +08:00
|
|
|
nSetSystemFoldersNotification = iFolderType;
|
2022-09-28 05:55:29 +08:00
|
|
|
bDelete = bDelete || UNUSED_OPTION_VALUE === FolderUserStore.spamFolder();
|
2014-08-20 23:03:12 +08:00
|
|
|
break;
|
2022-12-15 20:49:39 +08:00
|
|
|
case FolderType.Inbox:
|
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:
|
2021-03-11 05:41:35 +08:00
|
|
|
oMoveFolder = getFolderFromCacheList(FolderUserStore.trashFolder());
|
2022-12-15 20:49:39 +08:00
|
|
|
nSetSystemFoldersNotification = iFolderType;
|
2022-09-28 05:55:29 +08:00
|
|
|
bDelete = bDelete || UNUSED_OPTION_VALUE === FolderUserStore.trashFolder()
|
|
|
|
|| sFromFolderFullName === FolderUserStore.spamFolder()
|
|
|
|
|| sFromFolderFullName === FolderUserStore.trashFolder();
|
2014-08-20 23:03:12 +08:00
|
|
|
break;
|
2016-06-07 05:57:52 +08:00
|
|
|
case FolderType.Archive:
|
2021-03-11 05:41:35 +08:00
|
|
|
oMoveFolder = getFolderFromCacheList(FolderUserStore.archiveFolder());
|
2022-12-15 20:49:39 +08:00
|
|
|
nSetSystemFoldersNotification = iFolderType;
|
2022-09-28 05:55:29 +08:00
|
|
|
bDelete = bDelete || UNUSED_OPTION_VALUE === FolderUserStore.archiveFolder();
|
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
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2023-10-08 20:45:50 +08:00
|
|
|
if (bDelete) {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(AskPopupView, [
|
2019-07-05 03:19:24 +08:00
|
|
|
i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'),
|
|
|
|
() => {
|
2023-08-21 22:02:57 +08:00
|
|
|
MessagelistUserStore.moveMessages(sFromFolderFullName, oUids);
|
2019-07-05 03:19:24 +08:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
} else if (oMoveFolder) {
|
2023-08-21 22:02:57 +08:00
|
|
|
MessagelistUserStore.moveMessages(sFromFolderFullName, oUids, oMoveFolder.fullName);
|
2023-10-08 20:45:50 +08:00
|
|
|
} else {
|
|
|
|
showScreenPopup(FolderSystemPopupView, [nSetSystemFoldersNotification]);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +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) {
|
2022-08-23 03:52:00 +08:00
|
|
|
folderInformation(folder, list);
|
2016-04-21 01:12:51 +08:00
|
|
|
}
|
2013-12-16 01:16:25 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
logout() {
|
2023-07-05 02:26:31 +08:00
|
|
|
localStorage.removeItem('register_protocol_offered');
|
2022-10-19 05:32:47 +08:00
|
|
|
Remote.request('Logout', () => rl.logoutReload(Settings.app('customLogoutLink')));
|
2016-04-21 01:12:51 +08:00
|
|
|
}
|
2015-02-19 03:52:52 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
bootstart() {
|
|
|
|
super.bootstart();
|
2014-05-13 16:29:36 +08:00
|
|
|
|
2021-08-31 22:21:40 +08:00
|
|
|
addEventListener('beforeunload', event => {
|
2023-03-20 22:21:56 +08:00
|
|
|
if (arePopupsVisible() || (!SettingsUserStore.usePreviewPane() && MessageUserStore.message())) {
|
2021-08-31 22:21:40 +08:00
|
|
|
event.preventDefault();
|
2023-02-21 22:45:21 +08:00
|
|
|
return event.returnValue = i18n('POPUPS_ASK/EXIT_ARE_YOU_SURE');
|
2021-08-31 22:21:40 +08:00
|
|
|
}
|
|
|
|
}, {capture: true});
|
2021-11-01 18:24:11 +08:00
|
|
|
}
|
2021-03-05 23:46:40 +08:00
|
|
|
|
2022-10-04 16:04:41 +08:00
|
|
|
refresh() {
|
2023-03-18 06:20:42 +08:00
|
|
|
initThemes();
|
2023-02-21 18:52:50 +08:00
|
|
|
LanguageStore.language(SettingsGet('language'));
|
2022-10-04 16:04:41 +08:00
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
|
2021-11-01 18:24:11 +08:00
|
|
|
start() {
|
2021-03-10 18:44:48 +08:00
|
|
|
if (SettingsGet('Auth')) {
|
2022-11-14 16:15:25 +08:00
|
|
|
rl.setTitle(i18n('GLOBAL/LOADING'));
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2022-06-08 00:46:06 +08:00
|
|
|
SMAudio.notifications(!!SettingsGet('SoundNotification'));
|
|
|
|
NotificationUserStore.enabled(!!SettingsGet('DesktopNotifications'));
|
2021-09-23 20:24:06 +08:00
|
|
|
|
|
|
|
AccountUserStore.email(SettingsGet('Email'));
|
|
|
|
|
2021-11-19 19:44:53 +08:00
|
|
|
SettingsUserStore.init();
|
2021-11-24 15:36:27 +08:00
|
|
|
ContactUserStore.init();
|
2021-11-19 19:44:53 +08:00
|
|
|
|
2022-02-24 02:26:52 +08:00
|
|
|
loadFolders(value => {
|
2021-04-13 01:15:33 +08:00
|
|
|
try {
|
|
|
|
if (value) {
|
|
|
|
startScreens([
|
|
|
|
MailBoxUserScreen,
|
2021-09-23 17:05:19 +08:00
|
|
|
SettingsUserScreen
|
2021-04-13 01:15:33 +08:00
|
|
|
]);
|
|
|
|
|
2023-02-01 19:21:31 +08:00
|
|
|
setRefreshFoldersInterval(pInt(SettingsGet('CheckMailInterval')));
|
2014-10-29 06:05:50 +08:00
|
|
|
|
2024-02-11 23:40:35 +08:00
|
|
|
loadAccountsAndIdentities();
|
2015-02-19 03:52:52 +08:00
|
|
|
|
2021-04-13 01:15:33 +08:00
|
|
|
setTimeout(() => {
|
2021-11-30 17:19:43 +08:00
|
|
|
const cF = FolderUserStore.currentFolderFullName();
|
2022-10-10 19:52:56 +08:00
|
|
|
getFolderInboxName() === cF || folderInformation(cF);
|
2022-02-24 02:26:52 +08:00
|
|
|
FolderUserStore.hasCapability('LIST-STATUS') || folderInformationMultiply(true);
|
2021-04-13 01:15:33 +08:00
|
|
|
}, 1000);
|
|
|
|
|
2021-12-03 06:15:24 +08:00
|
|
|
setTimeout(() => Remote.request('AppDelayStart'), 35000);
|
2021-04-13 01:15:33 +08:00
|
|
|
|
2022-01-12 19:11:37 +08:00
|
|
|
// add pointermove ?
|
2022-02-24 18:19:19 +08:00
|
|
|
addEventsListener(doc, ['touchstart','mousemove','keydown'], SettingsUserStore.delayLogout, {passive:true});
|
2021-04-13 01:15:33 +08:00
|
|
|
SettingsUserStore.delayLogout();
|
2021-03-18 23:12:24 +08:00
|
|
|
|
2021-11-13 16:46:59 +08:00
|
|
|
// initLeftSideLayoutResizer
|
|
|
|
setTimeout(() => {
|
|
|
|
const left = elementById('rl-left'),
|
|
|
|
fToggle = () =>
|
2023-02-09 00:39:30 +08:00
|
|
|
setLayoutResizer(left, ClientSideKeyNameFolderListSize,
|
2021-11-13 16:46:59 +08:00
|
|
|
(ThemeStore.isMobile() || leftPanelDisabled()) ? 0 : 'Width');
|
2023-01-26 21:11:30 +08:00
|
|
|
if (left) {
|
2021-11-13 16:46:59 +08:00
|
|
|
fToggle();
|
|
|
|
leftPanelDisabled.subscribe(fToggle);
|
|
|
|
}
|
|
|
|
}, 1);
|
2021-09-23 20:24:06 +08:00
|
|
|
|
2023-07-04 12:06:47 +08:00
|
|
|
setInterval(reloadTime, 60000);
|
2021-09-23 20:24:06 +08:00
|
|
|
|
2022-01-20 01:24:07 +08:00
|
|
|
PgpUserStore.init();
|
2024-02-21 01:29:35 +08:00
|
|
|
SMimeUserStore.loadCertificates();
|
2022-03-04 22:22:37 +08:00
|
|
|
|
2023-02-21 22:45:21 +08:00
|
|
|
setTimeout(() => mailToHelper(SettingsGet('mailToEmail')), 500);
|
|
|
|
|
2023-07-05 02:26:31 +08:00
|
|
|
if (!localStorage.getItem('register_protocol_offered')) {
|
|
|
|
// When auto-login is active
|
|
|
|
navigator.registerProtocolHandler?.(
|
|
|
|
'mailto',
|
|
|
|
location.protocol + '//' + location.host + location.pathname + '?mailto&to=%s',
|
|
|
|
(SettingsGet('title') || 'SnappyMail')
|
|
|
|
);
|
|
|
|
localStorage.setItem('register_protocol_offered', '1');
|
|
|
|
}
|
2022-10-10 19:52:56 +08:00
|
|
|
|
2021-04-13 01:15:33 +08:00
|
|
|
} else {
|
|
|
|
this.logout();
|
2015-04-08 00:39:43 +08:00
|
|
|
}
|
2021-04-13 01:15:33 +08:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
});
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-10-13 01:46:41 +08:00
|
|
|
startScreens([LoginUserScreen]);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2021-07-19 20:26:32 +08:00
|
|
|
}
|
|
|
|
|
2021-03-10 18:43:23 +08:00
|
|
|
showMessageComposer(params = [])
|
2021-01-26 05:00:13 +08:00
|
|
|
{
|
2021-09-17 19:58:49 +08:00
|
|
|
showScreenPopup(ComposePopupView, params);
|
2021-01-26 05:00:13 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2024-03-18 19:25:24 +08:00
|
|
|
|
2024-03-19 00:17:25 +08:00
|
|
|
AskPopupView.password = function(sAskDesc, btnText, ask) {
|
2024-03-18 19:25:24 +08:00
|
|
|
return new Promise(resolve => {
|
|
|
|
this.showModal([
|
|
|
|
sAskDesc,
|
2024-04-23 20:54:48 +08:00
|
|
|
view => resolve({
|
|
|
|
password:view.passphrase(),
|
|
|
|
username:/*ask & 2 ? */view.username(),
|
|
|
|
remember:/*ask & 4 ? */view.remember()
|
|
|
|
}),
|
2024-03-18 19:25:24 +08:00
|
|
|
() => resolve(null),
|
|
|
|
true,
|
2024-04-23 20:54:48 +08:00
|
|
|
ask || 1,
|
2024-03-18 19:25:24 +08:00
|
|
|
btnText
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
AskPopupView.cryptkey = () => new Promise(resolve => {
|
|
|
|
const fn = () => AskPopupView.showModal([
|
|
|
|
i18n('CRYPTO/ASK_CRYPTKEY_PASS'),
|
|
|
|
view => {
|
|
|
|
let pass = view.passphrase();
|
|
|
|
if (pass) {
|
|
|
|
Remote.post('ResealCryptKey', null, {
|
|
|
|
passphrase: pass
|
|
|
|
}).then(response => {
|
|
|
|
resolve(response?.Result);
|
|
|
|
}).catch(e => {
|
|
|
|
if (111 === e.code) {
|
|
|
|
fn();
|
|
|
|
} else {
|
|
|
|
console.error(e);
|
|
|
|
resolve(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
resolve(null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
() => resolve(null),
|
|
|
|
true,
|
|
|
|
1,
|
|
|
|
i18n('CRYPTO/DECRYPT')
|
|
|
|
]);
|
|
|
|
fn();
|
|
|
|
});
|