mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-29 03:18:37 +00:00
android, desktop: extract profile selection from the picker row handler
ActiveProfilePicker performed the whole profile change - connection reassignment, switch, alerts, close - inside the row's onSelected lambda, where nothing else can reach it. Lift it to selectProfile(user), called by the row. Pure move: the body is unchanged apart from indentation, so picking a profile behaves exactly as before. It gives the next commit a way to take the same path for a newly created profile rather than duplicating it.
This commit is contained in:
+46
-44
@@ -314,6 +314,51 @@ fun ActiveProfilePicker(
|
||||
}
|
||||
}
|
||||
|
||||
fun selectProfile(user: User) {
|
||||
switchingProfile.value = true
|
||||
withApi {
|
||||
try {
|
||||
appPreferences.incognito.set(false)
|
||||
var updatedConn: PendingContactConnection? = null;
|
||||
|
||||
if (contactConnection != null) {
|
||||
updatedConn = controller.apiChangeConnectionUser(rhId, contactConnection.pccConnId, user.userId)
|
||||
if (updatedConn != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
chatModel.chatsContext.updateContactConnection(rhId, updatedConn)
|
||||
updateShownConnection(updatedConn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((contactConnection != null && updatedConn != null) || contactConnection == null) {
|
||||
controller.changeActiveUser_(
|
||||
rhId = user.remoteHostId,
|
||||
toUserId = user.userId,
|
||||
viewPwd = if (user.hidden) searchTextOrPassword.value else null
|
||||
)
|
||||
|
||||
if (chatModel.currentUser.value?.userId != user.userId) {
|
||||
AlertManager.shared.showAlertMsg(generalGetString(
|
||||
MR.strings.switching_profile_error_title),
|
||||
String.format(generalGetString(MR.strings.switching_profile_error_message), user.chatViewName)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (updatedConn != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
chatModel.chatsContext.updateContactConnection(user.remoteHostId, updatedConn)
|
||||
}
|
||||
}
|
||||
|
||||
close()
|
||||
} finally {
|
||||
switchingProfile.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ProfilePickerUserOption(user: User) {
|
||||
val selected = selectedProfile?.userId == user.userId && !incognito
|
||||
@@ -322,50 +367,7 @@ fun ActiveProfilePicker(
|
||||
title = user.chatViewName,
|
||||
disabled = switchingProfile.value || selected,
|
||||
selected = selected,
|
||||
onSelected = {
|
||||
switchingProfile.value = true
|
||||
withApi {
|
||||
try {
|
||||
appPreferences.incognito.set(false)
|
||||
var updatedConn: PendingContactConnection? = null;
|
||||
|
||||
if (contactConnection != null) {
|
||||
updatedConn = controller.apiChangeConnectionUser(rhId, contactConnection.pccConnId, user.userId)
|
||||
if (updatedConn != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
chatModel.chatsContext.updateContactConnection(rhId, updatedConn)
|
||||
updateShownConnection(updatedConn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((contactConnection != null && updatedConn != null) || contactConnection == null) {
|
||||
controller.changeActiveUser_(
|
||||
rhId = user.remoteHostId,
|
||||
toUserId = user.userId,
|
||||
viewPwd = if (user.hidden) searchTextOrPassword.value else null
|
||||
)
|
||||
|
||||
if (chatModel.currentUser.value?.userId != user.userId) {
|
||||
AlertManager.shared.showAlertMsg(generalGetString(
|
||||
MR.strings.switching_profile_error_title),
|
||||
String.format(generalGetString(MR.strings.switching_profile_error_message), user.chatViewName)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (updatedConn != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
chatModel.chatsContext.updateContactConnection(user.remoteHostId, updatedConn)
|
||||
}
|
||||
}
|
||||
|
||||
close()
|
||||
} finally {
|
||||
switchingProfile.value = false
|
||||
}
|
||||
}
|
||||
},
|
||||
onSelected = { selectProfile(user) },
|
||||
image = { ProfileImage(size = 42.dp, image = user.image) },
|
||||
badge = user.profile.localBadge
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user