snappymail/dev/Screen/User/MailBox.js

173 lines
4.3 KiB
JavaScript
Raw Normal View History

2020-08-14 04:58:41 +08:00
import { Focused, Capa, ClientSideKeyName } from 'Common/Enums';
import { leftPanelDisabled, leftPanelType, moveAction } from 'Common/Globals';
import { pString, pInt } from 'Common/Utils';
2019-07-05 03:19:24 +08:00
import { getFolderFromCacheList, getFolderFullNameRaw, getFolderInboxName } from 'Common/Cache';
import { i18n } from 'Common/Translator';
2016-07-07 07:11:13 +08:00
import AppStore from 'Stores/User/App';
import AccountStore from 'Stores/User/Account';
import SettingsStore from 'Stores/User/Settings';
import FolderStore from 'Stores/User/Folder';
import MessageStore from 'Stores/User/Message';
2019-07-05 03:19:24 +08:00
import { SystemDropDownMailBoxUserView } from 'View/User/MailBox/SystemDropDown';
import { FolderListMailBoxUserView } from 'View/User/MailBox/FolderList';
import { MessageListMailBoxUserView } from 'View/User/MailBox/MessageList';
import { MessageViewMailBoxUserView } from 'View/User/MailBox/MessageView';
2019-07-05 03:19:24 +08:00
import { warmUpScreenPopup } from 'Knoin/Knoin';
2019-07-05 03:19:24 +08:00
import { AbstractScreen } from 'Knoin/AbstractScreen';
2016-07-07 07:11:13 +08:00
const Settings = rl.settings;
2019-07-05 03:19:24 +08:00
class MailBoxUserScreen extends AbstractScreen {
2016-07-16 05:29:42 +08:00
constructor() {
2016-07-07 07:11:13 +08:00
super('mailbox', [
SystemDropDownMailBoxUserView,
FolderListMailBoxUserView,
MessageListMailBoxUserView,
MessageViewMailBoxUserView
2016-07-07 07:11:13 +08:00
]);
}
/**
* @returns {void}
*/
updateWindowTitle() {
let foldersInboxUnreadCount = FolderStore.foldersInboxUnreadCount();
const email = AccountStore.email();
if (Settings.app('listPermanentFiltered')) {
2016-07-07 07:11:13 +08:00
foldersInboxUnreadCount = 0;
}
rl.setWindowTitle(
(email
? '' + (0 < foldersInboxUnreadCount ? '(' + foldersInboxUnreadCount + ') ' : ' ') + email + ' - '
: ''
) + i18n('TITLES/MAILBOX')
2019-07-05 03:19:24 +08:00
);
2016-07-07 07:11:13 +08:00
}
/**
* @returns {void}
*/
onShow() {
this.updateWindowTitle();
AppStore.focusedState(Focused.None);
AppStore.focusedState(Focused.MessageList);
if (Settings.app('mobile')) {
2016-07-07 07:11:13 +08:00
leftPanelDisabled(true);
}
2019-07-05 03:19:24 +08:00
if (!Settings.capa(Capa.Folders)) {
2016-07-07 07:11:13 +08:00
leftPanelType(Settings.capa(Capa.Composer) || Settings.capa(Capa.Contacts) ? 'short' : 'none');
2019-07-05 03:19:24 +08:00
} else {
2016-07-07 07:11:13 +08:00
leftPanelType('');
}
}
/**
* @param {string} folderHash
* @param {number} page
* @param {string} search
* @returns {void}
2016-07-07 07:11:13 +08:00
*/
onRoute(folderHash, page, search) {
let threadUid = folderHash.replace(/^(.+)~([\d]+)$/, '$2');
const folder = getFolderFromCacheList(getFolderFullNameRaw(folderHash.replace(/~([\d]+)$/, '')));
2019-07-05 03:19:24 +08:00
if (folder) {
if (folderHash === threadUid) {
2016-07-07 07:11:13 +08:00
threadUid = '';
}
FolderStore.currentFolder(folder);
MessageStore.messageListPage(page);
MessageStore.messageListSearch(search);
MessageStore.messageListThreadUid(threadUid);
2020-09-15 15:29:25 +08:00
rl.app.reloadMessageList();
2016-07-07 07:11:13 +08:00
}
}
/**
* @returns {void}
*/
onStart() {
2020-08-14 04:58:41 +08:00
setTimeout(() => SettingsStore.layout.valueHasMutated(), 50);
setTimeout(() => warmUpScreenPopup(require('View/Popup/Compose')), 500);
2016-07-07 07:11:13 +08:00
addEventListener('mailbox.inbox-unread-count', e => {
FolderStore.foldersInboxUnreadCount(e.detail);
2016-07-07 07:11:13 +08:00
const email = AccountStore.email();
AccountStore.accounts.forEach(item => {
2019-07-05 03:19:24 +08:00
if (item && email === item.email) {
item.count(e.detail);
2016-07-07 07:11:13 +08:00
}
});
this.updateWindowTitle();
});
}
/**
* @returns {void}
*/
onBuild() {
if (!Settings.app('mobile')) {
setTimeout(() =>
2020-09-15 15:29:25 +08:00
rl.app.initHorizontalLayoutResizer(ClientSideKeyName.MessageListSize)
, 1);
2016-07-07 07:11:13 +08:00
}
2017-02-09 01:48:53 +08:00
document.addEventListener('click', event =>
event.target.closest('#rl-right') && moveAction(false)
);
2016-07-07 07:11:13 +08:00
}
/**
* @returns {Array}
*/
routes() {
2019-07-05 03:19:24 +08:00
const inboxFolderName = getFolderInboxName(),
2016-07-07 07:11:13 +08:00
fNormS = (request, vals) => {
vals[0] = pString(vals[0]);
vals[1] = pInt(vals[1]);
vals[1] = 0 >= vals[1] ? 1 : vals[1];
vals[2] = pString(vals[2]);
if (!request) {
2016-07-07 07:11:13 +08:00
vals[0] = inboxFolderName;
vals[1] = 1;
}
return [decodeURI(vals[0]), vals[1], decodeURI(vals[2])];
2016-07-07 07:11:13 +08:00
},
fNormD = (request, vals) => {
vals[0] = pString(vals[0]);
vals[1] = pString(vals[1]);
if (!request) {
2016-07-07 07:11:13 +08:00
vals[0] = inboxFolderName;
}
return [decodeURI(vals[0]), 1, decodeURI(vals[1])];
2016-07-07 07:11:13 +08:00
};
return [
2019-07-05 03:19:24 +08:00
[/^([a-zA-Z0-9~]+)\/p([1-9][0-9]*)\/(.+)\/?$/, { 'normalize_': fNormS }],
[/^([a-zA-Z0-9~]+)\/p([1-9][0-9]*)$/, { 'normalize_': fNormS }],
[/^([a-zA-Z0-9~]+)\/(.+)\/?$/, { 'normalize_': fNormD }],
[/^([^/]*)$/, { 'normalize_': fNormS }]
2016-07-07 07:11:13 +08:00
];
}
}
2019-07-05 03:19:24 +08:00
export { MailBoxUserScreen, MailBoxUserScreen as default };