mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-08 22:18:28 +03:00
Cleanup array.length checks and for() to forEach()
This commit is contained in:
parent
db5751cd00
commit
82bed1ed80
24 changed files with 135 additions and 169 deletions
|
|
@ -111,11 +111,11 @@ class AdvancedSearchPopupView extends AbstractViewNext {
|
|||
isPart.push('flagged');
|
||||
}
|
||||
|
||||
if (0 < hasPart.length) {
|
||||
if (hasPart.length) {
|
||||
result.push('has:' + hasPart.join(','));
|
||||
}
|
||||
|
||||
if (0 < isPart.length) {
|
||||
if (isPart.length) {
|
||||
result.push('is:' + isPart.join(','));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -202,19 +202,19 @@ class ComposePopupView extends AbstractViewNext {
|
|||
this.showReplyTo = ko.observable(false);
|
||||
|
||||
this.cc.subscribe((value) => {
|
||||
if (false === this.showCc() && 0 < value.length) {
|
||||
if (false === this.showCc() && value.length) {
|
||||
this.showCc(true);
|
||||
}
|
||||
});
|
||||
|
||||
this.bcc.subscribe((value) => {
|
||||
if (false === this.showBcc() && 0 < value.length) {
|
||||
if (false === this.showBcc() && value.length) {
|
||||
this.showBcc(true);
|
||||
}
|
||||
});
|
||||
|
||||
this.replyTo.subscribe((value) => {
|
||||
if (false === this.showReplyTo() && 0 < value.length) {
|
||||
if (false === this.showReplyTo() && value.length) {
|
||||
this.showReplyTo(true);
|
||||
}
|
||||
});
|
||||
|
|
@ -286,13 +286,13 @@ class ComposePopupView extends AbstractViewNext {
|
|||
});
|
||||
|
||||
this.to.subscribe((value) => {
|
||||
if (this.emptyToError() && 0 < value.length) {
|
||||
if (this.emptyToError() && value.length) {
|
||||
this.emptyToError(false);
|
||||
}
|
||||
});
|
||||
|
||||
this.attachmentsInProcess.subscribe((value) => {
|
||||
if (this.attachmentsInProcessError() && isArray(value) && 0 === value.length) {
|
||||
if (this.attachmentsInProcessError() && isArray(value) && value.length) {
|
||||
this.attachmentsInProcessError(false);
|
||||
}
|
||||
});
|
||||
|
|
@ -352,10 +352,10 @@ class ComposePopupView extends AbstractViewNext {
|
|||
this.attachmentsInErrorError(false);
|
||||
this.emptyToError(false);
|
||||
|
||||
if (0 < this.attachmentsInProcess().length) {
|
||||
if (this.attachmentsInProcess().length) {
|
||||
this.attachmentsInProcessError(true);
|
||||
this.attachmentsPlace(true);
|
||||
} else if (0 < this.attachmentsInError().length) {
|
||||
} else if (this.attachmentsInError().length) {
|
||||
this.attachmentsInErrorError(true);
|
||||
this.attachmentsPlace(true);
|
||||
}
|
||||
|
|
@ -370,7 +370,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
isArray(this.aDraftInfo) &&
|
||||
3 === this.aDraftInfo.length &&
|
||||
isNormal(this.aDraftInfo[2]) &&
|
||||
0 < this.aDraftInfo[2].length
|
||||
this.aDraftInfo[2].length
|
||||
) {
|
||||
sSentFolder = this.aDraftInfo[2];
|
||||
}
|
||||
|
|
@ -774,7 +774,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
}
|
||||
}
|
||||
|
||||
if (moments && 0 < moments.length) {
|
||||
if (moments) {
|
||||
moments.forEach(data => {
|
||||
signature = signature.replace(data[0], momentorFormat(0, data[1]));
|
||||
});
|
||||
|
|
@ -1055,7 +1055,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
i18n('COMPOSE/FORWARD_MESSAGE_TOP_TO') +
|
||||
': ' +
|
||||
sTo +
|
||||
(0 < sCc.length ? '<br />' + i18n('COMPOSE/FORWARD_MESSAGE_TOP_CC') + ': ' + sCc : '') +
|
||||
(sCc.length ? '<br />' + i18n('COMPOSE/FORWARD_MESSAGE_TOP_CC') + ': ' + sCc : '') +
|
||||
'<br />' +
|
||||
i18n('COMPOSE/FORWARD_MESSAGE_TOP_SENT') +
|
||||
': ' +
|
||||
|
|
@ -1379,7 +1379,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
if (attachment) {
|
||||
if ('' !== error && 0 < error.length) {
|
||||
if ('' !== error && error.length) {
|
||||
attachment
|
||||
.waiting(false)
|
||||
.uploading(false)
|
||||
|
|
@ -1542,15 +1542,15 @@ class ComposePopupView extends AbstractViewNext {
|
|||
*/
|
||||
isEmptyForm(includeAttachmentInProgress = true) {
|
||||
const withoutAttachment = includeAttachmentInProgress
|
||||
? 0 === this.attachments().length
|
||||
: 0 === this.attachmentsInReady().length;
|
||||
? !this.attachments().length
|
||||
: !this.attachmentsInReady().length;
|
||||
|
||||
return (
|
||||
0 === this.to().length &&
|
||||
0 === this.cc().length &&
|
||||
0 === this.bcc().length &&
|
||||
0 === this.replyTo().length &&
|
||||
0 === this.subject().length &&
|
||||
!this.to().length &&
|
||||
!this.cc().length &&
|
||||
!this.bcc().length &&
|
||||
!this.replyTo().length &&
|
||||
!this.subject().length &&
|
||||
withoutAttachment &&
|
||||
(!this.oEditor || '' === this.oEditor.getData())
|
||||
);
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
if (result && this.encrypt()) {
|
||||
if (0 === this.encryptKeys().length) {
|
||||
if (!this.encryptKeys().length) {
|
||||
this.notification(i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND'));
|
||||
result = false;
|
||||
} else if (this.encryptKeys()) {
|
||||
|
|
@ -172,7 +172,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
}
|
||||
});
|
||||
|
||||
if (result && (0 === aPublicKeys.length || this.encryptKeys().length !== aPublicKeys.length)) {
|
||||
if (result && (!aPublicKeys.length || this.encryptKeys().length !== aPublicKeys.length)) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -183,22 +183,24 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
let pgpPromise = null;
|
||||
|
||||
try {
|
||||
if (privateKey && 0 === aPublicKeys.length) {
|
||||
if (aPublicKeys.length) {
|
||||
if (privateKey) {
|
||||
pgpPromise = PgpStore.openpgp.encrypt({
|
||||
data: this.text(),
|
||||
publicKeys: aPublicKeys,
|
||||
privateKeys: [privateKey]
|
||||
});
|
||||
} else {
|
||||
pgpPromise = PgpStore.openpgp.encrypt({
|
||||
data: this.text(),
|
||||
publicKeys: aPublicKeys
|
||||
});
|
||||
}
|
||||
} else if (privateKey) {
|
||||
pgpPromise = PgpStore.openpgp.sign({
|
||||
data: this.text(),
|
||||
privateKeys: [privateKey]
|
||||
});
|
||||
} else if (privateKey && 0 < aPublicKeys.length) {
|
||||
pgpPromise = PgpStore.openpgp.encrypt({
|
||||
data: this.text(),
|
||||
publicKeys: aPublicKeys,
|
||||
privateKeys: [privateKey]
|
||||
});
|
||||
} else if (!privateKey && 0 < aPublicKeys.length) {
|
||||
pgpPromise = PgpStore.openpgp.encrypt({
|
||||
data: this.text(),
|
||||
publicKeys: aPublicKeys
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
log(e);
|
||||
|
|
@ -380,7 +382,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
this.sign(true);
|
||||
}
|
||||
|
||||
if (rec && 0 < rec.length) {
|
||||
if (rec.length) {
|
||||
this.encryptKeys(
|
||||
rec.map(recEmail => {
|
||||
const keys = PgpStore.findAllPublicKeysByEmailNotNative(recEmail);
|
||||
|
|
@ -401,7 +403,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
)
|
||||
);
|
||||
|
||||
if (0 < this.encryptKeys().length) {
|
||||
if (this.encryptKeys().length) {
|
||||
this.encrypt(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
super();
|
||||
|
||||
const fFastClearEmptyListHelper = (list) => {
|
||||
if (list && 0 < list.length) {
|
||||
if (list && list.length) {
|
||||
this.viewProperties.removeAll(list);
|
||||
delegateRunOnDestroy(list);
|
||||
}
|
||||
|
|
@ -456,7 +456,7 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
let currentContact = this.currentContact(),
|
||||
count = this.contacts().length;
|
||||
|
||||
if (0 < contacts.length) {
|
||||
if (contacts.length) {
|
||||
contacts.forEach(contact => {
|
||||
if (currentContact && currentContact.idContact === contact.idContact) {
|
||||
currentContact = null;
|
||||
|
|
@ -481,7 +481,7 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
deleteSelectedContacts() {
|
||||
if (0 < this.contactsCheckedOrSelected().length) {
|
||||
if (this.contactsCheckedOrSelected().length) {
|
||||
Remote.contactsDelete(this.deleteResponse.bind(this), this.contactsCheckedOrSelectedUids());
|
||||
|
||||
this.removeCheckedOrSelectedContactsFromList();
|
||||
|
|
|
|||
|
|
@ -43,13 +43,13 @@ class IdentityPopupView extends AbstractViewNext {
|
|||
this.submitError = ko.observable('');
|
||||
|
||||
this.bcc.subscribe((value) => {
|
||||
if (false === this.showBcc() && 0 < value.length) {
|
||||
if (false === this.showBcc() && value.length) {
|
||||
this.showBcc(true);
|
||||
}
|
||||
});
|
||||
|
||||
this.replyTo.subscribe((value) => {
|
||||
if (false === this.showReplyTo() && 0 < value.length) {
|
||||
if (false === this.showReplyTo() && value.length) {
|
||||
this.showReplyTo(true);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -163,9 +163,8 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
});
|
||||
|
||||
this.isIncompleteChecked = ko.computed(() => {
|
||||
const m = MessageStore.messageList().length,
|
||||
c = MessageStore.messageListChecked().length;
|
||||
return 0 < m && 0 < c && m > c;
|
||||
const c = MessageStore.messageListChecked().length;
|
||||
return c && MessageStore.messageList().length > c;
|
||||
});
|
||||
|
||||
this.hasMessages = ko.computed(() => 0 < this.messageList().length);
|
||||
|
|
@ -209,13 +208,11 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
);
|
||||
|
||||
this.mobileCheckedStateShow = ko.computed(() => {
|
||||
const checked = 0 < this.messageListChecked().length;
|
||||
return this.mobile ? checked : true;
|
||||
return this.mobile ? 0 < this.messageListChecked().length : true;
|
||||
});
|
||||
|
||||
this.mobileCheckedStateHide = ko.computed(() => {
|
||||
const checked = 0 < this.messageListChecked().length;
|
||||
return this.mobile ? !checked : true;
|
||||
return this.mobile ? !this.messageListChecked().length : true;
|
||||
});
|
||||
|
||||
this.messageListFocused = ko.computed(() => Focused.MessageList === AppStore.focusedState());
|
||||
|
|
@ -399,7 +396,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
goToUpUpOrDownDown(up) {
|
||||
if (0 < this.messageListChecked().length) {
|
||||
if (this.messageListChecked().length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -652,7 +649,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
const checked = this.messageListCheckedOrSelected();
|
||||
if (currentMessage) {
|
||||
const checkedUids = checked.map(message => message.uid);
|
||||
if (0 < checkedUids.length && checkedUids.includes(currentMessage.uid)) {
|
||||
if (checkedUids.includes(currentMessage.uid)) {
|
||||
this.setAction(
|
||||
currentMessage.folderFullNameRaw,
|
||||
currentMessage.flagged() ? MessageSetAction.UnsetFlag : MessageSetAction.SetFlag,
|
||||
|
|
@ -670,7 +667,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
|
||||
flagMessagesFast(bFlag) {
|
||||
const checked = this.messageListCheckedOrSelected();
|
||||
if (0 < checked.length) {
|
||||
if (checked.length) {
|
||||
if (isUnd(bFlag)) {
|
||||
const flagged = checked.filter(message => message.flagged());
|
||||
this.setAction(
|
||||
|
|
@ -690,12 +687,12 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
|
||||
seenMessagesFast(seen) {
|
||||
const checked = this.messageListCheckedOrSelected();
|
||||
if (0 < checked.length) {
|
||||
if (checked.length) {
|
||||
if (isUnd(seen)) {
|
||||
const unseen = checked.filter(message => message.unseen());
|
||||
this.setAction(
|
||||
checked[0].folderFullNameRaw,
|
||||
0 < unseen.length ? MessageSetAction.SetSeen : MessageSetAction.UnsetSeen,
|
||||
unseen.length ? MessageSetAction.SetSeen : MessageSetAction.UnsetSeen,
|
||||
checked
|
||||
);
|
||||
} else {
|
||||
|
|
@ -734,7 +731,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
'' === this.messageListSearchDesc() &&
|
||||
'' === this.messageListError() &&
|
||||
'' === this.messageListEndThreadUid() &&
|
||||
0 < this.messageList().length &&
|
||||
this.messageList().length &&
|
||||
(this.isSpamFolder() || this.isTrashFolder())
|
||||
);
|
||||
}
|
||||
|
|
@ -811,7 +808,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
// delete
|
||||
key('delete, shift+delete, shift+3', KeyState.MessageList, (event, handler) => {
|
||||
if (event) {
|
||||
if (0 < MessageStore.messageListCheckedOrSelected().length) {
|
||||
if (MessageStore.messageListCheckedOrSelected().length) {
|
||||
if (handler && 'shift+delete' === handler.shortcut) {
|
||||
this.deleteWithoutMoveCommand();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
|
|||
};
|
||||
|
||||
this.allowAttachmnetControls = ko.computed(
|
||||
() => 0 < this.attachmentsActions().length && Settings.capa(Capa.AttachmentsActions)
|
||||
() => this.attachmentsActions().length && Settings.capa(Capa.AttachmentsActions)
|
||||
);
|
||||
|
||||
this.downloadAsZipAllowed = ko.computed(
|
||||
|
|
@ -496,7 +496,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
|
|||
return null;
|
||||
}).filter(value => !!value);
|
||||
|
||||
if (0 < dynamicEls.length) {
|
||||
if (dynamicEls.length) {
|
||||
div.on('onBeforeOpen.lg', () => {
|
||||
useKeyboardShortcuts(false);
|
||||
removeInFocus(true);
|
||||
|
|
@ -888,7 +888,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
|
|||
|
||||
downloadAsZip() {
|
||||
const hashes = this.getAttachmentsHashes();
|
||||
if (0 < hashes.length) {
|
||||
if (hashes.length) {
|
||||
Promises.attachmentsActions('Zip', hashes, this.downloadAsZipLoading)
|
||||
.then((result) => {
|
||||
if (result && result.Result && result.Result.Files && result.Result.Files[0] && result.Result.Files[0].Hash) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue