snappymail/dev/Screen/User/MailBox.js

183 lines
4.7 KiB
JavaScript
Raw Normal View History

import window from 'window';
2016-07-07 07:11:13 +08:00
2019-07-05 03:19:24 +08:00
import { Focused, Capa, ClientSideKeyName, Magics } from 'Common/Enums';
import { $html, leftPanelDisabled, leftPanelType, moveAction, bMobileDevice } from 'Common/Globals';
import { pString, pInt, windowResizeCallback } 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 * as Events from 'Common/Events';
import * as Settings from 'Storage/Settings';
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 { getApp } from 'Helper/Apps/User';
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
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();
2019-07-05 03:19:24 +08:00
if (Settings.appSettingsGet('listPermanentFiltered')) {
2016-07-07 07:11:13 +08:00
foldersInboxUnreadCount = 0;
}
2019-07-05 03:19:24 +08:00
getApp().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);
2019-07-05 03:19:24 +08:00
if (Settings.appSettingsGet('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);
getApp().reloadMessageList();
2016-07-07 07:11:13 +08:00
}
}
/**
* @returns {void}
*/
onStart() {
FolderStore.folderList.subscribe(windowResizeCallback);
MessageStore.messageList.subscribe(windowResizeCallback);
MessageStore.message.subscribe(windowResizeCallback);
setTimeout(() => SettingsStore.layout.valueHasMutated(), Magics.Time50ms);
setTimeout(() => warmUpScreenPopup(require('View/Popup/Compose')), Magics.Time500ms);
2016-07-07 07:11:13 +08:00
Events.sub('mailbox.inbox-unread-count', (count) => {
FolderStore.foldersInboxUnreadCount(count);
const email = AccountStore.email();
AccountStore.accounts().forEach(item => {
2019-07-05 03:19:24 +08:00
if (item && email === item.email) {
2016-07-07 07:11:13 +08:00
item.count(count);
}
});
this.updateWindowTitle();
});
}
/**
* @returns {void}
*/
onBuild() {
2019-07-05 03:19:24 +08:00
if (!bMobileDevice && !Settings.appSettingsGet('mobile')) {
setTimeout(() =>
getApp().initHorizontalLayoutResizer(ClientSideKeyName.MessageListSize)
, 1);
2016-07-07 07:11:13 +08:00
}
2017-02-09 01:48:53 +08:00
$html.on('click', '#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 [window.decodeURI(vals[0]), vals[1], window.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 [window.decodeURI(vals[0]), 1, window.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 };