From cdb79d11aad143c944b8eba2d7eadd50553e2e3d Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 8 Mar 2020 04:46:20 -0400 Subject: [PATCH] Use const instead of let when possible --- src/gui/Base/HBox.qml | 2 +- src/gui/Base/HMenu.qml | 2 +- src/gui/Base/HMxcImage.qml | 10 +++++----- src/gui/Base/HSelectableLabelContainer.qml | 6 +++--- src/gui/Dialogs/ExportKeys.qml | 2 +- src/gui/Dialogs/ImportKeys.qml | 4 ++-- src/gui/Dialogs/SendFilePicker.qml | 4 ++-- src/gui/MainPane/AccountRoomsList.qml | 4 ++-- src/gui/PageLoader.qml | 8 ++++---- src/gui/Pages/AccountSettings/Profile.qml | 2 +- src/gui/Pages/AddAccount/SignIn.qml | 2 +- src/gui/Pages/AddChat/CreateRoom.qml | 2 +- src/gui/Pages/AddChat/DirectChat.qml | 2 +- src/gui/Pages/AddChat/JoinRoom.qml | 2 +- src/gui/Pages/Chat/Composer.qml | 16 ++++++++-------- src/gui/Pages/Chat/Timeline/EventImage.qml | 4 ++-- src/gui/Pages/Chat/Timeline/EventList.qml | 10 +++++----- src/gui/Pages/Chat/Timeline/EventMediaLoader.qml | 6 +++--- src/gui/Popups/InviteToRoomPopup.qml | 2 +- src/gui/Popups/PasswordPopup.qml | 2 +- src/gui/PythonBridge/Privates/EventHandlers.qml | 4 ++-- src/gui/Utils.qml | 14 +++++++------- src/gui/Window.qml | 4 ++-- 23 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/gui/Base/HBox.qml b/src/gui/Base/HBox.qml index 888c59b4..402d542a 100644 --- a/src/gui/Base/HBox.qml +++ b/src/gui/Base/HBox.qml @@ -27,7 +27,7 @@ Rectangle { function enterClickButton() { for (let i = 0; i < buttonModel.length; i++) { - let btn = buttonRepeater.itemAt(i) + const btn = buttonRepeater.itemAt(i) if (btn.enabled && btn.name === clickButtonOnEnter) btn.clicked() } } diff --git a/src/gui/Base/HMenu.qml b/src/gui/Base/HMenu.qml index 1a816a08..7c8a819f 100644 --- a/src/gui/Base/HMenu.qml +++ b/src/gui/Base/HMenu.qml @@ -11,7 +11,7 @@ Menu { let result = 0 for (let i = 0; i < count; ++i) { - let item = itemAt(i) + const item = itemAt(i) if (! item.visible) continue result = Math.max(item.implicitWidth, result) diff --git a/src/gui/Base/HMxcImage.qml b/src/gui/Base/HMxcImage.qml index 355e6d63..84f4e7e9 100644 --- a/src/gui/Base/HMxcImage.qml +++ b/src/gui/Base/HMxcImage.qml @@ -25,8 +25,8 @@ HImage { function update() { if (! py) return // component was destroyed - let w = sourceSize.width || width - let h = sourceSize.height || height + const w = sourceSize.width || width + const h = sourceSize.height || height if (! image.mxc || w < 1 || h < 1 ) { show = false @@ -39,9 +39,9 @@ HImage { return } - let method = image.thumbnail ? "get_thumbnail" : "get_media" - let args = image.thumbnail ? - [image.mxc, w, h, cryptDict] : [image.mxc, cryptDict] + const method = image.thumbnail ? "get_thumbnail" : "get_media" + const args = image.thumbnail ? + [image.mxc, w, h, cryptDict] : [image.mxc, cryptDict] py.callCoro("media_cache." + method, args, path => { if (! image) return diff --git a/src/gui/Base/HSelectableLabelContainer.qml b/src/gui/Base/HSelectableLabelContainer.qml index 82e481d9..25e314a5 100644 --- a/src/gui/Base/HSelectableLabelContainer.qml +++ b/src/gui/Base/HSelectableLabelContainer.qml @@ -25,9 +25,9 @@ FocusScope { ] readonly property string joinedSelection: { - let toCopy = [] + const toCopy = [] - for (let key of Object.keys(selectedTexts).sort()) { + for (const key of Object.keys(selectedTexts).sort()) { if (! selectedTexts[key]) continue // For some dumb reason, Object.keys convert the floats to strings @@ -53,7 +53,7 @@ FocusScope { selecting = false } onDragPointChanged: { - let pos = mapFromItem( + const pos = mapFromItem( mainUI, eventPoint.scenePosition.x, eventPoint.scenePosition.y, ) draggedItem.x = pos.x diff --git a/src/gui/Dialogs/ExportKeys.qml b/src/gui/Dialogs/ExportKeys.qml index 04aa5bcd..cfe0d067 100644 --- a/src/gui/Dialogs/ExportKeys.qml +++ b/src/gui/Dialogs/ExportKeys.qml @@ -26,7 +26,7 @@ HFileDialogOpener { function exportKeys(file, passphrase) { exporting = true - let path = file.toString().replace(/^file:\/\//, "") + const path = file.toString().replace(/^file:\/\//, "") py.callClientCoro(userId, "export_keys", [path, passphrase], () => { exporting = false diff --git a/src/gui/Dialogs/ImportKeys.qml b/src/gui/Dialogs/ImportKeys.qml index 4abe9f8a..907a499d 100644 --- a/src/gui/Dialogs/ImportKeys.qml +++ b/src/gui/Dialogs/ImportKeys.qml @@ -29,8 +29,8 @@ HFileDialogOpener { function verifyPassword(pass, callback) { - importing = true - let path = file.toString().replace(/^file:\/\//, "") + importing = true + const path = file.toString().replace(/^file:\/\//, "") py.callClientCoro(userId, "import_keys", [path, pass], () => { importing = false diff --git a/src/gui/Dialogs/SendFilePicker.qml b/src/gui/Dialogs/SendFilePicker.qml index 957d6025..56a3987c 100644 --- a/src/gui/Dialogs/SendFilePicker.qml +++ b/src/gui/Dialogs/SendFilePicker.qml @@ -9,8 +9,8 @@ HFileDialogOpener { dialog.fileMode: FileDialog.OpenFiles onFilesPicked: { - for (let file of files) { - let path = Qt.resolvedUrl(file).replace(/^file:/, "") + for (const file of files) { + const path = Qt.resolvedUrl(file).replace(/^file:/, "") utils.sendFile(userId, roomId, path, () => { if (destroyWhenDone) destroy() diff --git a/src/gui/MainPane/AccountRoomsList.qml b/src/gui/MainPane/AccountRoomsList.qml index 13a1f6f4..f46aab11 100644 --- a/src/gui/MainPane/AccountRoomsList.qml +++ b/src/gui/MainPane/AccountRoomsList.qml @@ -73,14 +73,14 @@ HListView { } function _previous() { - let currentAccount = currentItem + const currentAccount = currentItem // Nothing is selected if (! currentAccount) { decrementCurrentIndex() } - let roomList = currentAccount.roomList + const roomList = currentAccount.roomList // An account is selected if (! roomList.currentItem) { diff --git a/src/gui/PageLoader.qml b/src/gui/PageLoader.qml index f4a911c2..e4a17f9a 100644 --- a/src/gui/PageLoader.qml +++ b/src/gui/PageLoader.qml @@ -20,8 +20,8 @@ HLoader { return } - let page = window.uiState.page - let props = window.uiState.pageProperties + const page = window.uiState.page + const props = window.uiState.pageProperties if (page === "Pages/Chat/Chat.qml") { pageLoader.showRoom(props.userId, props.roomId) @@ -46,7 +46,7 @@ HLoader { } function showPage(name, properties={}) { - let path = `Pages/${name}.qml` + const path = `Pages/${name}.qml` _show(path, properties) window.uiState.page = path @@ -66,7 +66,7 @@ HLoader { timesBack = Math.min(timesBack, history.length - 1) if (timesBack < 1) return false - let [componentUrl, properties] = history[timesBack] + const [componentUrl, properties] = history[timesBack] _show(componentUrl, properties) diff --git a/src/gui/Pages/AccountSettings/Profile.qml b/src/gui/Pages/AccountSettings/Profile.qml index ff4ab386..83b2e317 100644 --- a/src/gui/Pages/AccountSettings/Profile.qml +++ b/src/gui/Pages/AccountSettings/Profile.qml @@ -28,7 +28,7 @@ HGridLayout { if (avatar.changed) { saveButton.avatarChangeRunning = true - let path = + const path = Qt.resolvedUrl(avatar.sourceOverride).replace(/^file:/, "") py.callClientCoro(userId, "set_avatar_from_file", [path], () => { diff --git a/src/gui/Pages/AddAccount/SignIn.qml b/src/gui/Pages/AddAccount/SignIn.qml index 89ceca02..973784e3 100644 --- a/src/gui/Pages/AddAccount/SignIn.qml +++ b/src/gui/Pages/AddAccount/SignIn.qml @@ -30,7 +30,7 @@ HBox { errorMessage.text = "" - let args = [ + const args = [ idField.text.trim(), passwordField.text, undefined, serverField.text.trim(), ] diff --git a/src/gui/Pages/AddChat/CreateRoom.qml b/src/gui/Pages/AddChat/CreateRoom.qml index 86a2ae35..648b00ea 100644 --- a/src/gui/Pages/AddChat/CreateRoom.qml +++ b/src/gui/Pages/AddChat/CreateRoom.qml @@ -20,7 +20,7 @@ HBox { button.loading = true errorMessage.text = "" - let args = [ + const args = [ nameField.text, topicField.text, publicCheckBox.checked, diff --git a/src/gui/Pages/AddChat/DirectChat.qml b/src/gui/Pages/AddChat/DirectChat.qml index d5524f86..a196c249 100644 --- a/src/gui/Pages/AddChat/DirectChat.qml +++ b/src/gui/Pages/AddChat/DirectChat.qml @@ -25,7 +25,7 @@ HBox { button.loading = true errorMessage.text = "" - let args = [userField.text.trim(), encryptCheckBox.checked] + const args = [userField.text.trim(), encryptCheckBox.checked] py.callClientCoro(userId, "new_direct_chat", args, roomId => { button.loading = false diff --git a/src/gui/Pages/AddChat/JoinRoom.qml b/src/gui/Pages/AddChat/JoinRoom.qml index 8c838ea4..1f6e873b 100644 --- a/src/gui/Pages/AddChat/JoinRoom.qml +++ b/src/gui/Pages/AddChat/JoinRoom.qml @@ -25,7 +25,7 @@ HBox { button.loading = true errorMessage.text = "" - let args = [roomField.text.trim()] + const args = [roomField.text.trim()] py.callClientCoro(userId, "room_join", args, roomId => { button.loading = false diff --git a/src/gui/Pages/Chat/Composer.qml b/src/gui/Pages/Chat/Composer.qml index df9f8437..aacf0aef 100644 --- a/src/gui/Pages/Chat/Composer.qml +++ b/src/gui/Pages/Chat/Composer.qml @@ -101,7 +101,7 @@ Rectangle { let foundAlias = null - for (let [user, writing_alias] of Object.entries(aliases)) { + for (const [user, writing_alias] of Object.entries(aliases)) { if (text.startsWith(writing_alias + " ")) { writingUserId = user foundAlias = new RegExp("^" + writing_alias + " ") @@ -119,15 +119,15 @@ Rectangle { writingUserId = Qt.binding(() => chat.userId) toSend = text - let vals = Object.values(aliases) + const vals = Object.values(aliases) - let longestAlias = + const longestAlias = vals.reduce((a, b) => a.length > b.length ? a: b) - let textNotStartsWithAnyAlias = + const textNotStartsWithAnyAlias = ! vals.some(a => a.startsWith(text)) - let textContainsCharNotInAnyAlias = + const textContainsCharNotInAnyAlias = vals.every(a => text.split("").some(c => ! a.includes(c))) // Only set typing when it's sure that the user will not use @@ -162,21 +162,21 @@ Rectangle { ev.modifiers & Qt.AltModifier) { let indents = 0 - let parts = lineText.split(indent) + const parts = lineText.split(indent) for (const [i, part] of parts.entries()) { if (i === parts.length - 1 || part) { break } indents += 1 } - let add = indent.repeat(indents) + const add = indent.repeat(indents) textArea.insert(cursorPosition, "\n" + add) return } if (textArea.text === "") { return } - let args = [chat.roomId, toSend] + const args = [chat.roomId, toSend] py.callClientCoro(writingUserId, "send_text", args) area.clear() diff --git a/src/gui/Pages/Chat/Timeline/EventImage.qml b/src/gui/Pages/Chat/Timeline/EventImage.qml index 7caf16cd..001d49c8 100644 --- a/src/gui/Pages/Chat/Timeline/EventImage.qml +++ b/src/gui/Pages/Chat/Timeline/EventImage.qml @@ -71,8 +71,8 @@ HMxcImage { return } - let toOpen = loader.mediaUrl || loader.thumbnailMxc - let isMxc = toOpen.startsWith("mxc://") + const toOpen = loader.mediaUrl || loader.thumbnailMxc + const isMxc = toOpen.startsWith("mxc://") isMxc ? py.callClientCoro(chat.userId, "mxc_to_http", [toOpen], callback) : diff --git a/src/gui/Pages/Chat/Timeline/EventList.qml b/src/gui/Pages/Chat/Timeline/EventList.qml index 4e87fd2a..e0afa63f 100644 --- a/src/gui/Pages/Chat/Timeline/EventList.qml +++ b/src/gui/Pages/Chat/Timeline/EventList.qml @@ -20,11 +20,11 @@ Rectangle { target: null onActiveChanged: if (! active) dragFlicker.speed = 0 onCentroidChanged: { - let left = centroid.pressedButtons & Qt.LeftButton - let vel = centroid.velocity.y - let pos = centroid.position.y - let dist = Math.min(selectableLabelContainer.height / 4, 50) - let boost = 20 * (pos < dist ? -pos : -(height - pos)) + const left = centroid.pressedButtons & Qt.LeftButton + const vel = centroid.velocity.y + const pos = centroid.position.y + const dist = Math.min(selectableLabelContainer.height / 4, 50) + const boost = 20 * (pos < dist ? -pos : -(height - pos)) dragFlicker.speed = left && vel && pos < dist ? 1000 + boost : diff --git a/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml b/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml index 59aaec2b..14c83e23 100644 --- a/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml +++ b/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml @@ -47,19 +47,19 @@ HLoader { if (singleMediaInfo.event_type === "RoomAvatarEvent") return EventDelegate.Media.Image - let mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase() + const mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase() if (mainType === "image") return EventDelegate.Media.Image if (mainType === "video") return EventDelegate.Media.Video if (mainType === "audio") return EventDelegate.Media.Audio - let fileEvents = ["RoomMessageFile", "RoomEncryptedFile"] + const fileEvents = ["RoomMessageFile", "RoomEncryptedFile"] if (fileEvents.includes(singleMediaInfo.event_type)) return EventDelegate.Media.File // If this is a preview for a link in a normal message - let ext = utils.urlExtension(mediaUrl) + const ext = utils.urlExtension(mediaUrl) if (imageExtensions.includes(ext)) return EventDelegate.Media.Image if (videoExtensions.includes(ext)) return EventDelegate.Media.Video diff --git a/src/gui/Popups/InviteToRoomPopup.qml b/src/gui/Popups/InviteToRoomPopup.qml index 747f1c4a..fc45f7a2 100644 --- a/src/gui/Popups/InviteToRoomPopup.qml +++ b/src/gui/Popups/InviteToRoomPopup.qml @@ -87,7 +87,7 @@ BoxPopup { // TODO: handle these: real user not found const lines = [] - for (let [user, error] of failedInvites) { + for (const [user, error] of failedInvites) { const type = py.getattr( py.getattr(error, "__class__"), "__name__", ) diff --git a/src/gui/Popups/PasswordPopup.qml b/src/gui/Popups/PasswordPopup.qml index fd98bf2d..eb6ba818 100644 --- a/src/gui/Popups/PasswordPopup.qml +++ b/src/gui/Popups/PasswordPopup.qml @@ -35,7 +35,7 @@ BoxPopup { box.buttonCallbacks: ({ ok: button => { - let password = passwordField.text + const password = passwordField.text okClicked = true button.loading = true errorMessage.text = "" diff --git a/src/gui/PythonBridge/Privates/EventHandlers.qml b/src/gui/PythonBridge/Privates/EventHandlers.qml index 3bc041a1..98aa4b62 100644 --- a/src/gui/PythonBridge/Privates/EventHandlers.qml +++ b/src/gui/PythonBridge/Privates/EventHandlers.qml @@ -18,8 +18,8 @@ QtObject { function onCoroutineDone(uuid, result, error, traceback) { - let onSuccess = Globals.pendingCoroutines[uuid].onSuccess - let onError = Globals.pendingCoroutines[uuid].onError + const onSuccess = Globals.pendingCoroutines[uuid].onSuccess + const onError = Globals.pendingCoroutines[uuid].onError delete Globals.pendingCoroutines[uuid] diff --git a/src/gui/Utils.qml b/src/gui/Utils.qml index 274cf110..06c37e38 100644 --- a/src/gui/Utils.qml +++ b/src/gui/Utils.qml @@ -20,7 +20,7 @@ QtObject { console.error("Failed creating component: ", comp.errorString()) } else if (! ready && status === Component.Ready) { - let incu = comp.incubateObject( + const incu = comp.incubateObject( parent, properties, Qt.Asynchronous, ) @@ -165,7 +165,7 @@ QtObject { text = text.toLowerCase() } - for (let word of filter.split(" ")) { + for (const word of filter.split(" ")) { if (word && ! text.includes(word)) { return false } @@ -175,7 +175,7 @@ QtObject { function filterMatchesAny(filter, ...texts) { - for (let text of texts) { + for (const text of texts) { if (filterMatches(filter, text)) return true } return false @@ -184,11 +184,11 @@ QtObject { function fitSize(minWidth, minHeight, width, height, maxWidth, maxHeight) { if (width >= height) { - let new_width = Math.min(Math.max(width, minWidth), maxWidth) + const new_width = Math.min(Math.max(width, minWidth), maxWidth) return Qt.size(new_width, height / (width / new_width)) } - let new_height = Math.min(Math.max(height, minHeight), maxHeight) + const new_height = Math.min(Math.max(height, minHeight), maxHeight) return Qt.size(width / (height / new_height), new_height) } @@ -231,9 +231,9 @@ QtObject { function formatDuration(milliseconds) { - let totalSeconds = milliseconds / 1000 + const totalSeconds = milliseconds / 1000 - let hours = Math.floor(totalSeconds / 3600) + const hours = Math.floor(totalSeconds / 3600) let minutes = Math.floor((totalSeconds % 3600) / 60) let seconds = Math.floor(totalSeconds % 60) diff --git a/src/gui/Window.qml b/src/gui/Window.qml index e9eb2918..a07941f8 100644 --- a/src/gui/Window.qml +++ b/src/gui/Window.qml @@ -50,9 +50,9 @@ ApplicationWindow { if (! obj.saveName || ! obj.saveProperties || obj.saveProperties.length < 1) return - let propertyValues = {} + const propertyValues = {} - for (let prop of obj.saveProperties) { + for (const prop of obj.saveProperties) { propertyValues[prop] = obj[prop] }