mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-22 21:52:28 +00:00
ui: don't commit profile picker state when the change failed
ActiveProfilePicker wrote the app-wide incognito preference before the call that can fail, and never rolled it back, in both directions: - selecting a profile set incognito=false, then, if apiChangeConnectionUser returned null, left the connection incognito while the preference said otherwise - selecting Incognito set incognito=true before apiSetConnectionIncognito, and undid nothing when it returned null Neither is visible at the time: the row reads the connection first (showingInvitation.value?.conn?.incognito), which was not changed. It surfaces on the next connection started with showingInvitation null, which falls through to the preference. Selecting a profile also closed the picker unconditionally, so a failed apiChangeConnectionUser left the connection on the old profile with the picker dismissed as if it had worked. Both APIs alert on error, so the failure was reported - but the picker still closed. Move all three inside the branch that runs only when the change landed.
This commit is contained in:
1 parent
a0b6643932
commit
10b88a02cb
1 file changed
+8
-8
+8
-8
@@ -326,7 +326,6 @@ fun ActiveProfilePicker(
|
||||
switchingProfile.value = true
|
||||
withApi {
|
||||
try {
|
||||
appPreferences.incognito.set(false)
|
||||
var updatedConn: PendingContactConnection? = null;
|
||||
|
||||
if (contactConnection != null) {
|
||||
@@ -340,6 +339,7 @@ fun ActiveProfilePicker(
|
||||
}
|
||||
|
||||
if ((contactConnection != null && updatedConn != null) || contactConnection == null) {
|
||||
appPreferences.incognito.set(false)
|
||||
controller.changeActiveUser_(
|
||||
rhId = user.remoteHostId,
|
||||
toUserId = user.userId,
|
||||
@@ -352,15 +352,15 @@ fun ActiveProfilePicker(
|
||||
String.format(generalGetString(MR.strings.switching_profile_error_message), user.chatViewName)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (updatedConn != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
chatModel.chatsContext.updateContactConnection(user.remoteHostId, updatedConn)
|
||||
if (updatedConn != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
chatModel.chatsContext.updateContactConnection(user.remoteHostId, updatedConn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close()
|
||||
close()
|
||||
}
|
||||
} finally {
|
||||
switchingProfile.value = false
|
||||
}
|
||||
@@ -383,9 +383,9 @@ fun ActiveProfilePicker(
|
||||
switchingProfile.value = true
|
||||
withApi {
|
||||
try {
|
||||
appPreferences.incognito.set(true)
|
||||
val conn = controller.apiSetConnectionIncognito(rhId, contactConnection.pccConnId, true)
|
||||
if (conn != null) {
|
||||
appPreferences.incognito.set(true)
|
||||
withContext(Dispatchers.Main) {
|
||||
chatModel.chatsContext.updateContactConnection(rhId, conn)
|
||||
updateShownConnection(conn)
|
||||
|
||||
Reference in new issue
Block a user