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

842 lines
23 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2019-07-05 03:19:24 +08:00
import { DATA_IMAGE_USER_DOT_PIC, UNUSED_OPTION_VALUE } from 'Common/Consts';
import {
2019-07-05 03:19:24 +08:00
Capa,
ComposeType,
ClientSideKeyName,
KeyState,
FolderType,
Focused,
Layout,
MessageSetAction
} from 'Common/Enums';
import { $htmlCL, leftPanelDisabled, keyScopeReal, useKeyboardShortcuts, moveAction } from 'Common/Globals';
import {
2019-07-05 03:19:24 +08:00
inFocus,
removeSelection,
removeInFocus,
mailToHelper,
isTransparent
} from 'Common/Utils';
import Audio from 'Common/Audio';
2019-07-05 03:19:24 +08:00
import { i18n } from 'Common/Translator';
import { attachmentDownload } from 'Common/Links';
2019-07-05 03:19:24 +08:00
import { getUserPic, storeMessageFlagsToCache } from 'Common/Cache';
import AppStore from 'Stores/User/App';
import SettingsStore from 'Stores/User/Settings';
import AccountStore from 'Stores/User/Account';
import FolderStore from 'Stores/User/Folder';
import MessageStore from 'Stores/User/Message';
import * as Local from 'Storage/Client';
import Remote from 'Remote/User/Fetch';
2019-07-05 03:19:24 +08:00
import { getApp } from 'Helper/Apps/User';
2019-07-05 03:19:24 +08:00
import { view, command, ViewType, showScreenPopup, createCommand } from 'Knoin/Knoin';
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
const Settings = rl.settings;
@view({
name: 'View/User/MailBox/MessageView',
type: ViewType.Right,
templateID: 'MailMessageView'
})
2019-07-05 03:19:24 +08:00
class MessageViewMailBoxUserView extends AbstractViewNext {
constructor() {
super();
2014-08-20 23:03:12 +08:00
let lastEmail = '';
2019-07-05 03:19:24 +08:00
const createCommandReplyHelper = (type) =>
createCommand(() => {
this.lastReplyAction(type);
this.replyOrforward(type);
}, this.canBeRepliedOrForwarded);
const createCommandActionHelper = (folderType, useFolder) =>
createCommand(() => {
const message = this.message();
if (message && this.allowMessageListActions) {
this.message(null);
getApp().deleteMessagesFromFolder(folderType, message.folderFullNameRaw, [message.uid], useFolder);
}
}, this.messageVisibility);
2014-08-20 23:03:12 +08:00
this.oHeaderDom = null;
this.oMessageScrollerDom = null;
2014-08-20 23:03:12 +08:00
this.bodyBackgroundColor = ko.observable('');
2014-08-20 23:03:12 +08:00
this.pswp = null;
2017-03-02 02:38:18 +08:00
this.moveAction = moveAction;
this.allowComposer = !!Settings.capa(Capa.Composer);
this.allowMessageActions = !!Settings.capa(Capa.MessageActions);
this.allowMessageListActions = !!Settings.capa(Capa.MessageListActions);
this.logoImg = (Settings.get('UserLogoMessage')||'').trim();
this.logoIframe = (Settings.get('UserIframeMessage')||'').trim();
this.mobile = !!Settings.app('mobile');
this.attachmentsActions = AppStore.attachmentsActions;
2016-05-01 09:07:10 +08:00
this.message = MessageStore.message;
this.messageListChecked = MessageStore.messageListChecked;
this.hasCheckedMessages = MessageStore.hasCheckedMessages;
this.messageListCheckedOrSelectedUidsWithSubMails = MessageStore.messageListCheckedOrSelectedUidsWithSubMails;
this.messageLoadingThrottle = MessageStore.messageLoadingThrottle;
this.messagesBodiesDom = MessageStore.messagesBodiesDom;
this.useThreads = SettingsStore.useThreads;
this.replySameFolder = SettingsStore.replySameFolder;
this.layout = SettingsStore.layout;
this.usePreviewPane = SettingsStore.usePreviewPane;
this.isMessageSelected = MessageStore.isMessageSelected;
this.messageActiveDom = MessageStore.messageActiveDom;
this.messageError = MessageStore.messageError;
2015-04-25 06:15:11 +08:00
this.fullScreenMode = MessageStore.messageFullScreenMode;
2014-08-22 23:08:56 +08:00
2019-07-05 03:19:24 +08:00
this.messageListOfThreadsLoading = ko.observable(false).extend({ rateLimit: 1 });
this.highlightUnselectedAttachments = ko.observable(false).extend({ falseTimeout: 2000 });
2014-08-20 23:03:12 +08:00
this.showAttachmnetControls = ko.observable(false);
this.showAttachmnetControlsState = v => Local.set(ClientSideKeyName.MessageAttachmnetControls, !!v);
this.allowAttachmnetControls = ko.computed(
() => this.attachmentsActions().length && Settings.capa(Capa.AttachmentsActions)
);
2015-04-25 06:15:11 +08:00
this.downloadAsZipAllowed = ko.computed(
() => this.attachmentsActions().includes('zip') && this.allowAttachmnetControls()
);
2015-04-11 05:52:15 +08:00
this.downloadAsZipLoading = ko.observable(false);
2019-07-05 03:19:24 +08:00
this.downloadAsZipError = ko.observable(false).extend({ falseTimeout: 7000 });
2015-04-25 06:15:11 +08:00
this.showAttachmnetControls.subscribe(v => this.message()
&& this.message().attachments().forEach(item => item && item.checked(!!v))
);
2015-04-14 02:45:09 +08:00
this.lastReplyAction_ = ko.observable('');
this.lastReplyAction = ko.computed({
read: this.lastReplyAction_,
write: value => this.lastReplyAction_(
[ComposeType.Reply, ComposeType.ReplyAll, ComposeType.Forward].includes(value)
? ComposeType.Reply
: value
)
});
2015-01-19 04:55:37 +08:00
this.lastReplyAction(Local.get(ClientSideKeyName.LastReplyAction) || ComposeType.Reply);
2015-01-19 04:55:37 +08:00
this.lastReplyAction_.subscribe(value => Local.set(ClientSideKeyName.LastReplyAction, value));
2014-08-20 23:03:12 +08:00
this.showFullInfo = ko.observable('1' === Local.get(ClientSideKeyName.MessageHeaderFullInfo));
2014-08-20 23:03:12 +08:00
this.moreDropdownTrigger = ko.observable(false);
2019-07-05 03:19:24 +08:00
this.messageDomFocused = ko.observable(false).extend({ rateLimit: 0 });
this.messageVisibility = ko.computed(() => !this.messageLoadingThrottle() && !!this.message());
this.message.subscribe(message => (!message) && MessageStore.selectorMessageSelected(null));
this.canBeRepliedOrForwarded = ko.computed(() => !this.isDraftFolder() && this.messageVisibility());
// commands
this.replyCommand = createCommandReplyHelper(ComposeType.Reply);
this.replyAllCommand = createCommandReplyHelper(ComposeType.ReplyAll);
this.forwardCommand = createCommandReplyHelper(ComposeType.Forward);
this.forwardAsAttachmentCommand = createCommandReplyHelper(ComposeType.ForwardAsAttachment);
this.editAsNewCommand = createCommandReplyHelper(ComposeType.EditAsNew);
this.deleteCommand = createCommandActionHelper(FolderType.Trash, true);
this.deleteWithoutMoveCommand = createCommandActionHelper(FolderType.Trash, false);
this.archiveCommand = createCommandActionHelper(FolderType.Archive, true);
this.spamCommand = createCommandActionHelper(FolderType.Spam, true);
this.notSpamCommand = createCommandActionHelper(FolderType.NotSpam, true);
// viewer
this.viewBodyTopValue = ko.observable(0);
this.viewFolder = '';
this.viewUid = '';
this.viewHash = '';
this.viewSubject = ko.observable('');
this.viewFromShort = ko.observable('');
this.viewFromDkimData = ko.observable(['none', '']);
this.viewToShort = ko.observable('');
this.viewFrom = ko.observable('');
this.viewTo = ko.observable('');
this.viewCc = ko.observable('');
this.viewBcc = ko.observable('');
this.viewReplyTo = ko.observable('');
this.viewTimeStamp = ko.observable(0);
this.viewSize = ko.observable('');
this.viewLineAsCss = ko.observable('');
this.viewViewLink = ko.observable('');
this.viewUnsubscribeLink = ko.observable('');
this.viewDownloadLink = ko.observable('');
this.viewUserPic = ko.observable(DATA_IMAGE_USER_DOT_PIC);
this.viewUserPicVisible = ko.observable(false);
this.viewIsImportant = ko.observable(false);
this.viewIsFlagged = ko.observable(false);
this.viewFromDkimVisibility = ko.computed(() => 'none' !== this.viewFromDkimData()[0]);
this.viewFromDkimStatusIconClass = ko.computed(() => {
2019-07-05 03:19:24 +08:00
switch (this.viewFromDkimData()[0]) {
case 'none':
return 'icon-none iconcolor-display-none';
case 'pass':
return 'icon-ok iconcolor-green';
default:
return 'icon-warning-alt iconcolor-red';
2016-06-30 08:02:45 +08:00
}
});
this.viewFromDkimStatusTitle = ko.computed(() => {
const status = this.viewFromDkimData();
2020-09-04 23:07:35 +08:00
if (Array.isNotEmpty(status)) {
2019-07-05 03:19:24 +08:00
if (status[0] && status[1]) {
return status[1];
2019-07-05 03:19:24 +08:00
} else if (status[0]) {
return 'DKIM: ' + status[0];
}
}
2015-03-06 08:42:40 +08:00
return '';
});
2014-08-20 23:03:12 +08:00
this.messageActiveDom.subscribe(dom => this.bodyBackgroundColor(this.detectDomBackgroundColor(dom)), this);
2014-08-20 23:03:12 +08:00
this.message.subscribe((message) => {
this.messageActiveDom(null);
2014-08-20 23:03:12 +08:00
2019-07-05 03:19:24 +08:00
if (message) {
this.showAttachmnetControls(false);
2019-07-05 03:19:24 +08:00
if (Local.get(ClientSideKeyName.MessageAttachmnetControls)) {
setTimeout(() => {
this.showAttachmnetControls(true);
2020-08-14 04:58:41 +08:00
}, 50);
}
2019-07-05 03:19:24 +08:00
if (this.viewHash !== message.hash) {
this.scrollMessageToTop();
}
2016-06-30 08:02:45 +08:00
this.viewFolder = message.folderFullNameRaw;
this.viewUid = message.uid;
this.viewHash = message.hash;
this.viewSubject(message.subject());
this.viewFromShort(message.fromToLine(true, true));
this.viewFromDkimData(message.fromDkimData());
this.viewToShort(message.toToLine(true, true));
this.viewFrom(message.fromToLine(false));
this.viewTo(message.toToLine(false));
this.viewCc(message.ccToLine(false));
this.viewBcc(message.bccToLine(false));
this.viewReplyTo(message.replyToToLine(false));
this.viewTimeStamp(message.dateTimeStampInUTC());
this.viewSize(message.friendlySize());
this.viewLineAsCss(message.lineAsCss());
this.viewViewLink(message.viewLink());
this.viewUnsubscribeLink(message.getFirstUnsubsribeLink());
this.viewDownloadLink(message.downloadLink());
this.viewIsImportant(message.isImportant());
this.viewIsFlagged(message.flagged());
lastEmail = message.fromAsSingleEmail();
getUserPic(lastEmail, (pic, email) => {
2019-07-05 03:19:24 +08:00
if (pic !== this.viewUserPic() && lastEmail === email) {
this.viewUserPicVisible(false);
this.viewUserPic(DATA_IMAGE_USER_DOT_PIC);
if (pic) {
this.viewUserPicVisible(true);
this.viewUserPic(pic);
}
}
});
2019-07-05 03:19:24 +08:00
} else {
this.viewFolder = '';
this.viewUid = '';
this.viewHash = '';
this.scrollMessageToTop();
}
});
this.message.viewTrigger.subscribe(() => {
const message = this.message();
message ? this.viewIsFlagged(message.flagged()) : this.viewIsFlagged(false);
});
this.fullScreenMode.subscribe(value => $htmlCL.toggle('rl-message-fullscreen', value));
this.messageFocused = ko.computed(() => Focused.MessageView === AppStore.focusedState());
2016-06-30 08:02:45 +08:00
this.messageListAndMessageViewLoading = ko.computed(
() => MessageStore.messageListCompleteLoadingThrottle() || MessageStore.messageLoadingThrottle()
);
2016-06-30 08:02:45 +08:00
addEventListener('mailbox.message-view.toggle-full-screen', () => this.toggleFullScreen());
this.attachmentPreview = this.attachmentPreview.bind(this);
2016-06-30 08:02:45 +08:00
}
@command()
closeMessageCommand() {
MessageStore.message(null);
}
@command((self) => self.messageVisibility())
messageVisibilityCommand() {} // eslint-disable-line no-empty-function
@command((self) => self.messageVisibility())
messageEditCommand() {
this.editMessage();
}
@command((self) => !self.messageListAndMessageViewLoading())
goUpCommand() {
dispatchEvent(new CustomEvent('mailbox.message-list.selector.go-up',
{detail:Layout.NoPreview === this.layout() ? !!this.message() : true}
));
}
@command((self) => !self.messageListAndMessageViewLoading())
goDownCommand() {
dispatchEvent(new CustomEvent('mailbox.message-list.selector.go-up',
{detail:Layout.NoPreview === this.layout() ? !!this.message() : true}
));
}
detectDomBackgroundColor(dom) {
2020-08-27 21:45:47 +08:00
let color = '';
if (dom) {
let limit = 5,
aC = dom;
while (!color && aC && limit--) {
let children = aC.children;
if (!children || 1 !== children.length || !children[0].matches('table,div,center')) break;
aC = children[0];
color = aC.style.backgroundColor || '';
if (!aC.matches('table')) {
color = isTransparent(color) ? '' : color;
}
}
2020-08-27 21:45:47 +08:00
color = isTransparent(color) ? '' : color;
2016-06-30 08:02:45 +08:00
}
2015-04-15 06:27:10 +08:00
2020-08-27 21:45:47 +08:00
return color;
2016-06-30 08:02:45 +08:00
}
2015-01-18 23:26:00 +08:00
fullScreen() {
this.fullScreenMode(true);
}
2015-04-25 06:15:11 +08:00
unFullScreen() {
this.fullScreenMode(false);
}
2015-04-25 06:15:11 +08:00
toggleFullScreen() {
removeSelection();
2015-01-18 23:26:00 +08:00
this.fullScreenMode(!this.fullScreenMode());
}
/**
* @param {string} sType
* @returns {void}
*/
replyOrforward(sType) {
Settings.capa(Capa.Composer) && showScreenPopup(require('View/Popup/Compose'), [sType, MessageStore.message()]);
2016-06-30 08:02:45 +08:00
}
2016-05-01 09:07:10 +08:00
checkHeaderHeight() {
this.oHeaderDom && this.viewBodyTopValue(this.message() ? this.oHeaderDom.offsetHeight : 0);
2016-06-30 08:02:45 +08:00
}
// displayMailToPopup(sMailToUrl) {
// sMailToUrl = sMailToUrl.replace(/\?.+$/, '');
//
// var
// sResult = '',
// aTo = [],
// EmailModel = require('Model/Email').default,
// fParseEmailLine = function(sLine) {
// return sLine ? [decodeURIComponent(sLine)].map(sItem => {
// var oEmailModel = new EmailModel();
2017-09-28 01:58:15 +08:00
// oEmailModel.parse(sItem);
// return oEmailModel.email ? oEmailModel : null;
// }).filter(value => !!value) : null;
// }
// ;
//
// aTo = fParseEmailLine(sMailToUrl);
// sResult = aTo && aTo[0] ? aTo[0].email : '';
//
// return sResult;
// }
/**
* @param {Object} oAttachment
* @returns {boolean}
*/
attachmentPreview(attachment) {
2019-07-05 03:19:24 +08:00
if (attachment && attachment.isImage() && !attachment.isLinked && this.message() && this.message().attachments()) {
let index = 0,
listIndex = 0;
const div = jQuery('<div>'),
dynamicEls = this.message().attachments().map(item => {
if (item && !item.isLinked && item.isImage()) {
if (item === attachment) {
index = listIndex;
}
listIndex += 1;
return {
src: item.linkPreview(),
thumb: item.linkThumbnail(),
subHtml: item.fileName,
downloadUrl: item.linkPreview()
};
}
return null;
}).filter(value => !!value);
if (dynamicEls.length) {
div.on('onBeforeOpen.lg', () => {
useKeyboardShortcuts(false);
removeInFocus(true);
});
div.on('onCloseAfter.lg', () => useKeyboardShortcuts(true));
div.lightGallery({
dynamic: true,
loadYoutubeThumbnail: false,
loadVimeoThumbnail: false,
thumbWidth: 80,
thumbContHeight: 95,
showThumbByDefault: false,
mode: 'lg-lollipop', // 'lg-slide',
index: index,
dynamicEl: dynamicEls
});
2016-06-17 07:23:49 +08:00
}
2014-08-20 23:03:12 +08:00
return false;
2016-06-30 08:02:45 +08:00
}
return true;
}
onBuild(dom) {
this.fullScreenMode.subscribe(value => value && this.message() && AppStore.focusedState(Focused.MessageView));
this.showFullInfo.subscribe(value => Local.set(ClientSideKeyName.MessageHeaderFullInfo, value ? '1' : '0'));
this.oHeaderDom = dom.querySelector('.messageItemHeader');
if (this.oHeaderDom) {
if (!this.resizeObserver) {
this.resizeObserver = new ResizeObserver(this.checkHeaderHeight.throttle(50).bind(this));
}
this.resizeObserver.observe(this.oHeaderDom);
} else if (this.resizeObserver) {
this.resizeObserver.disconnect();
}
const eqs = (ev, s) => ev.target.closestWithin(s, dom);
dom.addEventListener('click', event => {
this.mobile && leftPanelDisabled(true);
let el = eqs(event, 'a');
if (el) {
2019-07-05 03:19:24 +08:00
return !(
!!event &&
2020-08-14 04:58:41 +08:00
3 !== event.which &&
2019-07-05 03:19:24 +08:00
mailToHelper(
el.href,
Settings.capa(Capa.Composer) ? require('View/Popup/Compose') : null
2019-07-05 03:19:24 +08:00
)
);
}
if (eqs(event, '.attachmentsPlace .attachmentIconParent')) {
event.stopPropagation();
}
el = eqs(event, '.attachmentsPlace .showPreplay');
if (el) {
event.stopPropagation();
const attachment = ko.dataFor(el); // eslint-disable-line no-invalid-this
2019-07-05 03:19:24 +08:00
if (attachment && Audio.supported) {
switch (true) {
case Audio.supportedMp3 && attachment.isMp3():
Audio.playMp3(attachment.linkDownload(), attachment.fileName);
break;
case Audio.supportedOgg && attachment.isOgg():
Audio.playOgg(attachment.linkDownload(), attachment.fileName);
break;
case Audio.supportedWav && attachment.isWav():
Audio.playWav(attachment.linkDownload(), attachment.fileName);
break;
// no default
}
}
}
el = eqs(event, '.attachmentsPlace .attachmentItem .attachmentNameParent');
if (el) {
const attachment = ko.dataFor(el);
attachment && attachment.download && getApp().download(attachment.linkDownload());
}
if (eqs(event, '.messageItemHeader .subjectParent .flagParent')) {
2019-07-05 03:19:24 +08:00
// eslint-disable-line prefer-arrow-callback
const message = this.message();
message && getApp().messageListAction(
message.folderFullNameRaw,
message.flagged() ? MessageSetAction.UnsetFlag : MessageSetAction.SetFlag,
[message]
);
}
el = eqs(event, '.thread-list .flagParent');
if (el) {
2019-07-05 03:19:24 +08:00
// eslint-disable-line prefer-arrow-callback
const message = ko.dataFor(el); // eslint-disable-line no-invalid-this
message && message.folder && message.uid && getApp().messageListAction(
message.folder,
message.flagged() ? MessageSetAction.UnsetFlag : MessageSetAction.SetFlag,
[message]
);
2016-07-01 06:50:11 +08:00
this.threadsDropdownTrigger(true);
return false;
}
});
AppStore.focusedState.subscribe((value) => {
2019-07-05 03:19:24 +08:00
if (Focused.MessageView !== value) {
this.scrollMessageToTop();
this.scrollMessageToLeft();
}
});
keyScopeReal.subscribe(value => this.messageDomFocused(KeyState.MessageView === value && !inFocus()));
this.oMessageScrollerDom = dom.querySelector('.messageItem');
2016-07-01 06:50:11 +08:00
this.initShortcuts();
}
/**
* @returns {boolean}
*/
escShortcuts() {
2019-07-05 03:19:24 +08:00
if (this.viewModelVisibility() && this.message()) {
const preview = Layout.NoPreview !== this.layout();
2019-07-05 03:19:24 +08:00
if (this.fullScreenMode()) {
this.fullScreenMode(false);
2016-07-01 06:50:11 +08:00
if (preview) {
AppStore.focusedState(Focused.MessageList);
}
} else if (!preview) {
this.message(null);
2019-07-05 03:19:24 +08:00
} else {
AppStore.focusedState(Focused.MessageList);
}
2016-06-30 08:02:45 +08:00
return false;
}
2016-07-01 06:50:11 +08:00
return true;
}
initShortcuts() {
// exit fullscreen, back
key('esc, backspace', KeyState.MessageView, this.escShortcuts.bind(this));
// fullscreen
key('enter', KeyState.MessageView, () => {
this.toggleFullScreen();
2016-06-30 08:02:45 +08:00
return false;
});
2016-07-01 06:50:11 +08:00
// reply
key('r', [KeyState.MessageList, KeyState.MessageView], () => {
2019-07-05 03:19:24 +08:00
if (MessageStore.message()) {
this.replyCommand();
return false;
}
return true;
});
2016-06-30 08:02:45 +08:00
// replaAll
key('a', [KeyState.MessageList, KeyState.MessageView], () => {
2019-07-05 03:19:24 +08:00
if (MessageStore.message()) {
this.replyAllCommand();
return false;
}
2016-06-30 08:02:45 +08:00
return true;
});
// forward
key('f', [KeyState.MessageList, KeyState.MessageView], () => {
2019-07-05 03:19:24 +08:00
if (MessageStore.message()) {
this.forwardCommand();
return false;
}
2016-06-30 08:02:45 +08:00
return true;
});
// message information
key('ctrl+i, command+i', [KeyState.MessageList, KeyState.MessageView], () => {
2019-07-05 03:19:24 +08:00
if (MessageStore.message()) {
this.showFullInfo(!this.showFullInfo());
2014-11-20 07:25:39 +08:00
}
return false;
});
// toggle message blockquotes
key('b', [KeyState.MessageList, KeyState.MessageView], () => {
2020-08-27 21:45:47 +08:00
const message = MessageStore.message();
if (message && message.body) {
message.body.querySelectorAll('.rlBlockquoteSwitcher').forEach(node => node.click());
return false;
2014-11-20 07:25:39 +08:00
}
return true;
});
key('ctrl+up, command+up, ctrl+left, command+left', [KeyState.MessageList, KeyState.MessageView], () => {
this.goUpCommand();
2016-06-30 08:02:45 +08:00
return false;
});
2016-07-01 06:50:11 +08:00
key('ctrl+down, command+down, ctrl+right, command+right', [KeyState.MessageList, KeyState.MessageView], () => {
this.goDownCommand();
return false;
});
2015-04-14 02:45:09 +08:00
// print
key('ctrl+p, command+p', [KeyState.MessageView, KeyState.MessageList], () => {
2019-07-05 03:19:24 +08:00
if (this.message()) {
this.message().printMessage();
}
return false;
});
// delete
key('delete, shift+delete', KeyState.MessageView, (event, handler) => {
2019-07-05 03:19:24 +08:00
if (event) {
if (handler && 'shift+delete' === handler.shortcut) {
this.deleteWithoutMoveCommand();
2019-07-05 03:19:24 +08:00
} else {
this.deleteCommand();
2015-04-25 06:15:11 +08:00
}
2016-06-30 08:02:45 +08:00
return false;
2016-06-30 08:02:45 +08:00
}
2016-06-30 08:02:45 +08:00
return true;
});
2015-04-14 02:45:09 +08:00
// change focused state
key('tab, shift+tab, left', KeyState.MessageView, (event, handler) => {
2019-07-05 03:19:24 +08:00
if (!this.fullScreenMode() && this.message() && Layout.NoPreview !== this.layout()) {
if (event && handler && 'left' === handler.shortcut) {
if (this.oMessageScrollerDom && 0 < this.oMessageScrollerDom.scrollLeft) {
return true;
}
2016-06-30 08:02:45 +08:00
AppStore.focusedState(Focused.MessageList);
2019-07-05 03:19:24 +08:00
} else {
AppStore.focusedState(Focused.MessageList);
}
2019-07-05 03:19:24 +08:00
} else if (
this.message() &&
Layout.NoPreview === this.layout() &&
event &&
handler &&
'left' === handler.shortcut
) {
return true;
}
2016-06-30 08:02:45 +08:00
return false;
});
}
2016-06-30 08:02:45 +08:00
/**
* @returns {boolean}
*/
isDraftFolder() {
return MessageStore.message() && FolderStore.draftFolder() === MessageStore.message().folderFullNameRaw;
}
2016-06-30 08:02:45 +08:00
/**
* @returns {boolean}
*/
isSentFolder() {
return MessageStore.message() && FolderStore.sentFolder() === MessageStore.message().folderFullNameRaw;
}
2016-06-30 08:02:45 +08:00
/**
* @returns {boolean}
*/
isSpamFolder() {
return MessageStore.message() && FolderStore.spamFolder() === MessageStore.message().folderFullNameRaw;
}
2016-06-30 08:02:45 +08:00
/**
* @returns {boolean}
*/
isSpamDisabled() {
return MessageStore.message() && FolderStore.spamFolder() === UNUSED_OPTION_VALUE;
}
2016-06-30 08:02:45 +08:00
/**
* @returns {boolean}
*/
isArchiveFolder() {
return MessageStore.message() && FolderStore.archiveFolder() === MessageStore.message().folderFullNameRaw;
}
2016-06-30 08:02:45 +08:00
/**
* @returns {boolean}
*/
isArchiveDisabled() {
return MessageStore.message() && FolderStore.archiveFolder() === UNUSED_OPTION_VALUE;
2016-06-30 08:02:45 +08:00
}
/**
* @returns {boolean}
*/
isDraftOrSentFolder() {
return this.isDraftFolder() || this.isSentFolder();
2016-06-30 08:02:45 +08:00
}
composeClick() {
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Composer)) {
showScreenPopup(require('View/Popup/Compose'));
2015-04-25 06:15:11 +08:00
}
2016-06-30 08:02:45 +08:00
}
editMessage() {
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Composer) && MessageStore.message()) {
showScreenPopup(require('View/Popup/Compose'), [ComposeType.Draft, MessageStore.message()]);
}
2016-06-30 08:02:45 +08:00
}
scrollMessageToTop() {
2019-07-05 03:19:24 +08:00
if (this.oMessageScrollerDom) {
2020-08-14 04:58:41 +08:00
if (50 < this.oMessageScrollerDom.scrollTop) {
this.oMessageScrollerDom.scrollTop = 50;
2019-07-05 03:19:24 +08:00
} else {
this.oMessageScrollerDom.scrollTop = 0;
2016-06-30 08:02:45 +08:00
}
}
2016-06-30 08:02:45 +08:00
}
scrollMessageToLeft() {
2019-07-05 03:19:24 +08:00
if (this.oMessageScrollerDom) {
this.oMessageScrollerDom.scrollLeft = 0;
}
2016-06-30 08:02:45 +08:00
}
2015-04-25 06:15:11 +08:00
getAttachmentsHashes() {
const atts = this.message() ? this.message().attachments() : [];
return atts.map(item => (item && !item.isLinked && item.checked() ? item.download : '')).filter(value => !!value);
2016-06-30 08:02:45 +08:00
}
downloadAsZip() {
const hashes = this.getAttachmentsHashes();
if (hashes.length) {
Remote.attachmentsActions('Zip', hashes, this.downloadAsZipLoading)
2019-07-05 03:19:24 +08:00
.then((result) => {
if (result && result.Result && result.Result.Files && result.Result.Files[0] && result.Result.Files[0].Hash) {
getApp().download(attachmentDownload(result.Result.Files[0].Hash));
} else {
this.downloadAsZipError(true);
}
})
.catch(() => {
this.downloadAsZipError(true);
2019-07-05 03:19:24 +08:00
});
} else {
this.highlightUnselectedAttachments(true);
}
2016-06-30 08:02:45 +08:00
}
2015-04-14 02:45:09 +08:00
/**
* @param {MessageModel} oMessage
* @returns {void}
*/
showImages(message) {
2019-07-05 03:19:24 +08:00
if (message && message.showExternalImages) {
2020-08-27 21:45:47 +08:00
message.showExternalImages();
}
2016-06-30 08:02:45 +08:00
}
/**
* @returns {string}
*/
printableCheckedMessageCount() {
const cnt = this.messageListCheckedOrSelectedUidsWithSubMails().length;
return 0 < cnt ? (100 > cnt ? cnt : '99+') : ''; // eslint-disable-line no-magic-numbers
2016-06-30 08:02:45 +08:00
}
/**
* @param {MessageModel} oMessage
* @returns {void}
*/
readReceipt(oMessage) {
if (oMessage && oMessage.readReceipt()) {
2019-07-05 03:19:24 +08:00
Remote.sendReadReceiptMessage(
()=>{},
2019-07-05 03:19:24 +08:00
oMessage.folderFullNameRaw,
oMessage.uid,
oMessage.readReceipt(),
2019-07-05 03:19:24 +08:00
i18n('READ_RECEIPT/SUBJECT', { 'SUBJECT': oMessage.subject() }),
i18n('READ_RECEIPT/BODY', { 'READ-RECEIPT': AccountStore.email() })
);
2016-06-30 08:02:45 +08:00
oMessage.isReadReceipt(true);
storeMessageFlagsToCache(oMessage);
2014-08-25 15:10:51 +08:00
getApp().reloadFlagsCurrentMessageListAndMessageFromCache();
}
2016-06-30 08:02:45 +08:00
}
}
2014-01-04 08:20:07 +08:00
2019-07-05 03:19:24 +08:00
export { MessageViewMailBoxUserView, MessageViewMailBoxUserView as default };