Cleanup some code

This commit is contained in:
djmaze 2021-08-12 20:17:37 +02:00
parent 8d51e57d41
commit 8b116fa8ba
8 changed files with 227 additions and 276 deletions

View file

@ -179,7 +179,6 @@ class ComposePopupView extends AbstractViewPopup {
composeUploaderButton: null,
composeUploaderDropPlace: null,
dragAndDropEnabled: false,
attacheMultipleAllowed: false,
addAttachmentEnabled: false,
@ -1090,7 +1089,127 @@ class ComposePopupView extends AbstractViewPopup {
}
onBuild(dom) {
this.initUploader();
// initUploader
if (this.composeUploaderButton()) {
const uploadCache = {},
attachmentSizeLimit = pInt(SettingsGet('AttachmentLimit')),
oJua = new Jua({
action: serverRequest('Upload'),
name: 'uploader',
queueSize: 2,
multipleSizeLimit: 50,
clickElement: this.composeUploaderButton(),
dragAndDropElement: this.composeUploaderDropPlace()
});
oJua
// .on('onLimitReached', (limit) => {
// alert(limit);
// })
.on('onDragEnter', () => {
this.dragAndDropOver(true);
})
.on('onDragLeave', () => {
this.dragAndDropOver(false);
})
.on('onBodyDragEnter', () => {
this.attachmentsPlace(true);
this.dragAndDropVisible(true);
})
.on('onBodyDragLeave', () => {
this.dragAndDropVisible(false);
})
.on('onProgress', (id, loaded, total) => {
let item = uploadCache[id];
if (!item) {
item = this.getAttachmentById(id);
if (item) {
uploadCache[id] = item;
}
}
if (item) {
item.progress(Math.floor((loaded / total) * 100));
}
})
.on('onSelect', (sId, oData) => {
this.dragAndDropOver(false);
const fileName = undefined === oData.FileName ? '' : oData.FileName.toString(),
size = pInt(oData.Size, null),
attachment = new ComposeAttachmentModel(sId, fileName, size);
attachment.cancel = this.cancelAttachmentHelper(sId, oJua);
this.attachments.push(attachment);
this.attachmentsPlace(true);
if (0 < size && 0 < attachmentSizeLimit && attachmentSizeLimit < size) {
attachment
.waiting(false)
.uploading(true)
.complete(true)
.error(i18n('UPLOAD/ERROR_FILE_IS_TOO_BIG'));
return false;
}
return true;
})
.on('onStart', (id) => {
let item = uploadCache[id];
if (!item) {
item = this.getAttachmentById(id);
if (item) {
uploadCache[id] = item;
}
}
if (item) {
item
.waiting(false)
.uploading(true)
.complete(false);
}
})
.on('onComplete', (id, result, data) => {
const attachment = this.getAttachmentById(id),
errorCode = data && data.Result && data.Result.ErrorCode ? data.Result.ErrorCode : null,
attachmentJson = result && data && data.Result && data.Result.Attachment ? data.Result.Attachment : null;
let error = '';
if (null !== errorCode) {
error = getUploadErrorDescByCode(errorCode);
} else if (!attachmentJson) {
error = i18n('UPLOAD/ERROR_UNKNOWN');
}
if (attachment) {
if (error && error.length) {
attachment
.waiting(false)
.uploading(false)
.complete(true)
.error(error);
} else if (attachmentJson) {
attachment
.waiting(false)
.uploading(false)
.complete(true);
attachment.initByUploadJson(attachmentJson);
}
if (undefined === uploadCache[id]) {
delete uploadCache[id];
}
}
});
this.addAttachmentEnabled(true);
}
shortcuts.add('q', 'meta', Scope.Compose, ()=>false);
shortcuts.add('w', 'meta', Scope.Compose, ()=>false);
@ -1180,132 +1299,6 @@ class ComposePopupView extends AbstractViewPopup {
};
}
initUploader() {
if (this.composeUploaderButton()) {
const uploadCache = {},
attachmentSizeLimit = pInt(SettingsGet('AttachmentLimit')),
oJua = new Jua({
action: serverRequest('Upload'),
name: 'uploader',
queueSize: 2,
multipleSizeLimit: 50,
clickElement: this.composeUploaderButton(),
dragAndDropElement: this.composeUploaderDropPlace()
});
if (oJua) {
oJua
// .on('onLimitReached', (limit) => {
// alert(limit);
// })
.on('onDragEnter', () => {
this.dragAndDropOver(true);
})
.on('onDragLeave', () => {
this.dragAndDropOver(false);
})
.on('onBodyDragEnter', () => {
this.attachmentsPlace(true);
this.dragAndDropVisible(true);
})
.on('onBodyDragLeave', () => {
this.dragAndDropVisible(false);
})
.on('onProgress', (id, loaded, total) => {
let item = uploadCache[id];
if (!item) {
item = this.getAttachmentById(id);
if (item) {
uploadCache[id] = item;
}
}
if (item) {
item.progress(Math.floor((loaded / total) * 100));
}
})
.on('onSelect', (sId, oData) => {
this.dragAndDropOver(false);
const fileName = undefined === oData.FileName ? '' : oData.FileName.toString(),
size = pInt(oData.Size, null),
attachment = new ComposeAttachmentModel(sId, fileName, size);
attachment.cancel = this.cancelAttachmentHelper(sId, oJua);
this.attachments.push(attachment);
this.attachmentsPlace(true);
if (0 < size && 0 < attachmentSizeLimit && attachmentSizeLimit < size) {
attachment
.waiting(false)
.uploading(true)
.complete(true)
.error(i18n('UPLOAD/ERROR_FILE_IS_TOO_BIG'));
return false;
}
return true;
})
.on('onStart', (id) => {
let item = uploadCache[id];
if (!item) {
item = this.getAttachmentById(id);
if (item) {
uploadCache[id] = item;
}
}
if (item) {
item
.waiting(false)
.uploading(true)
.complete(false);
}
})
.on('onComplete', (id, result, data) => {
const attachment = this.getAttachmentById(id),
errorCode = data && data.Result && data.Result.ErrorCode ? data.Result.ErrorCode : null,
attachmentJson = result && data && data.Result && data.Result.Attachment ? data.Result.Attachment : null;
let error = '';
if (null !== errorCode) {
error = getUploadErrorDescByCode(errorCode);
} else if (!attachmentJson) {
error = i18n('UPLOAD/ERROR_UNKNOWN');
}
if (attachment) {
if (error && error.length) {
attachment
.waiting(false)
.uploading(false)
.complete(true)
.error(error);
} else if (attachmentJson) {
attachment
.waiting(false)
.uploading(false)
.complete(true);
attachment.initByUploadJson(attachmentJson);
}
if (undefined === uploadCache[id]) {
delete uploadCache[id];
}
}
});
this.addAttachmentEnabled(true).dragAndDropEnabled(true);
} else {
this.addAttachmentEnabled(false).dragAndDropEnabled(false);
}
}
}
/**
* @returns {Object}
*/

View file

@ -324,32 +324,6 @@ class ContactsPopupView extends AbstractViewPopup {
rl.app.download(serverRequestRaw('ContactsCsv'));
}
initUploader() {
if (this.importUploaderButton()) {
const j = new Jua({
action: serverRequest('UploadContacts'),
name: 'uploader',
queueSize: 1,
multipleSizeLimit: 1,
disableMultiple: true,
disableDocumentDropPrevent: true,
clickElement: this.importUploaderButton()
});
if (j) {
j.on('onStart', () => {
ContactUserStore.importing(true);
}).on('onComplete', (id, result, data) => {
ContactUserStore.importing(false);
this.reloadContactList();
if (!id || !result || !data || !data.Result) {
alert(i18n('CONTACTS/ERROR_IMPORT_FILE'));
}
});
}
}
}
removeCheckedOrSelectedContactsFromList() {
const contacts = this.contactsCheckedOrSelected();
@ -494,7 +468,31 @@ class ContactsPopupView extends AbstractViewPopup {
}
});
this.initUploader();
// initUploader
if (this.importUploaderButton()) {
const j = new Jua({
action: serverRequest('UploadContacts'),
name: 'uploader',
queueSize: 1,
multipleSizeLimit: 1,
disableMultiple: true,
disableDocumentDropPrevent: true,
clickElement: this.importUploaderButton()
});
if (j) {
j.on('onStart', () => {
ContactUserStore.importing(true);
}).on('onComplete', (id, result, data) => {
ContactUserStore.importing(false);
this.reloadContactList();
if (!id || !result || !data || !data.Result) {
alert(i18n('CONTACTS/ERROR_IMPORT_FILE'));
}
});
}
}
}
onShow(bBackToCompose, sLastComposeFocusedField) {

View file

@ -706,15 +706,41 @@ export class MessageListMailBoxUserView extends AbstractViewRight {
el && this.gotoThread(ko.dataFor(el));
});
this.initUploaderForAppend();
this.initShortcuts();
// initUploaderForAppend
if (!ThemeStore.isMobile() && Settings.capa(Capa.Prefetch)) {
ifvisible.idle(this.prefetchNextTick.bind(this));
if (Settings.app('allowAppendMessage') && this.dragOverArea()) {
const oJua = new Jua({
action: serverRequest('Append'),
name: 'AppendFile',
queueSize: 1,
multipleSizeLimit: 1,
hidden: {
Folder: () => FolderUserStore.currentFolderFullNameRaw()
},
dragAndDropElement: this.dragOverArea(),
dragAndDropBodyElement: this.dragOverBodyArea()
});
this.dragOver.subscribe(value => value && this.selector.scrollToTop());
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) => {
if (sUid && oData && 'message/rfc822' === oData.Type) {
MessageUserStore.listLoading(true);
return true;
}
return false;
})
.on('onComplete', () => rl.app.reloadMessageList(true, true));
}
}
initShortcuts() {
// initShortcuts
shortcuts.add('enter,open', '', Scope.MessageList, () => {
if (MessageUserStore.message() && this.useAutoSelect()) {
dispatchEvent(new CustomEvent('mailbox.message-view.toggle-full-screen'));
@ -855,6 +881,10 @@ export class MessageListMailBoxUserView extends AbstractViewRight {
shortcuts.add('arrowleft', 'meta', Scope.MessageView, ()=>false);
shortcuts.add('arrowright', 'meta', Scope.MessageView, ()=>false);
if (!ThemeStore.isMobile() && Settings.capa(Capa.Prefetch)) {
ifvisible.idle(this.prefetchNextTick.bind(this));
}
}
prefetchNextTick() {
@ -894,41 +924,4 @@ export class MessageListMailBoxUserView extends AbstractViewRight {
LIMIT: FileInfo.friendlySize(QuotaUserStore.quota())
}).replace(/<[^>]+>/g, '');
}
initUploaderForAppend() {
if (!Settings.app('allowAppendMessage') || !this.dragOverArea()) {
return false;
}
const oJua = new Jua({
action: serverRequest('Append'),
name: 'AppendFile',
queueSize: 1,
multipleSizeLimit: 1,
hidden: {
Folder: () => FolderUserStore.currentFolderFullNameRaw()
},
dragAndDropElement: this.dragOverArea(),
dragAndDropBodyElement: this.dragOverBodyArea()
});
this.dragOver.subscribe(value => value && this.selector.scrollToTop());
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) => {
if (sUid && oData && 'message/rfc822' === oData.Type) {
MessageUserStore.listLoading(true);
return true;
}
return false;
})
.on('onComplete', () => rl.app.reloadMessageList(true, true));
return !!oJua;
}
}

View file

@ -53,9 +53,9 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
createCommandActionHelper = (folderType, useFolder) =>
createCommand(() => {
const message = this.message();
const message = MessageUserStore.message();
if (message && this.allowMessageListActions) {
this.message(null);
MessageUserStore.message(null);
rl.app.deleteMessagesFromFolder(folderType, message.folder, [message.uid], useFolder);
}
}, this.messageVisibility);
@ -84,9 +84,6 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
this.hasCheckedMessages = MessageUserStore.hasCheckedMessages;
this.messageLoadingThrottle = MessageUserStore.messageLoading;
this.messagesBodiesDom = MessageUserStore.messagesBodiesDom;
this.useThreads = SettingsUserStore.useThreads;
this.replySameFolder = SettingsUserStore.replySameFolder;
this.layout = SettingsUserStore.layout;
this.isMessageSelected = MessageUserStore.isMessageSelected;
this.messageActiveDom = MessageUserStore.messageActiveDom;
this.messageError = MessageUserStore.messageError;
@ -157,7 +154,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
)
},
messageVisibility: () => !MessageUserStore.messageLoading() && !!this.message(),
messageVisibility: () => !MessageUserStore.messageLoading() && !!MessageUserStore.message(),
canBeRepliedOrForwarded: () => !this.isDraftFolder() && this.messageVisibility(),
@ -190,8 +187,8 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
});
this.addSubscribables({
showAttachmnetControls: v => this.message()
&& this.message().attachments.forEach(item => item && item.checked(!!v)),
showAttachmnetControls: v => MessageUserStore.message()
&& MessageUserStore.message().attachments.forEach(item => item && item.checked(!!v)),
lastReplyAction_: value => Local.set(ClientSideKeyName.LastReplyAction, value),
@ -253,7 +250,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
});
MessageUserStore.messageViewTrigger.subscribe(() => {
const message = this.message();
const message = MessageUserStore.message();
this.viewIsFlagged(message ? message.isFlagged() : false);
});
@ -279,13 +276,13 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
goUpCommand() {
dispatchEvent(new CustomEvent('mailbox.message-list.selector.go-up',
{detail:SettingsUserStore.usePreviewPane() || !!this.message()} // bForceSelect
{detail:SettingsUserStore.usePreviewPane() || !!MessageUserStore.message()} // bForceSelect
));
}
goDownCommand() {
dispatchEvent(new CustomEvent('mailbox.message-list.selector.go-down',
{detail:SettingsUserStore.usePreviewPane() || !!this.message()} // bForceSelect
{detail:SettingsUserStore.usePreviewPane() || !!MessageUserStore.message()} // bForceSelect
));
}
@ -306,11 +303,12 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
}
checkHeaderHeight() {
this.oHeaderDom && this.viewBodyTopValue(this.message() ? this.oHeaderDom.offsetHeight : 0);
this.oHeaderDom && this.viewBodyTopValue(MessageUserStore.message() ? this.oHeaderDom.offsetHeight : 0);
}
onBuild(dom) {
this.fullScreenMode.subscribe(value => value && this.message() && AppUserStore.focusedState(Scope.MessageView));
this.fullScreenMode.subscribe(value =>
value && MessageUserStore.message() && AppUserStore.focusedState(Scope.MessageView));
this.showFullInfo.subscribe(value => Local.set(ClientSideKeyName.MessageHeaderFullInfo, value ? '1' : '0'));
@ -384,7 +382,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
}
if (eqs(event, '.messageItemHeader .subjectParent .flagParent')) {
const message = this.message();
const message = MessageUserStore.message();
message && rl.app.messageListAction(
message.folder,
message.isFlagged() ? MessageSetAction.UnsetFlag : MessageSetAction.SetFlag,
@ -418,13 +416,11 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
this.oMessageScrollerDom = dom.querySelector('.messageItem');
this.initShortcuts();
}
// initShortcuts
initShortcuts() {
// exit fullscreen, back
shortcuts.add('escape,backspace', '', Scope.MessageView, () => {
if (this.viewModelVisible && this.message()) {
if (this.viewModelVisible && MessageUserStore.message()) {
const preview = SettingsUserStore.usePreviewPane();
if (this.fullScreenMode()) {
this.fullScreenMode(false);
@ -433,7 +429,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
AppUserStore.focusedState(Scope.MessageList);
}
} else if (!preview) {
this.message(null);
MessageUserStore.message(null);
} else {
AppUserStore.focusedState(Scope.MessageList);
}
@ -459,7 +455,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
return true;
});
// replaAll
// replyAll
shortcuts.add('a', '', [Scope.MessageList, Scope.MessageView], () => {
if (MessageUserStore.message()) {
this.replyAllCommand();
@ -515,7 +511,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
// print
shortcuts.add('p,printscreen', 'meta', [Scope.MessageView, Scope.MessageList], () => {
this.message() && this.message().printMessage();
MessageUserStore.message() && MessageUserStore.message().printMessage();
return false;
});
@ -531,7 +527,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
// change focused state
shortcuts.add('arrowleft', '', Scope.MessageView, () => {
if (!this.fullScreenMode() && this.message() && SettingsUserStore.usePreviewPane()) {
if (!this.fullScreenMode() && MessageUserStore.message() && SettingsUserStore.usePreviewPane()) {
if (this.oMessageScrollerDom && 0 < this.oMessageScrollerDom.scrollLeft) {
return true;
}
@ -540,7 +536,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
}
});
shortcuts.add('tab', 'shift', Scope.MessageView, () => {
if (!this.fullScreenMode() && this.message() && SettingsUserStore.usePreviewPane()) {
if (!this.fullScreenMode() && MessageUserStore.message() && SettingsUserStore.usePreviewPane()) {
AppUserStore.focusedState(Scope.MessageList);
}
return false;
@ -623,7 +619,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
}
downloadAsZip() {
const hashes = (this.message() ? this.message().attachments : [])
const hashes = (MessageUserStore.message() ? MessageUserStore.message().attachments : [])
.map(item => (item && !item.isLinked && item.checked() ? item.download : ''))
.filter(v => v);
if (hashes.length) {
@ -647,10 +643,8 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
* @param {MessageModel} oMessage
* @returns {void}
*/
showImages(message) {
if (message && message.showExternalImages) {
message.showExternalImages();
}
showImages() {
MessageUserStore.message() && MessageUserStore.message().showExternalImages();
}
/**
@ -665,7 +659,8 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
* @param {MessageModel} oMessage
* @returns {void}
*/
readReceipt(oMessage) {
readReceipt() {
let oMessage = MessageUserStore.message()
if (oMessage && oMessage.readReceipt()) {
Remote.sendReadReceiptMessage(
()=>{},