From 8d52b0afdfa8a8993d846bb4acaeca8404516edd Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 20 Feb 2023 15:59:37 +0100 Subject: [PATCH] Bugfix: Notification enum conflicts with window.Notification --- dev/Common/Enums.js | 2 +- dev/Common/Translator.js | 6 +++--- dev/Common/UtilsUser.js | 4 ++-- dev/Remote/AbstractFetch.js | 24 ++++++++++++------------ dev/Settings/Admin/Packages.js | 6 +++--- dev/Settings/User/Folders.js | 10 +++++----- dev/Sieve/Utils.js | 4 ++-- dev/Stores/User/Contact.js | 3 ++- dev/Stores/User/Messagelist.js | 6 +++--- dev/View/Popup/Compose.js | 12 ++++++------ dev/View/Popup/FolderCreate.js | 4 ++-- dev/View/User/Login.js | 8 ++++---- dev/bootstrap.js | 4 ++-- 13 files changed, 47 insertions(+), 46 deletions(-) diff --git a/dev/Common/Enums.js b/dev/Common/Enums.js index 4726fafb4..804d10b78 100644 --- a/dev/Common/Enums.js +++ b/dev/Common/Enums.js @@ -39,7 +39,7 @@ SaveSettingStatus = { /** * @enum {number} */ -Notification = { +Notifications = { RequestError: 1, RequestAborted: 2, RequestTimeout: 3, diff --git a/dev/Common/Translator.js b/dev/Common/Translator.js index 2ab180fcb..3eb638546 100644 --- a/dev/Common/Translator.js +++ b/dev/Common/Translator.js @@ -1,5 +1,5 @@ import ko from 'ko'; -import { Notification, UploadErrorCode } from 'Common/Enums'; +import { Notifications, UploadErrorCode } from 'Common/Enums'; import { langLink } from 'Common/Links'; import { doc, createElement } from 'Common/Globals'; import { getKeyByValue, forEachObjectEntry } from 'Common/Utils'; @@ -20,7 +20,7 @@ const i18nKey = key => key.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase(), getNotificationMessage = code => { - let key = getKeyByValue(Notification, code); + let key = getKeyByValue(Notifications, code); return key ? I18N_DATA.NOTIFICATIONS[i18nKey(key).replace('_NOTIFICATION', '_ERROR')] : ''; }, @@ -176,7 +176,7 @@ export const */ getNotification = (code, message = '', defCode = 0) => { code = pInt(code); - if (Notification.ClientViewError === code && message) { + if (Notifications.ClientViewError === code && message) { return message; } diff --git a/dev/Common/UtilsUser.js b/dev/Common/UtilsUser.js index a4187aefd..ad7bba859 100644 --- a/dev/Common/UtilsUser.js +++ b/dev/Common/UtilsUser.js @@ -1,5 +1,5 @@ import { MessageFlagsCache } from 'Common/Cache'; -import { Notification } from 'Common/Enums'; +import { Notifications } from 'Common/Enums'; import { MessageSetAction, ComposeType/*, FolderType*/ } from 'Common/EnumsUser'; import { doc, createElement, elementById, dropdowns, dropdownVisibility, SettingsGet, leftPanelDisabled } from 'Common/Globals'; import { plainToHtml } from 'Common/Html'; @@ -293,7 +293,7 @@ populateMessageBody = (oMessage, popup) => { popup || MessageUserStore.loading(true); Remote.message((iError, oData/*, bCached*/) => { if (iError) { - if (Notification.RequestAborted !== iError && !popup) { + if (Notifications.RequestAborted !== iError && !popup) { MessageUserStore.message(null); MessageUserStore.error(getNotification(iError)); } diff --git a/dev/Remote/AbstractFetch.js b/dev/Remote/AbstractFetch.js index 546fc26f9..03728a734 100644 --- a/dev/Remote/AbstractFetch.js +++ b/dev/Remote/AbstractFetch.js @@ -1,4 +1,4 @@ -import { Notification } from 'Common/Enums'; +import { Notifications } from 'Common/Enums'; import { isArray, pInt, pString } from 'Common/Utils'; import { serverRequest } from 'Common/Links'; import { getNotification } from 'Common/Translator'; @@ -9,18 +9,18 @@ const getURL = (add = '') => serverRequest('Json') + pString(add), checkResponseError = data => { const err = data ? data.ErrorCode : null; - if (Notification.InvalidToken === err) { + if (Notifications.InvalidToken === err) { console.error(getNotification(err)); // alert(getNotification(err)); rl.logoutReload(); } else if ([ - Notification.AuthError, - Notification.ConnectionError, - Notification.DomainNotAllowed, - Notification.AccountNotAllowed, - Notification.MailServerError, - Notification.UnknownNotification, - Notification.UnknownError + Notifications.AuthError, + Notifications.ConnectionError, + Notifications.DomainNotAllowed, + Notifications.AccountNotAllowed, + Notifications.MailServerError, + Notifications.UnknownNotification, + Notifications.UnknownError ].includes(err) ) { if (7 < ++iJsonErrorCount) { @@ -65,7 +65,7 @@ class FetchError extends Error { constructor(code, message) { super(message); - this.code = code || Notification.JsonFalse; + this.code = code || Notifications.JsonFalse; } } @@ -145,7 +145,7 @@ export class AbstractFetchRemote iJsonErrorCount = 0; } else { checkResponseError(data); - iError = data.ErrorCode || Notification.UnknownError + iError = data.ErrorCode || Notifications.UnknownError } } @@ -197,7 +197,7 @@ export class AbstractFetchRemote abort(action, 0, 1); if (!data) { - return Promise.reject(new FetchError(Notification.JsonParse)); + return Promise.reject(new FetchError(Notifications.JsonParse)); } /* let isCached = false, type = ''; diff --git a/dev/Settings/Admin/Packages.js b/dev/Settings/Admin/Packages.js index 3a0925880..ef8b6ffa4 100644 --- a/dev/Settings/Admin/Packages.js +++ b/dev/Settings/Admin/Packages.js @@ -1,6 +1,6 @@ import ko from 'ko'; -import { Notification } from 'Common/Enums'; +import { Notifications } from 'Common/Enums'; import { getNotification } from 'Common/Translator'; import { PackageAdminStore } from 'Stores/Admin/Package'; @@ -67,7 +67,7 @@ export class AdminSettingsPackages extends AbstractViewSettings { if (iError) { this.packagesError( - getNotification(install ? Notification.CantInstallPackage : Notification.CantDeletePackage) + getNotification(install ? Notifications.CantInstallPackage : Notifications.CantDeletePackage) + (data.ErrorMessage ? ':\n' + data.ErrorMessage : '') ); } else if (data.Result.Reload) { @@ -113,7 +113,7 @@ export class AdminSettingsPackages extends AbstractViewSettings { if (iError) { plugin.enabled(disable); this.packagesError( - (Notification.UnsupportedPluginPackage === iError && data?.ErrorMessage) + (Notifications.UnsupportedPluginPackage === iError && data?.ErrorMessage) ? data.ErrorMessage : getNotification(iError) ); diff --git a/dev/Settings/User/Folders.js b/dev/Settings/User/Folders.js index b16443d73..f00c891a1 100644 --- a/dev/Settings/User/Folders.js +++ b/dev/Settings/User/Folders.js @@ -1,6 +1,6 @@ import ko from 'ko'; -import { Notification } from 'Common/Enums'; +import { Notifications } from 'Common/Enums'; import { FolderMetadataKeys } from 'Common/EnumsUser'; import { getNotification } from 'Common/Translator'; @@ -84,7 +84,7 @@ export class UserSettingsFolders /*extends AbstractViewSettings*/ { }) .catch(error => { FolderUserStore.folderListError( - getNotification(error.code, '', Notification.CantRenameFolder) + getNotification(error.code, '', Notifications.CantRenameFolder) + '.\n' + error.message); }); } @@ -119,8 +119,8 @@ export class UserSettingsFolders /*extends AbstractViewSettings*/ { && folderToRemove.askDelete() ) { if (0 < folderToRemove.totalEmails()) { -// FolderUserStore.folderListError(getNotification(Notification.CantDeleteNonEmptyFolder)); - folderToRemove.errorMsg(getNotification(Notification.CantDeleteNonEmptyFolder)); +// FolderUserStore.folderListError(getNotification(Notifications.CantDeleteNonEmptyFolder)); + folderToRemove.errorMsg(getNotification(Notifications.CantDeleteNonEmptyFolder)); } else { folderForDeletion(null); @@ -141,7 +141,7 @@ export class UserSettingsFolders /*extends AbstractViewSettings*/ { }, error => { FolderUserStore.folderListError( - getNotification(error.code, '', Notification.CantDeleteFolder) + getNotification(error.code, '', Notifications.CantDeleteFolder) + '.\n' + error.message ); } diff --git a/dev/Sieve/Utils.js b/dev/Sieve/Utils.js index 7544db465..14c58101a 100644 --- a/dev/Sieve/Utils.js +++ b/dev/Sieve/Utils.js @@ -25,13 +25,13 @@ export const arr.map(item => item.toString?.() || item).join(separator), /* getNotificationMessage = code => { - let key = getKeyByValue(Notification, code); + let key = getKeyByValue(Notifications, code); return key ? I18N_DATA.NOTIFICATIONS[i18nKey(key).replace('_NOTIFICATION', '_ERROR')] : ''; rl.i18n('NOTIFICATIONS/') }, getNotification = (code, message = '', defCode = 0) => { code = parseInt(code, 10) || 0; - if (Notification.ClientViewError === code && message) { + if (Notifications.ClientViewError === code && message) { return message; } diff --git a/dev/Stores/User/Contact.js b/dev/Stores/User/Contact.js index 863759787..89f1b01dd 100644 --- a/dev/Stores/User/Contact.js +++ b/dev/Stores/User/Contact.js @@ -2,6 +2,7 @@ import ko from 'ko'; import { SettingsGet } from 'Common/Globals'; import { koComputable, addObservablesTo, koArrayWithDestroy } from 'External/ko'; import Remote from 'Remote/User/Fetch'; +import { Notifications } from 'Common/Enums'; export const ContactUserStore = koArrayWithDestroy(); @@ -43,7 +44,7 @@ ContactUserStore.sync = fResultFunc => { } catch (e) { ContactUserStore.syncing(false); console.error(e); - fResultFunc?.(Notification.UnknownError); + fResultFunc?.(Notifications.UnknownError); } }, 'ContactsSync'); } diff --git a/dev/Stores/User/Messagelist.js b/dev/Stores/User/Messagelist.js index 1e7739bc1..c6535897c 100644 --- a/dev/Stores/User/Messagelist.js +++ b/dev/Stores/User/Messagelist.js @@ -1,7 +1,7 @@ import { koComputable, addObservablesTo, addComputablesTo } from 'External/ko'; import { SMAudio } from 'Common/Audio'; -import { Notification } from 'Common/Enums'; +import { Notifications } from 'Common/Enums'; import { MessageSetAction } from 'Common/EnumsUser'; import { $htmlCL } from 'Common/Globals'; import { arrayLength, pInt, pString } from 'Common/Utils'; @@ -198,7 +198,7 @@ MessagelistUserStore.reload = (bDropPagePosition = false, bDropCurrentFolderCach let error = ''; if (iError) { error = getNotification(iError); - if (Notification.RequestAborted !== iError) { + if (Notifications.RequestAborted !== iError) { MessagelistUserStore([]); } } else { @@ -281,7 +281,7 @@ MessagelistUserStore.reload = (bDropPagePosition = false, bDropCurrentFolderCach } else { MessagelistUserStore.count(0); MessagelistUserStore([]); - error = getNotification(Notification.CantGetMessageList); + error = getNotification(Notifications.CantGetMessageList); } MessagelistUserStore.error(error); } diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index b3df92418..a8a8d56d3 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -1,7 +1,7 @@ import ko from 'ko'; import { - Notification, + Notifications, UploadErrorCode } from 'Common/Enums'; @@ -458,13 +458,13 @@ export class ComposePopupView extends AbstractViewPopup { (iError, data) => { this.sending(false); if (iError) { - if (Notification.CantSaveMessage === iError) { + if (Notifications.CantSaveMessage === iError) { this.sendSuccessButSaveError(true); this.savedErrorDesc(i18n('COMPOSE/SAVED_ERROR_ON_SEND').trim()); } else { this.sendError(true); this.sendErrorDesc(getNotification(iError, data?.ErrorMessage) - || getNotification(Notification.CantSendMessage)); + || getNotification(Notifications.CantSendMessage)); } } else { this.close(); @@ -531,7 +531,7 @@ export class ComposePopupView extends AbstractViewPopup { if (!result) { this.savedError(true); - this.savedErrorDesc(getNotification(Notification.CantSaveMessage)); + this.savedErrorDesc(getNotification(Notifications.CantSaveMessage)); } reloadDraftFolder(); @@ -542,7 +542,7 @@ export class ComposePopupView extends AbstractViewPopup { }).catch(e => { this.saving(false); this.savedError(true); - this.savedErrorDesc(getNotification(Notification.CantSaveMessage) + ': ' + e); + this.savedErrorDesc(getNotification(Notifications.CantSaveMessage) + ': ' + e); }); } } @@ -612,7 +612,7 @@ export class ComposePopupView extends AbstractViewPopup { data.Result.map(item => (item?.[0] ? (new EmailModel(item[0], item[1])).toLine() : null)) .filter(v => v) ); - } else if (Notification.RequestAborted !== iError) { + } else if (Notifications.RequestAborted !== iError) { fResponse([]); } }, diff --git a/dev/View/Popup/FolderCreate.js b/dev/View/Popup/FolderCreate.js index 9087a8690..341294329 100644 --- a/dev/View/Popup/FolderCreate.js +++ b/dev/View/Popup/FolderCreate.js @@ -1,6 +1,6 @@ import { koComputable, addObservablesTo } from 'External/ko'; -import { Notification } from 'Common/Enums'; +import { Notifications } from 'Common/Enums'; import { defaultOptionsAfterRender } from 'Common/Utils'; import { folderListOptionsBuilder, sortFolders } from 'Common/Folders'; import { getNotification } from 'Common/Translator'; @@ -65,7 +65,7 @@ export class FolderCreatePopupView extends AbstractViewPopup { }, error => { FolderUserStore.folderListError( - getNotification(error.code, '', Notification.CantCreateFolder) + getNotification(error.code, '', Notifications.CantCreateFolder) + '.\n' + error.message); } ); diff --git a/dev/View/User/Login.js b/dev/View/User/Login.js index 017a98534..02043f385 100644 --- a/dev/View/User/Login.js +++ b/dev/View/User/Login.js @@ -1,4 +1,4 @@ -import { Notification } from 'Common/Enums'; +import { Notifications } from 'Common/Enums'; import { ClientSideKeyNameLastSignMe } from 'Common/EnumsUser'; import { SettingsGet, fireEvent } from 'Common/Globals'; import { getNotification, translatorReload, convertLangName } from 'Common/Translator'; @@ -120,11 +120,11 @@ export class LoginUserView extends AbstractViewLogin { }); if (iError) { this.submitRequest(false); - if (Notification.InvalidInputArgument == iError) { - iError = Notification.AuthError; + if (Notifications.InvalidInputArgument == iError) { + iError = Notifications.AuthError; } this.submitError(getNotification(iError, oData?.ErrorMessage, - Notification.UnknownNotification)); + Notifications.UnknownNotification)); this.submitErrorAdditional(oData?.ErrorMessageAdditional); } else { rl.setData(oData.Result); diff --git a/dev/bootstrap.js b/dev/bootstrap.js index 3c83a9f4e..21a3497a6 100644 --- a/dev/bootstrap.js +++ b/dev/bootstrap.js @@ -90,10 +90,10 @@ export default App => { } catch (e) { console.error(e); // console.log(data); - return Promise.reject(Notification.JsonParse); + return Promise.reject(Notifications.JsonParse); return { Result: false, - ErrorCode: 952, // Notification.JsonParse + ErrorCode: 952, // Notifications.JsonParse ErrorMessage: e.message, ErrorMessageAdditional: data }