Backend-dependent content removed from Constants, userProfile removed from Global

Closes: #16459
This commit is contained in:
Michał Cieślak 2024-10-16 09:56:23 +02:00 committed by Michał
parent 02993196e9
commit c22a15e8fa
12 changed files with 91 additions and 61 deletions

View File

@ -246,6 +246,13 @@ QtObject {
args.description, args.color, args.emoji, from)
}
function isDisplayNameDupeOfCommunityMember(displayName) {
if (displayName === "")
return false
return communitiesModuleInst.isDisplayNameDupeOfCommunityMember(displayName)
}
readonly property Connections connections: Connections {
target: communitiesModuleInst
function onImportingCommunityStateChanged(communityId, state, errorMsg) {

View File

@ -13,6 +13,7 @@ import shared.panels 1.0
import shared 1.0
import shared.popups 1.0
import shared.controls 1.0
import shared.validators 1.0
import utils 1.0
import "../popups"
@ -116,7 +117,7 @@ Item {
input.clearable: true
errorMessageCmp.wrapMode: Text.NoWrap
errorMessageCmp.horizontalAlignment: Text.AlignHCenter
validators: Constants.validators.displayName
validators: displayNameValidators.validators
onTextChanged: {
userImage.name = text;
}
@ -126,6 +127,10 @@ Item {
d.doAction()
}
}
DisplayNameValidators {
id: displayNameValidators
}
}
}

View File

@ -29,6 +29,7 @@ import StatusQ.Core.Utils 0.1 as SQUtils
import SortFilterProxyModel 0.2
import AppLayouts.stores 1.0 as AppLayoutsStores
import AppLayouts.Communities.stores 1.0 as CommunitiesStore
StatusSectionLayout {
id: root
@ -38,6 +39,7 @@ StatusSectionLayout {
property SharedStores.RootStore sharedRootStore
property ProfileSectionStore store
property AppLayoutsStores.RootStore globalStore
property CommunitiesStore.CommunitiesStore communitiesStore
required property var sendModalPopup
property var systemPalette
property var emojiPopup
@ -146,6 +148,8 @@ StatusSectionLayout {
profileStore: root.store.profileStore
contactsStore: root.store.contactsStore
communitiesStore: root.communitiesStore
sendToAccountEnabled: root.networkConnectionStore.sendBuyBridgeEnabled
sectionTitle: root.store.getNameForSubsection(Constants.settingsSubsection.profile)
contentWidth: d.contentWidth

View File

@ -33,7 +33,6 @@ Item {
label: qsTr("Display name")
placeholderText: qsTr("Display Name")
charLimit: Constants.keypair.nameLengthMax
validators: Constants.validators.displayName
input.tabNavItem: bioInput.input.edit
}

View File

@ -8,6 +8,7 @@ import shared 1.0
import shared.panels 1.0
import shared.popups 1.0
import shared.stores 1.0
import shared.validators 1.0
import shared.controls.chat 1.0
import "../popups"
@ -24,12 +25,14 @@ import StatusQ.Controls 0.1
import AppLayouts.Profile.helpers 1.0
import AppLayouts.Profile.panels 1.0
import AppLayouts.Wallet.stores 1.0
import AppLayouts.Communities.stores 1.0
SettingsContentBase {
id: root
property ProfileStore profileStore
property ContactsStore contactsStore
property CommunitiesStore communitiesStore
property bool sendToAccountEnabled: false
@ -294,8 +297,15 @@ SettingsContentBase {
displayName.input.edit.readOnly: isEnsName
displayName.text: profileStore.name
displayName.validationMode: StatusInput.ValidationMode.Always
displayName.validators: isEnsName ? [] : Constants.validators.displayName
displayName.validators: isEnsName ? [] : displayNameValidators.validators
bio.text: profileStore.bio
DisplayNameValidators {
id: displayNameValidators
myDisplayName: root.profileStore.name
communitiesStore: root.communitiesStore
}
}
}

View File

@ -1438,6 +1438,7 @@ Item {
sharedRootStore: appMain.sharedRootStore
store: appMain.rootStore.profileSectionStore
globalStore: appMain.rootStore
communitiesStore: appMain.communitiesStore
sendModalPopup: sendModal
systemPalette: appMain.sysPalette
emojiPopup: statusEmojiPopup.item

View File

@ -0,0 +1,60 @@
import QtQuick 2.15
import StatusQ.Controls.Validators 0.1
import AppLayouts.Communities.stores 1.0
import utils 1.0
QtObject {
id: root
/**
* communitiesStore and myDisplayName are optional. When provided
*/
property CommunitiesStore communitiesStore
property string myDisplayName
readonly property list<StatusValidator> validators: [
StatusValidator {
name: "startsWithSpaceValidator"
validate: t => !(t.startsWith(" ") || t.endsWith(" "))
errorMessage: qsTr("Display Names cant start or end with a space")
},
StatusRegularExpressionValidator {
regularExpression: /^$|^[a-zA-Z0-9\-_\u0020]+$/
errorMessage: qsTr("Invalid characters (use A-Z and 0-9, hyphens and underscores only)")
},
StatusMinLengthValidator {
minLength: Constants.keypair.nameLengthMin
errorMessage: qsTr("Display Names must be at least %n character(s) long",
"", Constants.keypair.nameLengthMin)
},
// TODO: Create `StatusMaxLengthValidator` in StatusQ
StatusValidator {
name: "maxLengthValidator"
validate: t => t.length <= Constants.keypair.nameLengthMax
errorMessage: qsTr("Display Names cant be longer than %n character(s)",
"", Constants.keypair.nameLengthMax)
},
StatusValidator {
name: "endsWith-ethValidator"
validate: t => !(t.endsWith("-eth") || t.endsWith("_eth") || t.endsWith(".eth"))
errorMessage: qsTr("Display Names cant end in “.eth”, “_eth” or “-eth”")
},
StatusValidator {
name: "isAliasValidator"
validate: function (t) { return !Utils.isAlias(t) }
errorMessage: qsTr("Adjective-animal Display Name formats are not allowed")
},
StatusValidator {
name: "isDuplicateInComunitiesValidator"
validate: displayName => {
if (!root.communitiesStore || displayName === root.myDisplayName)
return true
return !communitiesStore.isDisplayNameDupeOfCommunityMember(displayName)
}
errorMessage: qsTr("This Display Name is already in use in one of your joined communities")
}
]
}

View File

@ -0,0 +1 @@
DisplayNameValidators 1.0 DisplayNameValidators.qml

View File

@ -1,10 +1,8 @@
pragma Singleton
import QtQuick 2.13
import QtQml 2.15
import StatusQ.Components 0.1
import StatusQ.Controls.Validators 0.1
import StatusQ.Core.Theme 0.1
QtObject {
@ -555,43 +553,6 @@ QtObject {
errorMessage: qsTr("Key pair must be at least %n character(s)", "", keypair.nameLengthMin)
}
]
readonly property list<StatusValidator> displayName: [
StatusValidator {
name: "startsWithSpaceValidator"
validate: function (t) { return !(t.startsWith(" ") || t.endsWith(" "))}
errorMessage: qsTr("Display Names cant start or end with a space")
},
StatusRegularExpressionValidator {
regularExpression: /^$|^[a-zA-Z0-9\-_\u0020]+$/
errorMessage: qsTr("Invalid characters (use A-Z and 0-9, hyphens and underscores only)")
},
StatusMinLengthValidator {
minLength: keypair.nameLengthMin
errorMessage: qsTr("Display Names must be at least %n character(s) long", "", keypair.nameLengthMin)
},
// TODO: Create `StatusMaxLengthValidator` in StatusQ
StatusValidator {
name: "maxLengthValidator"
validate: function (t) { return t.length <= keypair.nameLengthMax }
errorMessage: qsTr("Display Names cant be longer than %n character(s)", "", keypair.nameLengthMax)
},
StatusValidator {
name: "endsWith-ethValidator"
validate: function (t) { return !(t.endsWith("-eth") || t.endsWith("_eth") || t.endsWith(".eth")) }
errorMessage: qsTr("Display Names cant end in “.eth”, “_eth” or “-eth”")
},
StatusValidator {
name: "isAliasValidator"
validate: function (t) { return !Utils.isAlias(t) }
errorMessage: qsTr("Adjective-animal Display Name formats are not allowed")
},
StatusValidator {
name: "isDuplicateInComunitiesValidator"
validate: function(t) { return !Utils.isDisplayNameDupeOfCommunityMember(t) }
errorMessage: qsTr("This Display Name is already in use in one of your joined communities")
}
]
}
readonly property QtObject settingsSection: QtObject {

View File

@ -9,7 +9,6 @@ QtObject {
property int settingsSubsection: Constants.settingsSubsection.profile
property int settingsSubSubsection: -1
property var userProfile
property bool appIsReady: false
// use the generic var as type to break the cyclic dependency

View File

@ -967,20 +967,4 @@ QtObject {
function addTimestampToURL(url) {
return globalUtilsInst.addTimestampToURL(url)
}
// Returns true if the provided displayName occurs in community members
function isDisplayNameDupeOfCommunityMember(displayName) {
if (!communitiesModuleInst)
return false
if (displayName === "")
return false
const myDisplayName = Global.userProfile ? Global.userProfile.name : ""
if (displayName === myDisplayName)
return false
return communitiesModuleInst.isDisplayNameDupeOfCommunityMember(displayName)
}
}

View File

@ -190,7 +190,6 @@ StatusWindow {
if (!appLoadingAnimation.runningProgressAnimation) {
mainModule.fakeLoadingScreenFinished()
}
Global.userProfile = userProfile
Global.appIsReady = true
loader.sourceComponent = app