mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-27 19:19:21 +03:00
Revamp array filtering
Replaced fakeMd5 with new Jua.randomId Cleanup more code
This commit is contained in:
parent
9992b20163
commit
c3a2da65df
23 changed files with 130 additions and 289 deletions
|
|
@ -12,7 +12,6 @@ import {
|
|||
} from 'Common/Enums';
|
||||
|
||||
import {
|
||||
replySubjectAdd,
|
||||
encodeHtml,
|
||||
inFocus,
|
||||
delegateRunOnDestroy,
|
||||
|
|
@ -42,7 +41,50 @@ import { ComposeAttachmentModel } from 'Model/ComposeAttachment';
|
|||
import { popup, command, isPopupVisible, showScreenPopup, hideScreenPopup } from 'Knoin/Knoin';
|
||||
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
|
||||
|
||||
const Settings = rl.settings;
|
||||
const Settings = rl.settings,
|
||||
/**
|
||||
* @param {string} prefix
|
||||
* @param {string} subject
|
||||
* @returns {string}
|
||||
*/
|
||||
replySubjectAdd = (prefix, subject) => {
|
||||
prefix = prefix.toUpperCase().trim();
|
||||
subject = subject.replace(/[\s]+/g, ' ').trim();
|
||||
|
||||
let drop = false,
|
||||
re = 'RE' === prefix,
|
||||
fwd = 'FWD' === prefix;
|
||||
|
||||
const parts = [],
|
||||
prefixIsRe = !fwd;
|
||||
|
||||
if (subject) {
|
||||
subject.split(':').forEach(part => {
|
||||
const trimmedPart = part.trim();
|
||||
if (!drop && (/^(RE|FWD)$/i.test(trimmedPart) || /^(RE|FWD)[[(][\d]+[\])]$/i.test(trimmedPart))) {
|
||||
if (!re) {
|
||||
re = !!/^RE/i.test(trimmedPart);
|
||||
}
|
||||
|
||||
if (!fwd) {
|
||||
fwd = !!/^FWD/i.test(trimmedPart);
|
||||
}
|
||||
} else {
|
||||
parts.push(part);
|
||||
drop = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (prefixIsRe) {
|
||||
re = false;
|
||||
} else {
|
||||
fwd = false;
|
||||
}
|
||||
|
||||
return ((prefixIsRe ? 'Re: ' : 'Fwd: ') + (re ? 'Re: ' : '')
|
||||
+ (fwd ? 'Fwd: ' : '') + parts.join(':').trim()).trim();
|
||||
};
|
||||
|
||||
ko.extenders.toggleSubscribe = (target, options) => {
|
||||
target.subscribe(options[1], options[0], 'beforeChange');
|
||||
|
|
@ -773,7 +815,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
if (Array.isNotEmpty(emails)) {
|
||||
const value = fKoValue().trim(),
|
||||
values = emails.map(item => item ? item.toLine(false) : null)
|
||||
.filter((value, index, self) => !!value && self.indexOf(value) == index);
|
||||
.validUnique();
|
||||
|
||||
fKoValue(value + (value ? ', ' : '') + values.join(', ').trim());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
this.encryptKeys = ko.observableArray([]);
|
||||
|
||||
this.encryptKeysView = ko.computed(
|
||||
() => this.encryptKeys().map(oKey => (oKey ? oKey.key : null)).filter(value => !!value)
|
||||
() => this.encryptKeys().map(oKey => (oKey ? oKey.key : null)).filter(v => v)
|
||||
);
|
||||
|
||||
this.privateKeysOptions = ko.computed(() => {
|
||||
|
|
@ -56,7 +56,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
}));
|
||||
});
|
||||
|
||||
return opts.flat().filter(value => !!value);
|
||||
return opts.flat().filter(v => v);
|
||||
});
|
||||
|
||||
this.publicKeysOptions = ko.computed(() => {
|
||||
|
|
@ -71,7 +71,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
'class': index % 2 ? 'odd' : 'even'
|
||||
}));
|
||||
});
|
||||
return opts.flat().filter(value => !!value);
|
||||
return opts.flat().filter(v => v);
|
||||
});
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
|
|
@ -156,7 +156,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
|
||||
this.encryptKeys().forEach(oKey => {
|
||||
if (oKey && oKey.key) {
|
||||
aPublicKeys = aPublicKeys.concat(oKey.key.getNativeKeys().flat(Infinity).filter(value => !!value));
|
||||
aPublicKeys = aPublicKeys.concat(oKey.key.getNativeKeys().flat(Infinity).filter(v => v));
|
||||
} else if (oKey && oKey.email) {
|
||||
this.notification(
|
||||
i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND_FOR', {
|
||||
|
|
@ -349,7 +349,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
email.clear();
|
||||
email.parse(value.trim());
|
||||
return email.email || false;
|
||||
}).filter(value => !!value);
|
||||
}).filter(v => v);
|
||||
|
||||
if (identity && identity.email()) {
|
||||
emailLine = identity.email();
|
||||
|
|
@ -385,9 +385,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
'key': publicKey
|
||||
}))
|
||||
: [];
|
||||
}).flat().filter(
|
||||
(encryptKey, index, self) => encryptKey => !!encryptKey.hash && self.indexOf(encryptKey) == index
|
||||
)
|
||||
}).flat().validUnique(encryptKey => encryptKey.hash)
|
||||
);
|
||||
|
||||
if (this.encryptKeys().length) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import {
|
|||
import {
|
||||
delegateRunOnDestroy,
|
||||
computedPagenatorHelper,
|
||||
fakeMd5,
|
||||
pInt
|
||||
} from 'Common/Utils';
|
||||
|
||||
|
|
@ -154,7 +153,7 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
selected = this.currentContact();
|
||||
|
||||
return selected
|
||||
? checked.concat([selected]).filter((value, index, self) => self.indexOf(value) == index)
|
||||
? checked.concat([selected]).unique()
|
||||
: checked;
|
||||
});
|
||||
|
||||
|
|
@ -282,7 +281,7 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
this.viewSaving(true);
|
||||
this.viewSaveTrigger(SaveSettingsStep.Animate);
|
||||
|
||||
const requestUid = fakeMd5(),
|
||||
const requestUid = Jua.randomId(),
|
||||
properties = [];
|
||||
|
||||
this.viewProperties().forEach(oItem => {
|
||||
|
|
@ -579,7 +578,7 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
return contact.parse(item) ? contact : null;
|
||||
});
|
||||
|
||||
list = list.filter(value => !!value);
|
||||
list = list.filter(v => v);
|
||||
|
||||
count = pInt(data.Result.Count);
|
||||
count = 0 < count ? count : 0;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { StorageResultType, Notification } from 'Common/Enums';
|
||||
import { fakeMd5 } from 'Common/Utils';
|
||||
import { getNotification } from 'Common/Translator';
|
||||
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
|
@ -158,7 +157,7 @@ class IdentityPopupView extends AbstractViewNext {
|
|||
|
||||
this.owner(!this.id);
|
||||
} else {
|
||||
this.id = fakeMd5();
|
||||
this.id = Jua.randomId();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { KeyState } from 'Common/Enums';
|
||||
import { selectElement } from 'Common/Utils';
|
||||
|
||||
import { popup } from 'Knoin/Knoin';
|
||||
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
|
||||
|
|
@ -27,7 +26,11 @@ class ViewOpenPgpKeyPopupView extends AbstractViewNext {
|
|||
selectKey() {
|
||||
const el = this.keyDom();
|
||||
if (el) {
|
||||
selectElement(el);
|
||||
let sel = getSelection(),
|
||||
range = document.createRange();
|
||||
sel.removeAllRanges();
|
||||
range.selectNodeContents(el);
|
||||
sel.addRange(range);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import { $htmlCL, leftPanelDisabled, keyScopeReal, moveAction } from 'Common/Glo
|
|||
|
||||
import {
|
||||
inFocus,
|
||||
removeSelection,
|
||||
mailToHelper,
|
||||
isTransparent
|
||||
} from 'Common/Utils';
|
||||
|
|
@ -336,7 +335,9 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
toggleFullScreen() {
|
||||
removeSelection();
|
||||
try {
|
||||
getSelection().removeAllRanges();
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
this.fullScreenMode(!this.fullScreenMode());
|
||||
}
|
||||
|
|
@ -365,7 +366,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
|
|||
// var oEmailModel = new EmailModel();
|
||||
// oEmailModel.parse(sItem);
|
||||
// return oEmailModel.email ? oEmailModel : null;
|
||||
// }).filter(value => !!value) : null;
|
||||
// }).filter(v => v) : null;
|
||||
// }
|
||||
// ;
|
||||
//
|
||||
|
|
@ -395,7 +396,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
|
|||
};
|
||||
}
|
||||
return null;
|
||||
}).filter(value => !!value);
|
||||
}).filter(v => v);
|
||||
|
||||
if (items.length) {
|
||||
}
|
||||
|
|
@ -712,7 +713,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
|
|||
|
||||
getAttachmentsHashes() {
|
||||
const atts = this.message() ? this.message().attachments() : [];
|
||||
return atts.map(item => (item && !item.isLinked && item.checked() ? item.download : '')).filter(value => !!value);
|
||||
return atts.map(item => (item && !item.isLinked && item.checked() ? item.download : '')).filter(v => v);
|
||||
}
|
||||
|
||||
downloadAsZip() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue