snappymail/dev/Screen/User/MailBox.js

129 lines
3.4 KiB
JavaScript
Raw Normal View History

import { Scope } from 'Common/Enums';
import { doc, leftPanelDisabled, moveAction, Settings } 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 { AppUserStore } from 'Stores/User/App';
import { AccountUserStore } from 'Stores/User/Account';
import { FolderUserStore } from 'Stores/User/Folder';
import { MessageUserStore } from 'Stores/User/Message';
import { ThemeStore } from 'Stores/Theme';
2016-07-07 07:11:13 +08:00
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 { AbstractScreen } from 'Knoin/AbstractScreen';
2016-07-07 07:11:13 +08:00
2021-01-22 23:32:08 +08:00
export 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() {
const count = Settings.app('listPermanentFiltered') ? 0 : FolderUserStore.foldersInboxUnreadCount(),
email = AccountUserStore.email();
2016-07-07 07:11:13 +08:00
rl.setWindowTitle(
(email
? '' + (0 < count ? '(' + count + ') ' : ' ') + 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();
AppUserStore.focusedState(Scope.None);
AppUserStore.focusedState(Scope.MessageList);
2016-07-07 07:11:13 +08:00
ThemeStore.isMobile() && leftPanelDisabled(true);
2016-07-07 07:11:13 +08:00
}
/**
* @param {string} folderHash
* @param {number} page
* @param {string} search
* @returns {void}
2016-07-07 07:11:13 +08:00
*/
onRoute(folderHash, page, search) {
const folder = getFolderFromCacheList(getFolderFullNameRaw(folderHash.replace(/~([\d]+)$/, '')));
2019-07-05 03:19:24 +08:00
if (folder) {
let threadUid = folderHash.replace(/^.+~([\d]+)$/, '$1');
2019-07-05 03:19:24 +08:00
if (folderHash === threadUid) {
2016-07-07 07:11:13 +08:00
threadUid = '';
}
FolderUserStore.currentFolder(folder);
2016-07-07 07:11:13 +08:00
MessageUserStore.listPage(1 > page ? 1 : page);
2021-03-12 23:54:37 +08:00
MessageUserStore.listSearch(search);
MessageUserStore.listThreadUid(threadUid);
2016-07-07 07:11:13 +08:00
2020-09-15 15:29:25 +08:00
rl.app.reloadMessageList();
2016-07-07 07:11:13 +08:00
}
}
/**
* @returns {void}
*/
onStart() {
if (!this.__started) {
super.onStart();
2016-07-07 07:11:13 +08:00
addEventListener('mailbox.inbox-unread-count', e => {
FolderUserStore.foldersInboxUnreadCount(e.detail);
2016-07-07 07:11:13 +08:00
const email = AccountUserStore.email();
AccountUserStore.accounts.forEach(item =>
item && email === item.email && item.count(e.detail)
);
2016-07-07 07:11:13 +08:00
this.updateWindowTitle();
});
}
2016-07-07 07:11:13 +08:00
}
/**
* @returns {void}
*/
onBuild() {
setTimeout(() => rl.app.initHorizontalLayoutResizer(), 1);
2017-02-09 01:48:53 +08:00
doc.addEventListener('click', event =>
event.target.closest('#rl-right') && moveAction(false)
);
2016-07-07 07:11:13 +08:00
}
/**
* @returns {Array}
*/
routes() {
const
folder = (request, vals) => request ? decodeURI(pString(vals[0])) : getFolderInboxName(),
fNormS = (request, vals) => [folder(request, vals), request ? pInt(vals[1]) : 1, decodeURI(pString(vals[2]))];
2016-07-07 07:11:13 +08:00
return [
[/^([^/]*)$/, { normalize_: fNormS }],
[/^([a-zA-Z0-9~]+)\/(.+)\/?$/, { normalize_: (request, vals) =>
[folder(request, vals), 1, decodeURI(pString(vals[1]))]
}],
[/^([a-zA-Z0-9~]+)\/p([1-9][0-9]*)(?:\/(.+)\/?)?$/, { normalize_: fNormS }]
2016-07-07 07:11:13 +08:00
];
}
}