snappymail/dev/View/User/MailBox/MessageList.js

952 lines
26 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
import {
2019-07-05 03:19:24 +08:00
Capa,
Layout,
Focused,
ComposeType,
FolderType,
MessageSetAction,
KeyState,
StorageResultType
} from 'Common/Enums';
2019-07-05 03:19:24 +08:00
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { leftPanelDisabled, moveAction } from 'Common/Globals';
import { computedPaginatorHelper } from 'Common/UtilsUser';
import { File } from 'Common/File';
2019-07-05 03:19:24 +08:00
import { mailBox, append } from 'Common/Links';
import { Selector } from 'Common/Selector';
2019-07-05 03:19:24 +08:00
import { i18n, initOnStartOrLangChange } from 'Common/Translator';
import {
2019-07-05 03:19:24 +08:00
getFolderFromCacheList,
clearMessageFlagsFromCacheByFolder,
hasRequestedMessage,
addRequestedMessage
} from 'Common/Cache';
import AppStore from 'Stores/User/App';
import QuotaStore from 'Stores/User/Quota';
import SettingsStore from 'Stores/User/Settings';
import FolderStore from 'Stores/User/Folder';
import MessageStore from 'Stores/User/Message';
import Remote from 'Remote/User/Fetch';
import { view, command, ViewType, showScreenPopup, popupVisibility } from 'Knoin/Knoin';
2019-07-05 03:19:24 +08:00
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
2020-08-07 22:28:30 +08:00
const
Settings = rl.settings,
2020-08-07 22:28:30 +08:00
canBeMovedHelper = (self) => self.canBeMoved(),
ifvisible = window.ifvisible;
@view({
name: 'View/User/MailBox/MessageList',
type: ViewType.Right,
templateID: 'MailMessageList'
})
2019-07-05 03:19:24 +08:00
class MessageListMailBoxUserView extends AbstractViewNext {
constructor() {
super();
this.sLastUid = null;
this.bPrefetch = false;
this.emptySubjectValue = '';
this.iGoToUpUpOrDownDownTimeout = 0;
this.mobile = !!Settings.app('mobile');
this.newMoveToFolder = !!Settings.get('NewMoveToFolder');
this.allowReload = !!Settings.capa(Capa.Reload);
this.allowSearch = !!Settings.capa(Capa.Search);
this.allowSearchAdv = !!Settings.capa(Capa.SearchAdv);
this.allowComposer = !!Settings.capa(Capa.Composer);
this.allowMessageListActions = !!Settings.capa(Capa.MessageListActions);
this.allowDangerousActions = !!Settings.capa(Capa.DangerousActions);
this.allowFolders = !!Settings.capa(Capa.Folders);
this.popupVisibility = popupVisibility;
this.message = MessageStore.message;
this.messageList = MessageStore.messageList;
this.messageListDisableAutoSelect = MessageStore.messageListDisableAutoSelect;
this.folderList = FolderStore.folderList;
this.composeInEdit = AppStore.composeInEdit;
this.leftPanelDisabled = leftPanelDisabled;
this.selectorMessageSelected = MessageStore.selectorMessageSelected;
this.selectorMessageFocused = MessageStore.selectorMessageFocused;
this.isMessageSelected = MessageStore.isMessageSelected;
this.messageListSearch = MessageStore.messageListSearch;
this.messageListThreadUid = MessageStore.messageListThreadUid;
this.messageListError = MessageStore.messageListError;
this.folderMenuForMove = FolderStore.folderMenuForMove;
this.useCheckboxesInList = SettingsStore.useCheckboxesInList;
this.mainMessageListSearch = MessageStore.mainMessageListSearch;
this.messageListEndFolder = MessageStore.messageListEndFolder;
this.messageListEndThreadUid = MessageStore.messageListEndThreadUid;
this.messageListCheckedOrSelected = MessageStore.messageListCheckedOrSelected;
this.messageListCheckedOrSelectedUidsWithSubMails = MessageStore.messageListCheckedOrSelectedUidsWithSubMails;
this.messageListCompleteLoadingThrottle = MessageStore.messageListCompleteLoadingThrottle;
this.messageListCompleteLoadingThrottleForAnimation = MessageStore.messageListCompleteLoadingThrottleForAnimation;
initOnStartOrLangChange(() => this.emptySubjectValue = i18n('MESSAGE_LIST/EMPTY_SUBJECT_TEXT'));
2014-08-21 23:08:34 +08:00
this.userQuota = QuotaStore.quota;
this.userUsageSize = QuotaStore.usage;
this.userUsageProc = QuotaStore.percentage;
2014-08-21 23:08:34 +08:00
this.moveDropdownTrigger = ko.observable(false);
this.moreDropdownTrigger = ko.observable(false);
// append drag and drop
2019-07-05 03:19:24 +08:00
this.dragOver = ko.observable(false).extend({ 'throttle': 1 });
this.dragOverEnter = ko.observable(false).extend({ 'throttle': 1 });
this.dragOverArea = ko.observable(null);
this.dragOverBodyArea = ko.observable(null);
2019-07-05 03:19:24 +08:00
this.messageListItemTemplate = ko.computed(() =>
this.mobile || Layout.SidePreview === SettingsStore.layout()
? 'MailMessageListItem'
: 'MailMessageListItemNoPreviewPane'
);
2014-08-21 23:08:34 +08:00
this.messageListSearchDesc = ko.computed(() => {
const value = MessageStore.messageListEndSearch();
return value ? i18n('MESSAGE_LIST/SEARCH_RESULT_FOR', { 'SEARCH': value }) : '';
});
2014-08-21 23:08:34 +08:00
2020-10-12 21:11:25 +08:00
this.messageListPaginator = ko.computed(
computedPaginatorHelper(MessageStore.messageListPage, MessageStore.messageListPageCount)
2019-07-05 03:19:24 +08:00
);
2014-08-21 23:08:34 +08:00
this.checkAll = ko.computed({
read: () => 0 < MessageStore.messageListChecked().length,
write: (value) => {
value = !!value;
MessageStore.messageList().forEach(message => message.checked(value));
}
});
2014-08-21 23:08:34 +08:00
this.inputMessageListSearchFocus = ko.observable(false);
this.sLastSearchValue = '';
this.inputProxyMessageListSearch = ko.computed({
read: this.mainMessageListSearch,
write: value => this.sLastSearchValue = value
});
this.isIncompleteChecked = ko.computed(() => {
const c = MessageStore.messageListChecked().length;
return c && MessageStore.messageList().length > c;
});
2014-08-21 23:08:34 +08:00
this.hasMessages = ko.computed(() => 0 < this.messageList().length);
2014-08-21 23:08:34 +08:00
this.hasCheckedOrSelectedLines = ko.computed(() => 0 < this.messageListCheckedOrSelected().length);
2014-08-21 23:08:34 +08:00
this.isSpamFolder = ko.computed(
() => FolderStore.spamFolder() === this.messageListEndFolder() && FolderStore.spamFolder()
);
2014-08-21 23:08:34 +08:00
this.isSpamDisabled = ko.computed(() => UNUSED_OPTION_VALUE === FolderStore.spamFolder());
2014-08-21 23:08:34 +08:00
this.isTrashFolder = ko.computed(
() => FolderStore.trashFolder() === this.messageListEndFolder() && FolderStore.trashFolder()
);
2014-08-21 23:08:34 +08:00
this.isDraftFolder = ko.computed(
() => FolderStore.draftFolder() === this.messageListEndFolder() && FolderStore.draftFolder()
);
this.isSentFolder = ko.computed(
() => FolderStore.sentFolder() === this.messageListEndFolder() && FolderStore.sentFolder()
);
this.isArchiveFolder = ko.computed(
() => FolderStore.archiveFolder() === this.messageListEndFolder() && FolderStore.archiveFolder()
);
this.isArchiveDisabled = ko.computed(() => UNUSED_OPTION_VALUE === FolderStore.archiveFolder());
this.isArchiveVisible = ko.computed(
() => !this.isArchiveFolder() && !this.isArchiveDisabled() && !this.isDraftFolder()
);
this.isSpamVisible = ko.computed(
() => !this.isSpamFolder() && !this.isSpamDisabled() && !this.isDraftFolder() && !this.isSentFolder()
);
this.isUnSpamVisible = ko.computed(
() => this.isSpamFolder() && !this.isSpamDisabled() && !this.isDraftFolder() && !this.isSentFolder()
);
// this.messageListChecked = MessageStore.messageListChecked;
this.mobileCheckedStateShow = ko.computed(() => this.mobile ? 0 < MessageStore.messageListChecked().length : true);
2016-06-16 07:36:44 +08:00
this.mobileCheckedStateHide = ko.computed(() => this.mobile ? !MessageStore.messageListChecked().length : true);
2015-07-07 02:46:44 +08:00
this.messageListFocused = ko.computed(() => Focused.MessageList === AppStore.focusedState());
this.canBeMoved = this.hasCheckedOrSelectedLines;
this.quotaTooltip = this.quotaTooltip.bind(this);
2016-05-01 09:07:10 +08:00
this.selector = new Selector(
2019-07-05 03:19:24 +08:00
this.messageList,
this.selectorMessageSelected,
this.selectorMessageFocused,
'.messageListItem .actionHandle',
'.messageListItem.selected',
'.messageListItem .checkboxMessage',
'.messageListItem.focused'
);
2016-05-01 09:07:10 +08:00
this.selector.on('onItemSelect', message => MessageStore.selectMessage(message));
2016-05-01 09:07:10 +08:00
this.selector.on('onItemGetUid', message => (message ? message.generateUid() : ''));
2016-05-01 09:07:10 +08:00
this.selector.on('onAutoSelect', () => this.useAutoSelect());
this.selector.on('onUpUpOrDownDown', v => this.goToUpUpOrDownDown(v));
2015-05-03 04:22:32 +08:00
addEventListener('mailbox.message-list.selector.go-down', e => this.selector.goDown(e.detail));
addEventListener('mailbox.message-list.selector.go-up', e => this.selector.goUp(e.detail));
addEventListener('mailbox.message.show', e => {
const sFolder = e.detail.Folder, sUid = e.detail.Uid;
const message = this.messageList().find(
2020-10-23 21:15:54 +08:00
item => item && sFolder === item.folder && sUid === item.uid
2019-07-05 03:19:24 +08:00
);
2019-07-05 03:19:24 +08:00
if ('INBOX' === sFolder) {
rl.route.setHash(mailBox(sFolder, 1));
}
2019-07-05 03:19:24 +08:00
if (message) {
this.selector.selectMessageItem(message);
2019-07-05 03:19:24 +08:00
} else {
if ('INBOX' !== sFolder) {
rl.route.setHash(mailBox(sFolder, 1));
2016-06-30 08:02:45 +08:00
}
MessageStore.selectMessageByFolderAndUid(sFolder, sUid);
}
2016-06-30 08:02:45 +08:00
});
2020-08-27 21:45:47 +08:00
MessageStore.messageListEndHash.subscribe((() =>
this.selector.scrollToFocused()
).throttle(50));
}
@command()
clearCommand() {
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.DangerousActions)) {
showScreenPopup(require('View/Popup/FolderClear'), [FolderStore.currentFolder()]);
}
}
@command()
reloadCommand() {
2019-07-05 03:19:24 +08:00
if (!MessageStore.messageListCompleteLoadingThrottleForAnimation() && this.allowReload) {
2020-09-15 15:29:25 +08:00
rl.app.reloadMessageList(false, true);
}
}
@command(canBeMovedHelper)
multyForwardCommand() {
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Composer)) {
showScreenPopup(require('View/Popup/Compose'), [
2019-07-05 03:19:24 +08:00
ComposeType.ForwardAsAttachment,
MessageStore.messageListCheckedOrSelected()
]);
}
}
@command(canBeMovedHelper)
deleteWithoutMoveCommand() {
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.DangerousActions)) {
2020-09-15 15:29:25 +08:00
rl.app.deleteMessagesFromFolder(
2019-07-05 03:19:24 +08:00
FolderType.Trash,
FolderStore.currentFolderFullNameRaw(),
2019-07-05 03:19:24 +08:00
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(),
false
);
}
}
@command(canBeMovedHelper)
deleteCommand() {
2020-09-15 15:29:25 +08:00
rl.app.deleteMessagesFromFolder(
2019-07-05 03:19:24 +08:00
FolderType.Trash,
FolderStore.currentFolderFullNameRaw(),
2019-07-05 03:19:24 +08:00
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(),
true
);
}
@command(canBeMovedHelper)
archiveCommand() {
2020-09-15 15:29:25 +08:00
rl.app.deleteMessagesFromFolder(
2019-07-05 03:19:24 +08:00
FolderType.Archive,
FolderStore.currentFolderFullNameRaw(),
2019-07-05 03:19:24 +08:00
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(),
true
);
}
@command(canBeMovedHelper)
spamCommand() {
2020-09-15 15:29:25 +08:00
rl.app.deleteMessagesFromFolder(
2019-07-05 03:19:24 +08:00
FolderType.Spam,
FolderStore.currentFolderFullNameRaw(),
2019-07-05 03:19:24 +08:00
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(),
true
);
}
@command(canBeMovedHelper)
notSpamCommand() {
2020-09-15 15:29:25 +08:00
rl.app.deleteMessagesFromFolder(
2019-07-05 03:19:24 +08:00
FolderType.NotSpam,
FolderStore.currentFolderFullNameRaw(),
2019-07-05 03:19:24 +08:00
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(),
true
);
}
@command(canBeMovedHelper)
moveCommand() {} // eslint-disable-line no-empty-function
2017-02-09 01:48:53 +08:00
@command(canBeMovedHelper)
moveNewCommand(vm, event) {
if (this.newMoveToFolder && this.mobileCheckedStateShow()) {
2017-02-09 01:48:53 +08:00
if (vm && event && event.preventDefault) {
event.preventDefault();
2020-09-30 20:07:03 +08:00
event.stopPropagation();
2017-02-09 01:48:53 +08:00
}
2020-09-30 20:07:03 +08:00
let b = moveAction();
AppStore.focusedState(b ? Focused.MessageList : Focused.FolderList);
moveAction(!b);
2017-02-09 01:48:53 +08:00
}
}
hideLeft(item, event) {
event.preventDefault();
event.stopPropagation();
leftPanelDisabled(true);
}
2016-07-01 06:50:11 +08:00
showLeft(item, event) {
event.preventDefault();
event.stopPropagation();
leftPanelDisabled(false);
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
composeClick() {
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Composer)) {
showScreenPopup(require('View/Popup/Compose'));
}
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
goToUpUpOrDownDown(up) {
if (MessageStore.messageListChecked().length) {
return false;
}
2016-06-30 08:02:45 +08:00
clearTimeout(this.iGoToUpUpOrDownDownTimeout);
this.iGoToUpUpOrDownDownTimeout = setTimeout(() => {
2020-09-30 20:07:03 +08:00
let prev, next, temp, current;
2020-10-12 21:11:25 +08:00
this.messageListPaginator().find(item => {
2019-07-05 03:19:24 +08:00
if (item) {
if (current) {
next = item;
2014-08-21 23:08:34 +08:00
}
2014-04-09 04:59:22 +08:00
2019-07-05 03:19:24 +08:00
if (item.current) {
current = item;
prev = temp;
2014-08-21 23:08:34 +08:00
}
2014-04-09 04:59:22 +08:00
2019-07-05 03:19:24 +08:00
if (next) {
return true;
}
2016-06-30 08:02:45 +08:00
temp = item;
}
2016-06-30 08:02:45 +08:00
return false;
});
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
if (Layout.NoPreview === SettingsStore.layout() && !this.message()) {
this.selector.iFocusedNextHelper = up ? -1 : 1;
2019-07-05 03:19:24 +08:00
} else {
this.selector.iSelectNextHelper = up ? -1 : 1;
}
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
if (up ? prev : next) {
this.selector.unselect();
this.gotoPage(up ? prev : next);
}
2020-08-14 04:58:41 +08:00
}, 350);
2016-06-30 08:02:45 +08:00
return true;
}
useAutoSelect() {
2020-09-30 20:07:03 +08:00
return !this.messageListDisableAutoSelect()
&& !/is:unseen/.test(this.mainMessageListSearch())
&& Layout.NoPreview !== SettingsStore.layout();
}
2016-08-10 03:52:30 +08:00
searchEnterAction() {
this.mainMessageListSearch(this.sLastSearchValue);
this.inputMessageListSearchFocus(false);
2016-06-30 08:02:45 +08:00
}
/**
* @returns {string}
*/
printableMessageCountForDeletion() {
const cnt = this.messageListCheckedOrSelectedUidsWithSubMails().length;
return 1 < cnt ? ' (' + (100 > cnt ? cnt : '99+') + ')' : ''; // eslint-disable-line no-magic-numbers
}
2016-08-10 03:52:30 +08:00
cancelSearch() {
this.mainMessageListSearch('');
this.inputMessageListSearchFocus(false);
2016-06-30 08:02:45 +08:00
}
2015-04-21 06:39:14 +08:00
cancelThreadUid() {
rl.route.setHash(
2019-07-05 03:19:24 +08:00
mailBox(
FolderStore.currentFolderFullNameHash(),
MessageStore.messageListPageBeforeThread(),
MessageStore.messageListSearch()
)
);
2016-06-30 08:02:45 +08:00
}
2015-04-23 05:33:02 +08:00
/**
* @param {string} sToFolderFullNameRaw
* @param {boolean} bCopy
* @returns {boolean}
*/
moveSelectedMessagesToFolder(sToFolderFullNameRaw, bCopy) {
2019-07-05 03:19:24 +08:00
if (this.canBeMoved()) {
2020-09-15 15:29:25 +08:00
rl.app.moveMessagesToFolder(
FolderStore.currentFolderFullNameRaw(),
2019-07-05 03:19:24 +08:00
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(),
sToFolderFullNameRaw,
bCopy
);
}
return false;
2016-06-30 08:02:45 +08:00
}
getDragData(event) {
const item = ko.dataFor(document.elementFromPoint(event.clientX, event.clientY));
item && item.checked && item.checked(true);
const uids = MessageStore.messageListCheckedOrSelectedUidsWithSubMails();
item && !uids.includes(item.uid) && uids.push(item.uid);
return uids.length ? {
copy: event.ctrlKey,
folder: FolderStore.currentFolderFullNameRaw(),
uids: uids
} : null;
2016-06-30 08:02:45 +08:00
}
2014-05-27 20:54:41 +08:00
/**
* @param {string} sFolderFullNameRaw
* @param {number} iSetAction
* @param {Array=} aMessages = null
* @returns {void}
*/
2016-12-15 05:56:17 +08:00
setAction(sFolderFullNameRaw, iSetAction, aMessages) {
2020-09-15 15:29:25 +08:00
rl.app.messageListAction(sFolderFullNameRaw, iSetAction, aMessages);
}
/**
* @param {string} sFolderFullNameRaw
* @param {number} iSetAction
2016-12-15 05:56:17 +08:00
* @param {string} sThreadUid = ''
* @returns {void}
*/
2016-12-15 05:56:17 +08:00
setActionForAll(sFolderFullNameRaw, iSetAction, sThreadUid = '') {
if (sFolderFullNameRaw) {
2016-12-15 05:56:17 +08:00
let cnt = 0;
const uids = [];
let folder = getFolderFromCacheList(sFolderFullNameRaw);
2019-07-05 03:19:24 +08:00
if (folder) {
switch (iSetAction) {
case MessageSetAction.SetSeen:
folder = getFolderFromCacheList(sFolderFullNameRaw);
2019-07-05 03:19:24 +08:00
if (folder) {
MessageStore.messageList().forEach(message => {
2020-10-23 21:15:54 +08:00
if (message.isUnseen()) {
++cnt;
2016-12-15 05:56:17 +08:00
}
2020-10-23 21:15:54 +08:00
message.isUnseen(false);
2016-12-15 05:56:17 +08:00
uids.push(message.uid);
});
2019-07-05 03:19:24 +08:00
if (sThreadUid) {
2016-12-15 05:56:17 +08:00
folder.messageCountUnread(folder.messageCountUnread() - cnt);
2019-07-05 03:19:24 +08:00
if (0 > folder.messageCountUnread()) {
2016-12-15 05:56:17 +08:00
folder.messageCountUnread(0);
}
2019-07-05 03:19:24 +08:00
} else {
2016-12-15 05:56:17 +08:00
folder.messageCountUnread(0);
}
clearMessageFlagsFromCacheByFolder(sFolderFullNameRaw);
}
Remote.messageSetSeenToAll(()=>{}, sFolderFullNameRaw, true, sThreadUid ? uids : null);
break;
case MessageSetAction.UnsetSeen:
folder = getFolderFromCacheList(sFolderFullNameRaw);
2019-07-05 03:19:24 +08:00
if (folder) {
MessageStore.messageList().forEach(message => {
2020-10-23 21:15:54 +08:00
if (!message.isUnseen()) {
++cnt;
2016-12-15 05:56:17 +08:00
}
2020-10-23 21:15:54 +08:00
message.isUnseen(true);
2016-12-15 05:56:17 +08:00
uids.push(message.uid);
});
2019-07-05 03:19:24 +08:00
if (sThreadUid) {
2016-12-15 05:56:17 +08:00
folder.messageCountUnread(folder.messageCountUnread() + cnt);
2019-07-05 03:19:24 +08:00
if (folder.messageCountAll() < folder.messageCountUnread()) {
2016-12-15 05:56:17 +08:00
folder.messageCountUnread(folder.messageCountAll());
}
2019-07-05 03:19:24 +08:00
} else {
2016-12-15 05:56:17 +08:00
folder.messageCountUnread(folder.messageCountAll());
}
clearMessageFlagsFromCacheByFolder(sFolderFullNameRaw);
}
2016-12-15 05:56:17 +08:00
Remote.messageSetSeenToAll(()=>{}, sFolderFullNameRaw, false, sThreadUid ? uids : null);
break;
// no default
}
2020-09-15 15:29:25 +08:00
rl.app.reloadFlagsCurrentMessageListAndMessageFromCache();
}
}
}
listSetSeen() {
2019-07-05 03:19:24 +08:00
this.setAction(
FolderStore.currentFolderFullNameRaw(),
MessageSetAction.SetSeen,
MessageStore.messageListCheckedOrSelected()
);
}
listSetAllSeen() {
2019-07-05 03:19:24 +08:00
this.setActionForAll(
FolderStore.currentFolderFullNameRaw(),
MessageSetAction.SetSeen,
this.messageListEndThreadUid()
);
}
listUnsetSeen() {
2019-07-05 03:19:24 +08:00
this.setAction(
FolderStore.currentFolderFullNameRaw(),
MessageSetAction.UnsetSeen,
MessageStore.messageListCheckedOrSelected()
);
2016-06-30 08:02:45 +08:00
}
2014-04-09 04:59:22 +08:00
listSetFlags() {
2019-07-05 03:19:24 +08:00
this.setAction(
FolderStore.currentFolderFullNameRaw(),
MessageSetAction.SetFlag,
MessageStore.messageListCheckedOrSelected()
);
}
2016-06-30 08:02:45 +08:00
listUnsetFlags() {
2019-07-05 03:19:24 +08:00
this.setAction(
FolderStore.currentFolderFullNameRaw(),
MessageSetAction.UnsetFlag,
MessageStore.messageListCheckedOrSelected()
);
}
flagMessages(currentMessage) {
const checked = this.messageListCheckedOrSelected();
2019-07-05 03:19:24 +08:00
if (currentMessage) {
const checkedUids = checked.map(message => message.uid);
if (checkedUids.includes(currentMessage.uid)) {
2019-07-05 03:19:24 +08:00
this.setAction(
2020-10-23 21:15:54 +08:00
currentMessage.folder,
currentMessage.isFlagged() ? MessageSetAction.UnsetFlag : MessageSetAction.SetFlag,
2019-07-05 03:19:24 +08:00
checked
);
} else {
this.setAction(
2020-10-23 21:15:54 +08:00
currentMessage.folder,
currentMessage.isFlagged() ? MessageSetAction.UnsetFlag : MessageSetAction.SetFlag,
2019-07-05 03:19:24 +08:00
[currentMessage]
);
}
}
}
2016-07-01 06:50:11 +08:00
flagMessagesFast(bFlag) {
const checked = this.messageListCheckedOrSelected();
if (checked.length) {
if (undefined === bFlag) {
2020-10-23 21:15:54 +08:00
const flagged = checked.filter(message => message.isFlagged());
2019-07-05 03:19:24 +08:00
this.setAction(
2020-10-23 21:15:54 +08:00
checked[0].folder,
2019-07-05 03:19:24 +08:00
checked.length === flagged.length ? MessageSetAction.UnsetFlag : MessageSetAction.SetFlag,
checked
);
} else {
this.setAction(
2020-10-23 21:15:54 +08:00
checked[0].folder,
2019-07-05 03:19:24 +08:00
!bFlag ? MessageSetAction.UnsetFlag : MessageSetAction.SetFlag,
checked
);
}
}
2016-06-30 08:02:45 +08:00
}
seenMessagesFast(seen) {
const checked = this.messageListCheckedOrSelected();
if (checked.length) {
if (undefined === seen) {
2020-10-23 21:15:54 +08:00
const unseen = checked.filter(message => message.isUnseen());
2019-07-05 03:19:24 +08:00
this.setAction(
2020-10-23 21:15:54 +08:00
checked[0].folder,
unseen.length ? MessageSetAction.SetSeen : MessageSetAction.UnsetSeen,
2019-07-05 03:19:24 +08:00
checked
);
} else {
this.setAction(
2020-10-23 21:15:54 +08:00
checked[0].folder,
2019-07-05 03:19:24 +08:00
seen ? MessageSetAction.SetSeen : MessageSetAction.UnsetSeen,
checked
);
}
}
2016-06-30 08:02:45 +08:00
}
2015-04-21 06:39:14 +08:00
gotoPage(page) {
page && rl.route.setHash(
mailBox(
FolderStore.currentFolderFullNameHash(),
page.value,
MessageStore.messageListSearch(),
MessageStore.messageListThreadUid()
)
);
}
2015-04-21 06:39:14 +08:00
gotoThread(message) {
2019-07-05 03:19:24 +08:00
if (message && 0 < message.threadsLen()) {
MessageStore.messageListPageBeforeThread(MessageStore.messageListPage());
rl.route.setHash(
mailBox(FolderStore.currentFolderFullNameHash(), 1, MessageStore.messageListSearch(), message.uid)
);
}
2016-06-30 08:02:45 +08:00
}
2015-04-21 06:39:14 +08:00
clearListIsVisible() {
2019-07-05 03:19:24 +08:00
return (
!this.messageListSearchDesc() &&
!this.messageListError() &&
!this.messageListEndThreadUid() &&
this.messageList().length &&
2019-07-05 03:19:24 +08:00
(this.isSpamFolder() || this.isTrashFolder())
);
2016-06-30 08:02:45 +08:00
}
2015-04-21 06:39:14 +08:00
onBuild(dom) {
const eqs = (ev, s) => ev.target.closestWithin(s, dom);
this.selector.init(dom.querySelector('.b-content'), KeyState.MessageList);
dom.addEventListener('click', event => {
this.mobile && leftPanelDisabled(true);
if (eqs(event, '.messageList .b-message-list-wrapper') && Focused.MessageView === AppStore.focusedState()) {
AppStore.focusedState(Focused.MessageList);
}
2020-10-12 21:11:25 +08:00
let el = eqs(event, '.e-paginator .e-page');
el && this.gotoPage(ko.dataFor(el));
eqs(event, '.messageList .checkboxCkeckAll') && this.checkAll(!this.checkAll());
el = eqs(event, '.messageList .messageListItem .flagParent');
el && this.flagMessages(ko.dataFor(el));
el = eqs(event, '.messageList .messageListItem .threads-len');
el && this.gotoThread(ko.dataFor(el));
});
dom.addEventListener('dblclick', event => {
let el = eqs(event, '.messageList .messageListItem .actionHandle');
el && this.gotoThread(ko.dataFor(el));
});
this.initUploaderForAppend();
this.initShortcuts();
if (ifvisible && !rl.settings.app('mobile') && Settings.capa(Capa.Prefetch)) {
2020-08-14 04:58:41 +08:00
ifvisible.idle(this.prefetchNextTick.bind(this));
}
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
initShortcuts() {
shortcuts.add('enter,open', '', KeyState.MessageList, () => {
2019-07-05 03:19:24 +08:00
if (this.message() && this.useAutoSelect()) {
dispatchEvent(new CustomEvent('mailbox.message-view.toggle-full-screen'));
return false;
}
return true;
2016-06-30 08:02:45 +08:00
});
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.MessageListActions)) {
// archive (zip)
shortcuts.add('z', '', [KeyState.MessageList, KeyState.MessageView], () => {
this.archiveCommand();
return false;
});
// delete
shortcuts.add('delete', 'shift', KeyState.MessageList, () => {
MessageStore.messageListCheckedOrSelected().length && this.deleteWithoutMoveCommand();
return false;
});
// shortcuts.add('3', 'shift', KeyState.MessageList, () => {
shortcuts.add('delete', '', KeyState.MessageList, () => {
MessageStore.messageListCheckedOrSelected().length && this.deleteCommand();
return false;
});
2016-06-30 08:02:45 +08:00
}
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Reload)) {
// check mail
shortcuts.add('r', 'meta', [KeyState.FolderList, KeyState.MessageList, KeyState.MessageView], () => {
this.reloadCommand();
return false;
});
2016-06-30 08:02:45 +08:00
}
2016-07-01 06:50:11 +08:00
// check all
shortcuts.add('a', 'meta', KeyState.MessageList, () => {
this.checkAll(!(this.checkAll() && !this.isIncompleteChecked()));
return false;
});
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Composer)) {
// write/compose (open compose popup)
shortcuts.add('w,c,new', '', [KeyState.MessageList, KeyState.MessageView], () => {
showScreenPopup(require('View/Popup/Compose'));
return false;
});
2016-06-30 08:02:45 +08:00
}
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.MessageListActions)) {
// important - star/flag messages
shortcuts.add('i', '', [KeyState.MessageList, KeyState.MessageView], () => {
this.flagMessagesFast();
return false;
});
2016-06-30 08:02:45 +08:00
}
shortcuts.add('t', '', [KeyState.MessageList], () => {
let message = this.selectorMessageSelected();
2019-07-05 03:19:24 +08:00
if (!message) {
message = this.selectorMessageFocused();
}
2019-07-05 03:19:24 +08:00
if (message && 0 < message.threadsLen()) {
this.gotoThread(message);
}
2014-08-21 23:08:34 +08:00
return false;
});
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.MessageListActions)) {
// move
shortcuts.add('insert', '', KeyState.MessageList, () => {
if (this.newMoveToFolder) {
2017-02-09 01:48:53 +08:00
this.moveNewCommand();
2019-07-05 03:19:24 +08:00
} else {
2017-02-09 01:48:53 +08:00
this.moveDropdownTrigger(true);
}
return false;
2016-06-30 08:02:45 +08:00
});
}
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.MessageListActions)) {
// read
shortcuts.add('q', '', [KeyState.MessageList, KeyState.MessageView], () => {
this.seenMessagesFast(true);
return false;
});
2016-06-30 08:02:45 +08:00
// unread
shortcuts.add('u', '', [KeyState.MessageList, KeyState.MessageView], () => {
this.seenMessagesFast(false);
return false;
});
}
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Composer)) {
shortcuts.add('f,mailforward', 'shift', [KeyState.MessageList, KeyState.MessageView], () => {
this.multyForwardCommand();
return false;
});
}
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Search)) {
// search input focus
shortcuts.add('/', '', [KeyState.MessageList, KeyState.MessageView], () => {
this.inputMessageListSearchFocus(true);
return false;
});
}
2016-06-30 08:02:45 +08:00
// cancel search
shortcuts.add('escape', '', KeyState.MessageList, () => {
if (this.messageListSearchDesc()) {
this.cancelSearch();
return false;
} else if (this.messageListEndThreadUid()) {
this.cancelThreadUid();
return false;
}
2016-06-30 08:02:45 +08:00
return true;
});
// change focused state
shortcuts.add('tab', 'shift', KeyState.MessageList, () => {
AppStore.focusedState(Focused.FolderList);
return false;
});
shortcuts.add('arrowleft', '', KeyState.MessageList, () => {
AppStore.focusedState(Focused.FolderList);
return false;
});
shortcuts.add('tab,arrowright', '', KeyState.MessageList, () => {
this.message() && AppStore.focusedState(Focused.MessageView);
return false;
});
shortcuts.add('arrowleft', 'meta', KeyState.MessageView, ()=>false);
shortcuts.add('arrowright', 'meta', KeyState.MessageView, ()=>false);
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
prefetchNextTick() {
2020-10-02 18:40:33 +08:00
if (ifvisible && !this.bPrefetch && !ifvisible.now() && this.viewModelVisible) {
const message = this.messageList().find(
2020-10-23 21:15:54 +08:00
item => item && !hasRequestedMessage(item.folder, item.uid)
2019-07-05 03:19:24 +08:00
);
if (message) {
this.bPrefetch = true;
2020-10-23 21:15:54 +08:00
addRequestedMessage(message.folder, message.uid);
2019-07-05 03:19:24 +08:00
Remote.message(
(result, data) => {
const next = !!(StorageResultType.Success === result && data && data.Result);
2020-07-23 02:29:48 +08:00
setTimeout(() => {
2019-07-05 03:19:24 +08:00
this.bPrefetch = false;
next && this.prefetchNextTick();
2020-08-14 04:58:41 +08:00
}, 1000);
2019-07-05 03:19:24 +08:00
},
2020-10-23 21:15:54 +08:00
message.folder,
2019-07-05 03:19:24 +08:00
message.uid
);
}
}
2016-06-30 08:02:45 +08:00
}
advancedSearchClick() {
Settings.capa(Capa.SearchAdv)
&& showScreenPopup(require('View/Popup/AdvancedSearch'), [this.mainMessageListSearch()]);
2016-06-30 08:02:45 +08:00
}
quotaTooltip() {
return i18n('MESSAGE_LIST/QUOTA_SIZE', {
'SIZE': File.friendlySize(this.userUsageSize()),
'PROC': this.userUsageProc(),
'LIMIT': File.friendlySize(this.userQuota())
2014-08-21 23:08:34 +08:00
});
}
2013-12-09 06:14:55 +08:00
initUploaderForAppend() {
if (!Settings.app('allowAppendMessage') || !this.dragOverArea()) {
return false;
2014-08-21 23:08:34 +08:00
}
2019-07-05 03:19:24 +08:00
const oJua = new Jua({
action: append(),
name: 'AppendFile',
queueSize: 1,
multipleSizeLimit: 1,
hidden: {
Folder: () => FolderStore.currentFolderFullNameRaw()
},
dragAndDropElement: this.dragOverArea(),
dragAndDropBodyElement: this.dragOverBodyArea()
});
this.dragOver.subscribe(value => value && this.selector.scrollToTop());
2015-02-22 06:00:51 +08:00
oJua
.on('onDragEnter', () => this.dragOverEnter(true))
.on('onDragLeave', () => this.dragOverEnter(false))
.on('onBodyDragEnter', () => this.dragOver(true))
.on('onBodyDragLeave', () => this.dragOver(false))
.on('onSelect', (sUid, oData) => {
2019-07-05 03:19:24 +08:00
if (sUid && oData && 'message/rfc822' === oData.Type) {
MessageStore.messageListLoading(true);
return true;
}
2014-08-21 23:08:34 +08:00
return false;
})
2020-09-15 15:29:25 +08:00
.on('onComplete', () => rl.app.reloadMessageList(true, true));
2014-08-21 23:08:34 +08:00
return !!oJua;
}
}
2019-07-05 03:19:24 +08:00
export { MessageListMailBoxUserView, MessageListMailBoxUserView as default };