2021-03-16 23:06:16 +08:00
|
|
|
import { Scope } from 'Common/Enums';
|
2022-03-14 22:42:05 +08:00
|
|
|
import { Layout, ClientSideKeyNameMessageListSize } from 'Common/EnumsUser';
|
2021-11-08 00:06:08 +08:00
|
|
|
import { doc, leftPanelDisabled, moveAction, Settings, elementById } from 'Common/Globals';
|
2020-08-19 18:34:05 +08:00
|
|
|
import { pString, pInt } from 'Common/Utils';
|
2021-11-05 17:20:06 +08:00
|
|
|
import { setLayoutResizer } from 'Common/UtilsUser';
|
2021-11-30 17:19:43 +08:00
|
|
|
import { getFolderFromCacheList, getFolderFullName, getFolderInboxName } from 'Common/Cache';
|
2019-07-05 03:19:24 +08:00
|
|
|
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
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { AppUserStore } from 'Stores/User/App';
|
|
|
|
import { AccountUserStore } from 'Stores/User/Account';
|
|
|
|
import { FolderUserStore } from 'Stores/User/Folder';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { MessagelistUserStore } from 'Stores/User/Messagelist';
|
2021-02-17 03:12:23 +08:00
|
|
|
import { ThemeStore } from 'Stores/Theme';
|
2016-07-07 07:11:13 +08:00
|
|
|
|
2021-09-23 16:40:10 +08:00
|
|
|
import { SystemDropDownUserView } from 'View/User/SystemDropDown';
|
2021-09-23 15:41:02 +08:00
|
|
|
import { MailFolderList } from 'View/User/MailBox/FolderList';
|
|
|
|
import { MailMessageList } from 'View/User/MailBox/MessageList';
|
|
|
|
import { MailMessageView } from 'View/User/MailBox/MessageView';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
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', [
|
2021-09-23 16:40:10 +08:00
|
|
|
SystemDropDownUserView,
|
2021-09-23 15:41:02 +08:00
|
|
|
MailFolderList,
|
|
|
|
MailMessageList,
|
|
|
|
MailMessageView
|
2016-07-07 07:11:13 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
updateWindowTitle() {
|
2021-03-11 05:41:35 +08:00
|
|
|
const count = Settings.app('listPermanentFiltered') ? 0 : FolderUserStore.foldersInboxUnreadCount(),
|
|
|
|
email = AccountUserStore.email();
|
2016-07-07 07:11:13 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
rl.setWindowTitle(
|
2020-07-28 23:20:14 +08:00
|
|
|
(email
|
2021-03-11 05:41:35 +08:00
|
|
|
? '' + (0 < count ? '(' + count + ') ' : ' ') + email + ' - '
|
2020-07-28 23:20:14 +08:00
|
|
|
: ''
|
|
|
|
) + i18n('TITLES/MAILBOX')
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
2016-07-07 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
onShow() {
|
|
|
|
this.updateWindowTitle();
|
|
|
|
|
2022-03-07 20:47:03 +08:00
|
|
|
AppUserStore.focusedState('none');
|
2021-03-16 23:06:16 +08:00
|
|
|
AppUserStore.focusedState(Scope.MessageList);
|
2016-07-07 07:11:13 +08:00
|
|
|
|
2021-02-17 03:12:23 +08:00
|
|
|
ThemeStore.isMobile() && leftPanelDisabled(true);
|
2016-07-07 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} folderHash
|
|
|
|
* @param {number} page
|
|
|
|
* @param {string} search
|
2016-08-17 06:01:20 +08:00
|
|
|
* @returns {void}
|
2016-07-07 07:11:13 +08:00
|
|
|
*/
|
|
|
|
onRoute(folderHash, page, search) {
|
2021-11-30 17:19:43 +08:00
|
|
|
const folder = getFolderFromCacheList(getFolderFullName(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
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
FolderUserStore.currentFolder(folder);
|
2016-07-07 07:11:13 +08:00
|
|
|
|
2022-02-24 02:26:52 +08:00
|
|
|
MessagelistUserStore.page(1 > page ? 1 : page);
|
|
|
|
MessagelistUserStore.listSearch(search);
|
|
|
|
MessagelistUserStore.threadUid((folderHash === threadUid) ? 0 : pInt(threadUid));
|
2016-07-07 07:11:13 +08:00
|
|
|
|
2022-02-24 02:26:52 +08:00
|
|
|
MessagelistUserStore.reload();
|
2016-07-07 07:11:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
onStart() {
|
2022-03-08 07:51:32 +08:00
|
|
|
super.onStart();
|
|
|
|
|
|
|
|
addEventListener('mailbox.inbox-unread-count', e => {
|
|
|
|
FolderUserStore.foldersInboxUnreadCount(e.detail);
|
|
|
|
/* // Disabled in SystemDropDown.html
|
|
|
|
const email = AccountUserStore.email();
|
|
|
|
AccountUserStore.accounts.forEach(item =>
|
|
|
|
item && email === item.email && item.count(e.detail)
|
|
|
|
);
|
2021-12-02 18:12:21 +08:00
|
|
|
*/
|
2022-03-08 07:51:32 +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
|
2021-11-08 00:06:08 +08:00
|
|
|
const top = elementById('V-MailMessageList'),
|
|
|
|
bottom = elementById('V-MailMessageView'),
|
2021-11-05 17:20:06 +08:00
|
|
|
fToggle = () => {
|
|
|
|
let layout = SettingsUserStore.layout();
|
2022-03-14 22:42:05 +08:00
|
|
|
setLayoutResizer(top, bottom, ClientSideKeyNameMessageListSize,
|
2021-11-05 17:20:06 +08:00
|
|
|
(ThemeStore.isMobile() || Layout.NoPreview === layout)
|
2021-11-06 19:27:37 +08:00
|
|
|
? 0
|
|
|
|
: (Layout.SidePreview === layout ? 'Width' : 'Height')
|
2021-11-05 17:20:06 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
if (top && bottom) {
|
|
|
|
fToggle();
|
|
|
|
addEventListener('rl-layout', fToggle);
|
|
|
|
}
|
|
|
|
}, 1);
|
2017-02-09 01:48:53 +08:00
|
|
|
|
2021-01-27 07:26:31 +08:00
|
|
|
doc.addEventListener('click', event =>
|
2020-08-30 16:30:50 +08:00
|
|
|
event.target.closest('#rl-right') && moveAction(false)
|
|
|
|
);
|
2016-07-07 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-12-08 00:22:56 +08:00
|
|
|
* Parse link as generated by mailBox()
|
2016-07-07 07:11:13 +08:00
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
routes() {
|
2021-01-27 07:26:31 +08:00
|
|
|
const
|
2021-12-08 00:22:56 +08:00
|
|
|
folder = (request, vals) => request ? pString(vals[0]) : getFolderInboxName(),
|
2021-03-30 16:58:24 +08:00
|
|
|
fNormS = (request, vals) => [folder(request, vals), request ? pInt(vals[1]) : 1, decodeURI(pString(vals[2]))];
|
2016-07-07 07:11:13 +08:00
|
|
|
|
|
|
|
return [
|
2021-12-07 23:52:05 +08:00
|
|
|
// Folder: INBOX | INBOX.sub | Sent | fullNameHash
|
2021-03-30 16:58:24 +08:00
|
|
|
[/^([^/]*)$/, { normalize_: fNormS }],
|
2021-12-07 23:52:05 +08:00
|
|
|
// Search: {folder}/{string}
|
2021-12-07 21:03:30 +08:00
|
|
|
[/^([a-zA-Z0-9.~_-]+)\/(.+)\/?$/, { normalize_: (request, vals) =>
|
2021-03-30 16:58:24 +08:00
|
|
|
[folder(request, vals), 1, decodeURI(pString(vals[1]))]
|
|
|
|
}],
|
2021-12-07 23:52:05 +08:00
|
|
|
// Page: {folder}/p{int}(/{search})?
|
2021-12-08 00:22:56 +08:00
|
|
|
[/^([a-zA-Z0-9.~_-]+)\/p([1-9][0-9]*)(?:\/(.+))?$/, { normalize_: fNormS }]
|
2016-07-07 07:11:13 +08:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|