snappymail/dev/Screen/User/MailBox.js

145 lines
3.9 KiB
JavaScript
Raw Normal View History

import { Scope } from 'Common/Enums';
2021-11-05 17:20:06 +08:00
import { Layout, ClientSideKeyName } from 'Common/EnumsUser';
import { doc, leftPanelDisabled, moveAction, Settings } from 'Common/Globals';
import { pString, pInt } from 'Common/Utils';
2021-11-05 17:20:06 +08:00
import { setLayoutResizer } from 'Common/UtilsUser';
2019-07-05 03:19:24 +08:00
import { getFolderFromCacheList, getFolderFullNameRaw, getFolderInboxName } from 'Common/Cache';
import { i18n } from 'Common/Translator';
2021-11-05 17:20:06 +08:00
import { SettingsUserStore } from 'Stores/User/Settings';
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
import { SystemDropDownUserView } from 'View/User/SystemDropDown';
import { MailFolderList } from 'View/User/MailBox/FolderList';
import { MailMessageList } from 'View/User/MailBox/MessageList';
import { MailMessageView } 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', [
SystemDropDownUserView,
MailFolderList,
MailMessageList,
MailMessageView
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) {
2021-09-10 22:28:29 +08:00
let threadUid = folderHash.replace(/^.+~(\d+)$/, '$1');
2016-07-07 07:11:13 +08:00
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);
2021-09-10 22:28:29 +08:00
MessageUserStore.listThreadUid((folderHash === threadUid) ? 0 : pInt(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() {
2021-11-05 17:20:06 +08:00
setTimeout(() => {
// initMailboxLayoutResizer
const top = doc.querySelector('.RL-MailMessageList'),
bottom = doc.querySelector('.RL-MailMessageView'),
fToggle = () => {
let layout = SettingsUserStore.layout();
setLayoutResizer(top, bottom, ClientSideKeyName.MessageListSize,
(ThemeStore.isMobile() || Layout.NoPreview === layout)
? null
: (Layout.SidePreview === layout ? 'width' : 'height')
);
};
if (top && bottom) {
fToggle();
addEventListener('rl-layout', fToggle);
}
}, 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
];
}
}