This commit is contained in:
Evgeny @ SimpleX Chat
2026-06-30 18:38:38 +00:00
parent c991130f03
commit 633a95dbe6
7 changed files with 32 additions and 11 deletions
+9
View File
@@ -1366,6 +1366,15 @@ func apiSetProfileAddress(on: Bool) async throws -> User? {
}
// name is the encoded SimplexName (e.g. "@alice.simplex"); nil clears it
func setSimplexNameError(_ error: Error, isChannel: Bool) -> String {
if let e = error as? ChatError, case let .error(.simplexName(name, .noValidLink)) = e {
return isChannel
? "The SimpleX name \(name.shortName) is registered without channel link. Add channel link to the name via the registration page."
: "The SimpleX name \(name.shortName) is registered without SimpleX address. Add your SimpleX address to the name via the registration page."
}
return responseError(error)
}
func apiSetUserName(_ name: String?) async throws -> User {
let userId = try currentUserId("apiSetUserName")
let r: ChatResponse1 = try await chatSendCmd(.apiSetUserName(userId: userId, name: name))
@@ -265,7 +265,7 @@ struct GroupChatInfoView: View {
}
return nil
} catch {
return responseError(error)
return setSimplexNameError(error, isChannel: true)
}
}
)
@@ -204,7 +204,7 @@ struct UserAddressView: View {
await MainActor.run { chatModel.updateUser(u) }
return nil
} catch {
return responseError(error)
return setSimplexNameError(error, isChannel: false)
}
}
)
@@ -757,7 +757,7 @@ struct SetSimplexNameView: View {
}
.navigationTitle(titleKey)
.alert(isPresented: $showAlert) {
Alert(title: Text("Error saving SimpleX name"), message: Text(alertMessage))
Alert(title: Text("Error saving name"), message: Text(alertMessage))
}
}
@@ -1629,6 +1629,13 @@ object ChatController {
}
}
fun setSimplexNameErrorText(err: ChatError, isChannel: Boolean): String =
if (err is ChatError.ChatErrorChat && err.errorType is ChatErrorType.SimplexName && err.errorType.simplexNameError is SimplexNameError.NoValidLink) {
val name = err.errorType.simplexName.shortName
if (isChannel) generalGetString(MR.strings.simplex_name_owner_no_channel_link).format(name)
else generalGetString(MR.strings.simplex_name_owner_no_address).format(name)
} else err.string
fun connErrorText(e: ChatError): String = when {
e is ChatError.ChatErrorChat && e.errorType is ChatErrorType.InvalidConnReq ->
generalGetString(MR.strings.invalid_connection_link)
@@ -1821,7 +1828,10 @@ object ChatController {
return when {
r is API.Result && r.res is CR.UserProfileUpdated -> r.res.user.updateRemoteHostId(rh)
r is API.Result && r.res is CR.UserProfileNoChange -> r.res.user.updateRemoteHostId(rh)
else -> throw Exception("failed to set SimpleX name: ${r.responseType} ${r.details}")
else -> {
if (r is API.Error) AlertManager.shared.showAlertMsg(generalGetString(MR.strings.error_saving_simplex_name), setSimplexNameErrorText(r.err, false))
throw Exception("failed to set SimpleX name: ${r.responseType} ${r.details}")
}
}
}
@@ -2385,7 +2395,7 @@ object ChatController {
return when {
r is API.Result && r.res is CR.GroupUpdated -> r.res.toGroup
r is API.Error -> {
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.error_saving_simplex_name), r.err.string)
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.error_saving_simplex_name), setSimplexNameErrorText(r.err, true))
null
}
else -> {
@@ -373,7 +373,7 @@ private fun UserAddressLayout(
withContext(Dispatchers.Main) { chatModel.updateUser(u) }
true
} catch (e: Exception) {
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.error_saving_simplex_name), e.message ?: "")
Log.e(TAG, "apiSetUserName: ${e.message}")
false
}
},
@@ -946,7 +946,9 @@
<string name="simplex_name_not_verified">SimpleX name not verified</string>
<string name="set_simplex_name">Set SimpleX name</string>
<string name="simplex_name_placeholder">name.simplex</string>
<string name="error_saving_simplex_name">Error saving SimpleX name</string>
<string name="error_saving_simplex_name">Error saving name</string>
<string name="simplex_name_owner_no_channel_link">The SimpleX name %1$s is registered without channel link. Add channel link to the name via the registration page.</string>
<string name="simplex_name_owner_no_address">The SimpleX name %1$s is registered without SimpleX address. Add your SimpleX address to the name via the registration page.</string>
<string name="set_user_simplex_name_footer">Set a SimpleX name so people can connect to you using @yourname instead of a link. The name must already be registered to your address.</string>
<string name="set_channel_simplex_name_footer">Set a SimpleX name so people can find this channel as #name. The name must be registered to this channel\'s address.</string>
<string name="or_show_this_qr_code">Or show this code</string>
+4 -4
View File
@@ -1499,12 +1499,12 @@ processChatCommand cxt nm = \case
else do
cl' <- case name_ of
Nothing -> pure contactLink
Just SimplexNameInfo {nameDomain} -> do
UserContactLink {shortLinkDataSet, connLinkContact = CCLink fl sl_} <- withFastStore (`getUserAddress` user)
Just ni@SimplexNameInfo {nameDomain} -> do
UserContactLink {shortLinkDataSet, connLinkContact = CCLink fl sl_} <- withFastStore (`getUserAddress` user)
case sl_ of
Just sl | shortLinkDataSet -> do
NameRecord {nrSimplexContact} <- withAgent $ \a -> resolveSimplexName a nm (aUserId user) nameDomain
unless (nameResolvesTo sl nrSimplexContact) $ throwCmdError "name does not point to your address"
unless (nameResolvesTo sl nrSimplexContact) $ throwChatError $ CESimplexName ni SNENoValidLink
pure $ Just (CLShort sl)
_ -> throwCmdError "create the address short link and add it to name"
let p' = (fromLocalProfile p :: Profile) {simplexName = mkSimplexNameClaim name_ Nothing, contactLink = cl'}
@@ -3141,7 +3141,7 @@ processChatCommand cxt nm = \case
forM_ (claimName <$> simplexName) $ \newName@SimplexNameInfo {nameDomain} ->
when (Just newName /= (claimName <$> (existingAccess >>= publicGroupClaim))) $ do
NameRecord {nrSimplexChannel} <- withAgent $ \a -> resolveSimplexName a nm (aUserId user) nameDomain
unless (nameResolvesTo groupLink nrSimplexChannel) $ throwCmdError "name is not registered to this channel"
unless (nameResolvesTo groupLink nrSimplexChannel) $ throwChatError $ CESimplexName newName SNENoValidLink
runUpdateGroupProfile user gInfo p {publicGroup = Just pg {publicGroupAccess = Just access}}
Nothing -> throwChatError $ CECommandError "not a public group"
APICreateGroupLink groupId mRole -> withUser $ \user -> withGroupLock "createGroupLink" groupId $ do