mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 15:07:02 +03:00
Use JavaScript Optional chaining
This commit is contained in:
parent
d9bc435e2c
commit
732b6eb641
55 changed files with 169 additions and 199 deletions
|
|
@ -4,7 +4,7 @@ import { addObservablesTo } from 'External/ko';
|
|||
|
||||
let notificator = null,
|
||||
player = null,
|
||||
canPlay = type => player && !!player.canPlayType(type).replace('no', ''),
|
||||
canPlay = type => !!player?.canPlayType(type).replace('no', ''),
|
||||
|
||||
audioCtx = window.AudioContext || window.webkitAudioContext,
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ export const SMAudio = new class {
|
|||
}
|
||||
|
||||
pause() {
|
||||
player && player.pause();
|
||||
player?.pause();
|
||||
fireEvent('audio.stop');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@ export const
|
|||
* @param {string} folderHash
|
||||
* @returns {string}
|
||||
*/
|
||||
getFolderFullName = folderHash =>
|
||||
folderHash && FOLDERS_NAME_CACHE[folderHash] ? FOLDERS_NAME_CACHE[folderHash] : '',
|
||||
getFolderFullName = folderHash => (folderHash && FOLDERS_NAME_CACHE[folderHash]) || '',
|
||||
|
||||
/**
|
||||
* @param {string} folderHash
|
||||
|
|
@ -79,9 +78,7 @@ export class MessageFlagsCache
|
|||
* @returns {bool}
|
||||
*/
|
||||
static hasFlag(folderFullName, uid, flag) {
|
||||
return MESSAGE_FLAGS_CACHE[folderFullName]
|
||||
&& MESSAGE_FLAGS_CACHE[folderFullName][uid]
|
||||
&& MESSAGE_FLAGS_CACHE[folderFullName][uid].includes(flag);
|
||||
return MESSAGE_FLAGS_CACHE[folderFullName]?.[uid]?.includes(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -90,7 +87,7 @@ export class MessageFlagsCache
|
|||
* @returns {?Array}
|
||||
*/
|
||||
static getFor(folderFullName, uid) {
|
||||
return MESSAGE_FLAGS_CACHE[folderFullName] && MESSAGE_FLAGS_CACHE[folderFullName][uid];
|
||||
return MESSAGE_FLAGS_CACHE[folderFullName]?.[uid];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ export const FileInfo = {
|
|||
.map(item => item ? FileInfo.getIconClass(FileInfo.getExtension(item.fileName), item.mimeType) : '')
|
||||
.validUnique();
|
||||
|
||||
return (icons && 1 === icons.length && 'icon-file' !== icons[0])
|
||||
return (1 === icons?.length && 'icon-file' !== icons[0])
|
||||
? icons[0]
|
||||
: 'icon-attachment';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ fetchFolderInformation = (fCallback, folder, list = []) => {
|
|||
Remote.request('FolderInformation', fCallback, {
|
||||
Folder: folder,
|
||||
FlagsUids: uids,
|
||||
UidNext: (folderFromCache && folderFromCache.uidNext) || 0 // Used to check for new messages
|
||||
UidNext: folderFromCache?.uidNext || 0 // Used to check for new messages
|
||||
});
|
||||
} else if (SettingsUserStore.useThreads()) {
|
||||
MessagelistUserStore.reloadFlagsAndCachedMessage();
|
||||
|
|
@ -134,7 +134,7 @@ refreshFoldersInterval = 300000,
|
|||
* @param {Array=} list = []
|
||||
*/
|
||||
folderInformation = (folder, list) => {
|
||||
if (folder && folder.trim()) {
|
||||
if (folder?.trim()) {
|
||||
fetchFolderInformation(
|
||||
(iError, data) => {
|
||||
if (!iError && data.Result) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export const
|
|||
new CustomEvent(name, {detail:detail, cancelable: !!cancelable})
|
||||
),
|
||||
|
||||
formFieldFocused = () => doc.activeElement && doc.activeElement.matches('input,textarea'),
|
||||
formFieldFocused = () => doc.activeElement?.matches('input,textarea'),
|
||||
|
||||
addShortcut = (...args) => shortcuts.add(...args),
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ export const
|
|||
* @param {string} text
|
||||
* @returns {string}
|
||||
*/
|
||||
encodeHtml = text => (text && text.toString ? text.toString() : '' + text).replace(htmlre, m => htmlmap[m]),
|
||||
encodeHtml = text => (text?.toString?.() || '' + text).replace(htmlre, m => htmlmap[m]),
|
||||
|
||||
/**
|
||||
* Clears the Message Html for viewing
|
||||
|
|
@ -47,7 +47,7 @@ export const
|
|||
findAttachmentByCid = cid => oAttachments.findByCid(cid),
|
||||
findLocationByCid = cid => {
|
||||
const attachment = findAttachmentByCid(cid);
|
||||
return attachment && attachment.contentLocation ? attachment : 0;
|
||||
return attachment?.contentLocation ? attachment : 0;
|
||||
},
|
||||
|
||||
// convert body attributes to CSS
|
||||
|
|
@ -256,7 +256,7 @@ export const
|
|||
value = value.slice(4);
|
||||
setAttribute('data-x-src-cid', value);
|
||||
attachment = findAttachmentByCid(value);
|
||||
if (attachment && attachment.download) {
|
||||
if (attachment?.download) {
|
||||
oElement.src = attachment.linkPreview();
|
||||
attachment.isInline(true);
|
||||
attachment.isLinked(true);
|
||||
|
|
@ -320,7 +320,7 @@ export const
|
|||
let lowerUrl = found.toLowerCase();
|
||||
if ('cid:' === lowerUrl.slice(0, 4)) {
|
||||
const attachment = findAttachmentByCid(found);
|
||||
if (attachment && attachment.linkPreview && name) {
|
||||
if (attachment?.linkPreview && name) {
|
||||
oStyle[property] = "url('" + attachment.linkPreview() + "')";
|
||||
attachment.isInline(true);
|
||||
attachment.isLinked(true);
|
||||
|
|
@ -434,9 +434,8 @@ export const
|
|||
parent = node,
|
||||
ordered = 'OL' == node.tagName,
|
||||
i = 0;
|
||||
while (parent && parent.parentNode && parent.parentNode.closest) {
|
||||
parent = parent.parentNode.closest('ol,ul');
|
||||
parent && (prefix = ' ' + prefix);
|
||||
while ((parent = parent?.parentNode?.closest('ol,ul'))) {
|
||||
prefix = ' ' + prefix;
|
||||
}
|
||||
node.querySelectorAll(':scope > li').forEach(li => {
|
||||
li.prepend('\n' + prefix + (ordered ? `${++i}. ` : ' * '));
|
||||
|
|
@ -567,7 +566,7 @@ export class HtmlEditor {
|
|||
editor.on('focus', () => this.blurTimer && clearTimeout(this.blurTimer));
|
||||
editor.on('mode', () => {
|
||||
this.blurTrigger();
|
||||
this.onModeChange && this.onModeChange(!this.isPlain());
|
||||
this.onModeChange?.(!this.isPlain());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -575,7 +574,7 @@ export class HtmlEditor {
|
|||
blurTrigger() {
|
||||
if (this.onBlur) {
|
||||
clearTimeout(this.blurTimer);
|
||||
this.blurTimer = setTimeout(() => this.onBlur && this.onBlur(), 200);
|
||||
this.blurTimer = setTimeout(() => this.onBlur?.(), 200);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -685,7 +684,7 @@ export class HtmlEditor {
|
|||
|
||||
hasFocus() {
|
||||
try {
|
||||
return this.editor && !!this.editor.focusManager.hasFocus;
|
||||
return !!this.editor?.focusManager.hasFocus;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,10 +49,7 @@ export function runSettingsViewModelHooks(admin) {
|
|||
* @param {string} name
|
||||
* @returns {?}
|
||||
*/
|
||||
rl.pluginSettingsGet = (pluginSection, name) => {
|
||||
let plugins = SettingsGet('Plugins');
|
||||
plugins = plugins && null != plugins[pluginSection] ? plugins[pluginSection] : null;
|
||||
return plugins ? (null == plugins[name] ? null : plugins[name]) : null;
|
||||
};
|
||||
rl.pluginSettingsGet = (pluginSection, name) =>
|
||||
SettingsGet('Plugins')?.[pluginSection]?.[name];
|
||||
|
||||
rl.pluginPopupView = AbstractViewPopup;
|
||||
|
|
|
|||
|
|
@ -422,7 +422,7 @@ export class Selector {
|
|||
lineUid = '';
|
||||
|
||||
const uid = this.getItemUid(item);
|
||||
if (event && event.shiftKey) {
|
||||
if (event?.shiftKey) {
|
||||
if (uid && this.sLastUid && uid !== this.sLastUid) {
|
||||
list = this.list();
|
||||
checked = item.checked();
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ export const
|
|||
* @param {Function=} langCallback = null
|
||||
*/
|
||||
initOnStartOrLangChange = (startCallback, langCallback = null) => {
|
||||
startCallback && startCallback();
|
||||
startCallback?.();
|
||||
startCallback && trigger.subscribe(startCallback);
|
||||
langCallback && trigger.subscribe(langCallback);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -26,8 +26,7 @@ export const
|
|||
.trim(),
|
||||
|
||||
defaultOptionsAfterRender = (domItem, item) =>
|
||||
domItem && item && undefined !== item.disabled
|
||||
&& domItem.classList.toggle('disabled', domItem.disabled = item.disabled),
|
||||
item && undefined !== item.disabled && domItem?.classList.toggle('disabled', domItem.disabled = item.disabled),
|
||||
|
||||
// unescape(encodeURIComponent()) makes the UTF-16 DOMString to an UTF-8 string
|
||||
b64EncodeJSON = data => btoa(unescape(encodeURIComponent(JSON.stringify(data)))),
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ computedPaginatorHelper = (koCurrentPage, koPageCount) => {
|
|||
* @returns {boolean}
|
||||
*/
|
||||
mailToHelper = mailToUrl => {
|
||||
if (mailToUrl && 'mailto:' === mailToUrl.slice(0, 7).toLowerCase()) {
|
||||
if ('mailto:' === mailToUrl?.slice(0, 7).toLowerCase()) {
|
||||
mailToUrl = mailToUrl.slice(7).split('?');
|
||||
|
||||
const
|
||||
|
|
@ -181,7 +181,7 @@ setLayoutResizer = (source, target, sClientSideKeyName, mode) =>
|
|||
target.removeAttribute('style');
|
||||
source.removeAttribute('style');
|
||||
}
|
||||
source.observer && source.observer.disconnect();
|
||||
source.observer?.disconnect();
|
||||
// source.classList.toggle('resizable', mode);
|
||||
if (mode) {
|
||||
const length = Local.get(sClientSideKeyName + mode) || SettingsGet('Resizer' + sClientSideKeyName + mode),
|
||||
|
|
@ -248,7 +248,7 @@ setLayoutResizer = (source, target, sClientSideKeyName, mode) =>
|
|||
}
|
||||
source.layoutResizer.mode = mode;
|
||||
source.layoutResizer.key = sClientSideKeyName;
|
||||
source.observer && source.observer.observe(source, { box: 'border-box' });
|
||||
source.observer?.observe(source, { box: 'border-box' });
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ populateMessageBody = (oMessage, preload) => {
|
|||
oMessage = preload ? oMessage : null;
|
||||
let
|
||||
isNew = false,
|
||||
json = oData && oData.Result,
|
||||
json = oData?.Result,
|
||||
message = oMessage || MessageUserStore.message();
|
||||
|
||||
if (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue