From 9f9dcefcf8ebe0ab185387b13866e4b4a798bc13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Tue, 8 Oct 2024 13:20:50 +0200 Subject: [PATCH] chore: using StringUtils.plainText consistently There were two version of plainText - one exposed from the backend, another, backend-independent in StringUtils. The latter one is now used in all cases. --- storybook/pages/StatusChatInputPage.qml | 5 +---- storybook/qmlTests/tests/tst_StatusChatInput.qml | 4 ---- storybook/stubs/shared/stores/send/TransactionStore.qml | 4 ---- ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml | 6 +++--- ui/app/AppLayouts/Chat/stores/RootStore.qml | 6 +----- ui/app/AppLayouts/stores/RootStore.qml | 4 ---- ui/app/mainui/AppMain.qml | 2 +- ui/imports/shared/popups/send/views/RecipientView.qml | 7 ++++--- ui/imports/shared/status/StatusChatInput.qml | 6 +++--- ui/imports/shared/stores/send/TransactionStore.qml | 4 ---- ui/imports/shared/views/chat/MessageView.qml | 2 +- ui/imports/utils/Utils.qml | 4 ---- 12 files changed, 14 insertions(+), 40 deletions(-) diff --git a/storybook/pages/StatusChatInputPage.qml b/storybook/pages/StatusChatInputPage.qml index 51d04c2342..d4fadb6c2e 100644 --- a/storybook/pages/StatusChatInputPage.qml +++ b/storybook/pages/StatusChatInputPage.qml @@ -23,9 +23,6 @@ SplitView { property bool ready: false property var globalUtils: QtObject { - function plainText(htmlText) { - return htmlText.replace(/(?:[^]+?<\/style>|[\n]|[^]+?<\/script>|<(?:!|\/?[a-zA-Z]+).*?\/?>)/g,'') - } function isCompressedPubKey(publicKey) { return false } @@ -104,7 +101,7 @@ SplitView { onSendMessage: { logs.logEvent("StatusChatInput::sendMessage", ["MessageWithPk"], [chatInput.getTextWithPublicKeys()]) - logs.logEvent("StatusChatInput::sendMessage", ["PlainText"], [globalUtilsMock.globalUtils.plainText(chatInput.getTextWithPublicKeys())]) + logs.logEvent("StatusChatInput::sendMessage", ["PlainText"], [SQUtils.StringUtils.plainText(chatInput.getTextWithPublicKeys())]) logs.logEvent("StatusChatInput::sendMessage", ["RawText"], [chatInput.textInput.text]) } onEnableLinkPreviewForThisMessage: { diff --git a/storybook/qmlTests/tests/tst_StatusChatInput.qml b/storybook/qmlTests/tests/tst_StatusChatInput.qml index 707dc96314..a11436064b 100644 --- a/storybook/qmlTests/tests/tst_StatusChatInput.qml +++ b/storybook/qmlTests/tests/tst_StatusChatInput.qml @@ -695,10 +695,6 @@ Item { QtObject { id: globalUtilsMock - function plainText(htmlText) { - return TextUtils.htmlToPlainText(htmlText) - } - function isCompressedPubKey(publicKey) { return false } diff --git a/storybook/stubs/shared/stores/send/TransactionStore.qml b/storybook/stubs/shared/stores/send/TransactionStore.qml index fdc1fa8c08..9458bcf1d1 100644 --- a/storybook/stubs/shared/stores/send/TransactionStore.qml +++ b/storybook/stubs/shared/stores/send/TransactionStore.qml @@ -103,10 +103,6 @@ QtObject { return "OPT" } - function plainText(htmlFragment) { - return SQUtils.StringUtils.plainText(htmlFragment) - } - function prepareTransactionsForAddress(address) { console.log("prepareTransactionsForAddress:", address) } diff --git a/ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml b/ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml index fbb5be1f47..169c3a7f70 100644 --- a/ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml @@ -1,7 +1,7 @@ -import QtQuick 2.13 -import utils 1.0 +import QtQuick 2.15 import StatusQ.Core 0.1 +import StatusQ.Core.Utils 0.1 as SQUtils Item { id: suggestionsPanelRoot @@ -95,7 +95,7 @@ Item { return } - return Utils.plainText(this.filter) + return SQUtils.StringUtils.plainText(this.filter) } function shouldShowAll(filter) { diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index ddfcf37b7c..f9beb8b199 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -233,7 +233,7 @@ QtObject { } function cleanMessageText(formattedMessage) { - const text = globalUtilsInst.plainText(StatusQUtils.Emoji.deparse(formattedMessage)) + const text = StatusQUtils.StringUtils.plainText(StatusQUtils.Emoji.deparse(formattedMessage)) return interpretMessage(text) } @@ -427,10 +427,6 @@ QtObject { return globalUtilsInst.generateAlias(pk); } - function plainText(text) { - return globalUtilsInst.plainText(text) - } - function removeCommunityChat(chatId) { chatCommunitySectionModule.removeCommunityChat(chatId) } diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index b86ebbeb98..d7bca1da89 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -193,10 +193,6 @@ QtObject { communitiesModuleInst.cancelRequestToJoinCommunity(id) } - function plainText(text) { - return globalUtils.plainText(text); - } - function generateAlias(pk) { return globalUtils.generateAlias(pk); } diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index f5e50392ec..87d98e0e2f 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -455,7 +455,7 @@ Item { function onOpenLink(link: string) { // Qt sometimes inserts random HTML tags; and this will break on invalid URL inside QDesktopServices::openUrl(link) - link = appMain.rootStore.plainText(link) + link = SQUtils.StringUtils.plainText(link) Qt.openUrlExternally(link) } diff --git a/ui/imports/shared/popups/send/views/RecipientView.qml b/ui/imports/shared/popups/send/views/RecipientView.qml index c34219c887..58fd68c6ae 100644 --- a/ui/imports/shared/popups/send/views/RecipientView.qml +++ b/ui/imports/shared/popups/send/views/RecipientView.qml @@ -111,8 +111,9 @@ Loader { } function evaluateAndSetPreferredChains() { - let address = !!root.item.input && !!root.store.plainText(root.item.input.text) ? root.store.plainText(root.item.input.text): "" - let result = root.store.splitAndFormatAddressPrefix(address, !root.isBridgeTx && !root.isCollectiblesTransfer) + const plainText = StatusQUtils.StringUtils.plainText(root.item.input.text) + const address = !!root.item.input && !!plainText ? plainText: "" + const result = root.store.splitAndFormatAddressPrefix(address, !root.isBridgeTx && !root.isCollectiblesTransfer) if(!!result.address) { root.addressText = result.address if(!!root.item.input) { @@ -193,7 +194,7 @@ Loader { text: root.addressText function validateInput() { - const plainText = store.plainText(text) + const plainText = StatusQUtils.StringUtils.plainText(text) root.isLoading() if (Utils.isValidEns(plainText)) { d.isPending = true diff --git a/ui/imports/shared/status/StatusChatInput.qml b/ui/imports/shared/status/StatusChatInput.qml index cc447d9701..d6ff2f7158 100644 --- a/ui/imports/shared/status/StatusChatInput.qml +++ b/ui/imports/shared/status/StatusChatInput.qml @@ -481,7 +481,7 @@ Rectangle { validateImagesAndShowImageArea([clipboardImage]) event.accepted = true } else if (ClipboardUtils.hasText) { - const clipboardText = Utils.plainText(ClipboardUtils.text) + const clipboardText = StatusQUtils.StringUtils.plainText(ClipboardUtils.text) // prevent repetitive & huge clipboard paste, where huge is total char count > than messageLimitHard const selectionLength = messageInputField.selectionEnd - messageInputField.selectionStart; if ((messageLength + clipboardText.length - selectionLength) > control.messageLimitHard) @@ -498,7 +498,7 @@ Rectangle { d.copyTextStart = messageInputField.cursorPosition messageInputField.readOnly = true - const copiedText = Utils.plainText(d.copiedTextPlain) + const copiedText = StatusQUtils.StringUtils.plainText(d.copiedTextPlain) if (copiedText === clipboardText) { if (d.copiedTextPlain.includes("@")) { d.copiedTextFormatted = d.copiedTextFormatted.replace(/span style="/g, "span style=\" text-decoration:none;") @@ -622,7 +622,7 @@ Rectangle { const deparsedEmoji = StatusQUtils.Emoji.deparse(textWithoutMention); - return Utils.plainText(deparsedEmoji) + return StatusQUtils.StringUtils.plainText(deparsedEmoji) } function removeMentions(currentText) { diff --git a/ui/imports/shared/stores/send/TransactionStore.qml b/ui/imports/shared/stores/send/TransactionStore.qml index 04a6fa3646..387af2a7b2 100644 --- a/ui/imports/shared/stores/send/TransactionStore.qml +++ b/ui/imports/shared/stores/send/TransactionStore.qml @@ -80,10 +80,6 @@ QtObject { return globalUtils.wei2Eth(wei, decimals) } - function plainText(text) { - return globalUtils.plainText(text) - } - function getAsset(assetsList, symbol) { for(var i=0; i< assetsList.rowCount();i++) { let asset = assetsList.get(i) diff --git a/ui/imports/shared/views/chat/MessageView.qml b/ui/imports/shared/views/chat/MessageView.qml index 81d6d9fe2b..50a5228fed 100644 --- a/ui/imports/shared/views/chat/MessageView.qml +++ b/ui/imports/shared/views/chat/MessageView.qml @@ -660,7 +660,7 @@ Loader { return } - const message = root.rootStore.plainText(StatusQUtils.Emoji.deparse(newMessageText)) + const message = StatusQUtils.StringUtils.plainText(StatusQUtils.Emoji.deparse(newMessageText)) if (message.length <= 0) return; diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index 5f80f48866..76ac4a39dd 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -942,10 +942,6 @@ QtObject { return getElidedPk(compressedPk) } - function plainText(text) { - return globalUtilsInst.plainText(text) - } - function parseContactUrl(link) { let index = link.lastIndexOf("/u/")