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.
This commit is contained in:
Michał Cieślak 2024-10-08 13:20:50 +02:00 committed by Michał
parent 17be3bfb2c
commit 9f9dcefcf8
12 changed files with 14 additions and 40 deletions

View File

@ -23,9 +23,6 @@ SplitView {
property bool ready: false property bool ready: false
property var globalUtils: QtObject { property var globalUtils: QtObject {
function plainText(htmlText) {
return htmlText.replace(/(?:<style[^]+?>[^]+?<\/style>|[\n]|<script[^]+?>[^]+?<\/script>|<(?:!|\/?[a-zA-Z]+).*?\/?>)/g,'')
}
function isCompressedPubKey(publicKey) { function isCompressedPubKey(publicKey) {
return false return false
} }
@ -104,7 +101,7 @@ SplitView {
onSendMessage: { onSendMessage: {
logs.logEvent("StatusChatInput::sendMessage", ["MessageWithPk"], [chatInput.getTextWithPublicKeys()]) 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]) logs.logEvent("StatusChatInput::sendMessage", ["RawText"], [chatInput.textInput.text])
} }
onEnableLinkPreviewForThisMessage: { onEnableLinkPreviewForThisMessage: {

View File

@ -695,10 +695,6 @@ Item {
QtObject { QtObject {
id: globalUtilsMock id: globalUtilsMock
function plainText(htmlText) {
return TextUtils.htmlToPlainText(htmlText)
}
function isCompressedPubKey(publicKey) { function isCompressedPubKey(publicKey) {
return false return false
} }

View File

@ -103,10 +103,6 @@ QtObject {
return "OPT" return "OPT"
} }
function plainText(htmlFragment) {
return SQUtils.StringUtils.plainText(htmlFragment)
}
function prepareTransactionsForAddress(address) { function prepareTransactionsForAddress(address) {
console.log("prepareTransactionsForAddress:", address) console.log("prepareTransactionsForAddress:", address)
} }

View File

@ -1,7 +1,7 @@
import QtQuick 2.13 import QtQuick 2.15
import utils 1.0
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Utils 0.1 as SQUtils
Item { Item {
id: suggestionsPanelRoot id: suggestionsPanelRoot
@ -95,7 +95,7 @@ Item {
return return
} }
return Utils.plainText(this.filter) return SQUtils.StringUtils.plainText(this.filter)
} }
function shouldShowAll(filter) { function shouldShowAll(filter) {

View File

@ -233,7 +233,7 @@ QtObject {
} }
function cleanMessageText(formattedMessage) { function cleanMessageText(formattedMessage) {
const text = globalUtilsInst.plainText(StatusQUtils.Emoji.deparse(formattedMessage)) const text = StatusQUtils.StringUtils.plainText(StatusQUtils.Emoji.deparse(formattedMessage))
return interpretMessage(text) return interpretMessage(text)
} }
@ -427,10 +427,6 @@ QtObject {
return globalUtilsInst.generateAlias(pk); return globalUtilsInst.generateAlias(pk);
} }
function plainText(text) {
return globalUtilsInst.plainText(text)
}
function removeCommunityChat(chatId) { function removeCommunityChat(chatId) {
chatCommunitySectionModule.removeCommunityChat(chatId) chatCommunitySectionModule.removeCommunityChat(chatId)
} }

View File

@ -193,10 +193,6 @@ QtObject {
communitiesModuleInst.cancelRequestToJoinCommunity(id) communitiesModuleInst.cancelRequestToJoinCommunity(id)
} }
function plainText(text) {
return globalUtils.plainText(text);
}
function generateAlias(pk) { function generateAlias(pk) {
return globalUtils.generateAlias(pk); return globalUtils.generateAlias(pk);
} }

View File

@ -455,7 +455,7 @@ Item {
function onOpenLink(link: string) { function onOpenLink(link: string) {
// Qt sometimes inserts random HTML tags; and this will break on invalid URL inside QDesktopServices::openUrl(link) // 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) Qt.openUrlExternally(link)
} }

View File

@ -111,8 +111,9 @@ Loader {
} }
function evaluateAndSetPreferredChains() { function evaluateAndSetPreferredChains() {
let address = !!root.item.input && !!root.store.plainText(root.item.input.text) ? root.store.plainText(root.item.input.text): "" const plainText = StatusQUtils.StringUtils.plainText(root.item.input.text)
let result = root.store.splitAndFormatAddressPrefix(address, !root.isBridgeTx && !root.isCollectiblesTransfer) const address = !!root.item.input && !!plainText ? plainText: ""
const result = root.store.splitAndFormatAddressPrefix(address, !root.isBridgeTx && !root.isCollectiblesTransfer)
if(!!result.address) { if(!!result.address) {
root.addressText = result.address root.addressText = result.address
if(!!root.item.input) { if(!!root.item.input) {
@ -193,7 +194,7 @@ Loader {
text: root.addressText text: root.addressText
function validateInput() { function validateInput() {
const plainText = store.plainText(text) const plainText = StatusQUtils.StringUtils.plainText(text)
root.isLoading() root.isLoading()
if (Utils.isValidEns(plainText)) { if (Utils.isValidEns(plainText)) {
d.isPending = true d.isPending = true

View File

@ -481,7 +481,7 @@ Rectangle {
validateImagesAndShowImageArea([clipboardImage]) validateImagesAndShowImageArea([clipboardImage])
event.accepted = true event.accepted = true
} else if (ClipboardUtils.hasText) { } 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 // prevent repetitive & huge clipboard paste, where huge is total char count > than messageLimitHard
const selectionLength = messageInputField.selectionEnd - messageInputField.selectionStart; const selectionLength = messageInputField.selectionEnd - messageInputField.selectionStart;
if ((messageLength + clipboardText.length - selectionLength) > control.messageLimitHard) if ((messageLength + clipboardText.length - selectionLength) > control.messageLimitHard)
@ -498,7 +498,7 @@ Rectangle {
d.copyTextStart = messageInputField.cursorPosition d.copyTextStart = messageInputField.cursorPosition
messageInputField.readOnly = true messageInputField.readOnly = true
const copiedText = Utils.plainText(d.copiedTextPlain) const copiedText = StatusQUtils.StringUtils.plainText(d.copiedTextPlain)
if (copiedText === clipboardText) { if (copiedText === clipboardText) {
if (d.copiedTextPlain.includes("@")) { if (d.copiedTextPlain.includes("@")) {
d.copiedTextFormatted = d.copiedTextFormatted.replace(/span style="/g, "span style=\" text-decoration:none;") d.copiedTextFormatted = d.copiedTextFormatted.replace(/span style="/g, "span style=\" text-decoration:none;")
@ -622,7 +622,7 @@ Rectangle {
const deparsedEmoji = StatusQUtils.Emoji.deparse(textWithoutMention); const deparsedEmoji = StatusQUtils.Emoji.deparse(textWithoutMention);
return Utils.plainText(deparsedEmoji) return StatusQUtils.StringUtils.plainText(deparsedEmoji)
} }
function removeMentions(currentText) { function removeMentions(currentText) {

View File

@ -80,10 +80,6 @@ QtObject {
return globalUtils.wei2Eth(wei, decimals) return globalUtils.wei2Eth(wei, decimals)
} }
function plainText(text) {
return globalUtils.plainText(text)
}
function getAsset(assetsList, symbol) { function getAsset(assetsList, symbol) {
for(var i=0; i< assetsList.rowCount();i++) { for(var i=0; i< assetsList.rowCount();i++) {
let asset = assetsList.get(i) let asset = assetsList.get(i)

View File

@ -660,7 +660,7 @@ Loader {
return return
} }
const message = root.rootStore.plainText(StatusQUtils.Emoji.deparse(newMessageText)) const message = StatusQUtils.StringUtils.plainText(StatusQUtils.Emoji.deparse(newMessageText))
if (message.length <= 0) if (message.length <= 0)
return; return;

View File

@ -942,10 +942,6 @@ QtObject {
return getElidedPk(compressedPk) return getElidedPk(compressedPk)
} }
function plainText(text) {
return globalUtilsInst.plainText(text)
}
function parseContactUrl(link) { function parseContactUrl(link) {
let index = link.lastIndexOf("/u/") let index = link.lastIndexOf("/u/")