Use JavaScript Optional chaining

This commit is contained in:
the-djmaze 2022-09-02 11:52:07 +02:00
parent d9bc435e2c
commit 732b6eb641
55 changed files with 169 additions and 199 deletions

View file

@ -22,7 +22,7 @@ PackageAdminStore.fetch = () => {
const loading = {};
PackageAdminStore.forEach(item => {
if (item && item.loading()) {
if (item?.loading()) {
loading[item.file] = item;
}
});

View file

@ -21,6 +21,6 @@ AppUserStore.focusedState.subscribe(value => {
ThemeStore.isMobile() && leftPanelDisabled('FolderList' !== value);
}
let dom = elementById('V-Mail'+name);
dom && dom.classList.toggle('focused', name === value);
dom?.classList.toggle('focused', name === value);
});
});

View file

@ -33,12 +33,12 @@ ContactUserStore.sync = fResultFunc => {
line = JSON.parse(line);
if ('ContactsSync' === line.Action) {
ContactUserStore.syncing(false);
fResultFunc && fResultFunc(line.ErrorCode, line);
fResultFunc?.(line.ErrorCode, line);
}
} catch (e) {
ContactUserStore.syncing(false);
console.error(e);
fResultFunc && fResultFunc(Notification.UnknownError);
fResultFunc?.(Notification.UnknownError);
}
}, 'ContactsSync');
}

View file

@ -80,15 +80,9 @@ export const FolderUserStore = new class {
const
subscribeRemoveSystemFolder = observable => {
observable.subscribe(() => {
const folder = getFolderFromCacheList(observable());
folder && folder.type(FolderType.User);
}, self, 'beforeChange');
observable.subscribe(() => getFolderFromCacheList(observable())?.type(FolderType.User), self, 'beforeChange');
},
fSetSystemFolderType = type => value => {
const folder = getFolderFromCacheList(value);
folder && folder.type(type);
};
fSetSystemFolderType = type => value => getFolderFromCacheList(value)?.type(type);
subscribeRemoveSystemFolder(self.sentFolder);
subscribeRemoveSystemFolder(self.draftsFolder);
@ -134,8 +128,7 @@ export const FolderUserStore = new class {
fSearchFunction = (list) => {
list.forEach(folder => {
if (
folder &&
folder.selectable() &&
folder?.selectable() &&
folder.exists &&
timeout > folder.expires &&
(folder.isSystemFolder() || (folder.isSubscribed() && (folder.checkable() || !bDisplaySpecSetting)))
@ -143,7 +136,7 @@ export const FolderUserStore = new class {
timeouts.push([folder.expires, folder.fullName]);
}
if (folder && folder.subFolders.length) {
if (folder?.subFolders.length) {
fSearchFunction(folder.subFolders());
}
});

View file

@ -38,7 +38,7 @@ export const GnuPGUserStore = new class {
this.privateKeys([]);
Remote.request('GnupgGetKeys',
(iError, oData) => {
if (oData && oData.Result) {
if (oData?.Result) {
this.keyring = oData.Result;
const initKey = (key, isPrivate) => {
const aEmails = [];
@ -73,7 +73,7 @@ export const GnuPGUserStore = new class {
key.view = () => {
const fetch = pass => Remote.request('GnupgExportKey',
(iError, oData) => {
if (oData && oData.Result) {
if (oData?.Result) {
key.armor = oData.Result;
showScreenPopup(OpenPgpKeyPopupView, [key]);
}
@ -111,10 +111,10 @@ export const GnuPGUserStore = new class {
importKey(key, callback) {
Remote.request('GnupgImportKey',
(iError, oData) => {
if (oData && oData.Result/* && (oData.Result.imported || oData.Result.secretimported)*/) {
if (oData?.Result/* && (oData.Result.imported || oData.Result.secretimported)*/) {
this.loadKeyrings();
}
callback && callback(iError, oData);
callback?.(iError, oData);
}, {
Key: key
}
@ -131,10 +131,10 @@ export const GnuPGUserStore = new class {
storeKeyPair(keyPair, callback) {
Remote.request('PgpStoreKeyPair',
(iError, oData) => {
if (oData && oData.Result) {
if (oData?.Result) {
// this.gnupgKeyring = oData.Result;
}
callback && callback(iError, oData);
callback?.(iError, oData);
}, keyPair
);
}
@ -187,7 +187,7 @@ export const GnuPGUserStore = new class {
}
if (null !== params.Passphrase) {
const result = await Remote.post('GnupgDecrypt', null, params);
if (result && result.Result) {
if (result?.Result) {
return result.Result;
}
}
@ -208,7 +208,7 @@ export const GnuPGUserStore = new class {
data.SigPart = data.SigPart.body;
}
let response = await Remote.post('MessagePgpVerify', null, data);
if (response && response.Result) {
if (response?.Result) {
return {
fingerprint: response.Result.fingerprint,
success: 0 == response.Result.status // GOODSIG

View file

@ -42,7 +42,7 @@ export const MessageUserStore = new class {
purgeMessageBodyCache() {
const messagesDom = this.bodiesDom(),
children = messagesDom && messagesDom.children;
children = messagesDom?.children;
if (children) {
while (15 < children.length) {
children[0].remove();

View file

@ -270,8 +270,7 @@ MessagelistUserStore.setAction = (sFolderFullName, iSetAction, messages) => {
let folder,
alreadyUnread = 0,
rootUids = messages.map(oMessage => oMessage && oMessage.uid ? oMessage.uid : null)
.validUnique(),
rootUids = messages.map(oMessage => oMessage?.uid).validUnique(),
length = rootUids.length;
if (sFolderFullName && length) {
@ -333,7 +332,7 @@ MessagelistUserStore.removeMessagesFromList = (
? messageList.filter(item => item && uidForRemove.includes(pInt(item.uid)))
: [];
messages.forEach(item => item && item.isUnseen() && ++unseenCount);
messages.forEach(item => item?.isUnseen() && ++unseenCount);
if (fromFolder) {
fromFolder.hash = '';
@ -387,7 +386,7 @@ MessagelistUserStore.removeMessagesFromList = (
if (MessagelistUserStore.threadUid()) {
if (
messageList.length &&
messageList.find(item => item && item.deleted() && item.uid == MessagelistUserStore.threadUid())
messageList.find(item => item?.deleted() && item.uid == MessagelistUserStore.threadUid())
) {
const message = messageList.find(item => item && !item.deleted());
let setHash;

View file

@ -6,7 +6,7 @@ import { fireEvent } from 'Common/Globals';
* Might not work due to the new ServiceWorkerRegistration.showNotification
*/
const HTML5Notification = window.Notification,
HTML5NotificationStatus = () => (HTML5Notification && HTML5Notification.permission) || 'denied',
HTML5NotificationStatus = () => HTML5Notification?.permission || 'denied',
NotificationsDenied = () => 'denied' === HTML5NotificationStatus(),
NotificationsGranted = () => 'granted' === HTML5NotificationStatus(),
dispatchMessage = data => {
@ -26,7 +26,7 @@ if (WorkerNotifications && ServiceWorkerRegistration && ServiceWorkerRegistratio
/* Listen for close requests from the ServiceWorker */
WorkerNotifications.addEventListener('message', event => {
const obj = JSON.parse(event.data);
obj && 'notificationclick' === obj.action && dispatchMessage(obj.data);
'notificationclick' === obj?.action && dispatchMessage(obj.data);
});
} else {
WorkerNotifications = null;
@ -60,7 +60,7 @@ export const NotificationUserStore = new class {
icon: imageSrc || Links.staticLink('css/images/icon-message-notification.png'),
data: messageData
};
if (messageData && messageData.Uid) {
if (messageData?.Uid) {
options.tag = messageData.Uid;
}
if (WorkerNotifications) {
@ -83,7 +83,7 @@ export const NotificationUserStore = new class {
.catch(e => console.error(e));
} else {
const notification = new HTML5Notification(title, options);
notification.show && notification.show();
notification.show?.();
notification.onclick = messageData ? () => dispatchMessage(messageData) : null;
setTimeout(() => notification.close(), 7000);
}

View file

@ -196,7 +196,7 @@ export const OpenPGPUserStore = new class {
const publicKey = findOpenPGPKey(this.publicKeys, sender/*, sign*/);
return await openpgp.decrypt({
message,
verificationKeys: publicKey && publicKey.key,
verificationKeys: publicKey?.key,
// expectSigned: true,
// signature: '', // Detached signature
decryptionKeys: decryptedKey

View file

@ -169,7 +169,7 @@ export const
}
);
if (result) {
if (result.error && result.error.message) {
if (result.error?.message) {
if ('PWD_DIALOG_CANCEL' !== result.error.code) {
alert(result.error.code + ': ' + result.error.message);
}