From 1dcd2760b0b803a9e050532c8505379db6516288 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Wed, 25 Oct 2023 06:01:47 +0800 Subject: [PATCH] ui: show alert after saving profile with existing name (#3273) * android, desktop: show alert after saving profile with existing name * ios: show alert after saving profile with existing name * return statements * better way of showing alert --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> --- apps/ios/Shared/Model/SimpleXAPI.swift | 3 ++- apps/ios/Shared/Views/Chat/ChatInfoView.swift | 4 ++-- apps/ios/Shared/Views/ChatList/ChatListNavLink.swift | 4 ++-- apps/ios/Shared/Views/UserSettings/UserProfile.swift | 4 +++- apps/ios/SimpleXChat/AppGroup.swift | 6 +++--- .../kotlin/chat/simplex/common/model/SimpleXAPI.kt | 3 +++ .../simplex/common/views/usersettings/UserProfileView.kt | 2 +- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/apps/ios/Shared/Model/SimpleXAPI.swift b/apps/ios/Shared/Model/SimpleXAPI.swift index 99e8c0284..680a7132d 100644 --- a/apps/ios/Shared/Model/SimpleXAPI.swift +++ b/apps/ios/Shared/Model/SimpleXAPI.swift @@ -720,8 +720,9 @@ func apiUpdateProfile(profile: Profile) async throws -> (Profile, [Contact])? { let userId = try currentUserId("apiUpdateProfile") let r = await chatSendCmd(.apiUpdateProfile(userId: userId, profile: profile)) switch r { - case .userProfileNoChange: return nil + case .userProfileNoChange: return (profile, []) case let .userProfileUpdated(_, _, toProfile, updateSummary): return (toProfile, updateSummary.changedContacts) + case .chatCmdError(_, .errorStore(.duplicateName)): return nil; default: throw r } } diff --git a/apps/ios/Shared/Views/Chat/ChatInfoView.swift b/apps/ios/Shared/Views/Chat/ChatInfoView.swift index ec4cc0fc4..b90c9e747 100644 --- a/apps/ios/Shared/Views/Chat/ChatInfoView.swift +++ b/apps/ios/Shared/Views/Chat/ChatInfoView.swift @@ -242,7 +242,7 @@ struct ChatInfoView: View { } .actionSheet(isPresented: $showDeleteContactActionSheet) { if contact.ready && contact.active { - ActionSheet( + return ActionSheet( title: Text("Delete contact?\nThis cannot be undone!"), buttons: [ .destructive(Text("Delete and notify contact")) { deleteContact(notify: true) }, @@ -251,7 +251,7 @@ struct ChatInfoView: View { ] ) } else { - ActionSheet( + return ActionSheet( title: Text("Delete contact?\nThis cannot be undone!"), buttons: [ .destructive(Text("Delete")) { deleteContact() }, diff --git a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift index be912d666..088335d19 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift @@ -78,7 +78,7 @@ struct ChatListNavLink: View { .frame(height: rowHeights[dynamicTypeSize]) .actionSheet(isPresented: $showDeleteContactActionSheet) { if contact.ready && contact.active { - ActionSheet( + return ActionSheet( title: Text("Delete contact?\nThis cannot be undone!"), buttons: [ .destructive(Text("Delete and notify contact")) { Task { await deleteChat(chat, notify: true) } }, @@ -87,7 +87,7 @@ struct ChatListNavLink: View { ] ) } else { - ActionSheet( + return ActionSheet( title: Text("Delete contact?\nThis cannot be undone!"), buttons: [ .destructive(Text("Delete")) { Task { await deleteChat(chat) } }, diff --git a/apps/ios/Shared/Views/UserSettings/UserProfile.swift b/apps/ios/Shared/Views/UserSettings/UserProfile.swift index b1a362a5a..b64ec21de 100644 --- a/apps/ios/Shared/Views/UserSettings/UserProfile.swift +++ b/apps/ios/Shared/Views/UserSettings/UserProfile.swift @@ -174,11 +174,13 @@ struct UserProfile: View { chatModel.updateCurrentUser(newProfile) profile = newProfile } + editProfile = false + } else { + alert = .duplicateUserError } } catch { logger.error("UserProfile apiUpdateProfile error: \(responseError(error))") } - editProfile = false } } } diff --git a/apps/ios/SimpleXChat/AppGroup.swift b/apps/ios/SimpleXChat/AppGroup.swift index 4943dbd4e..cc61fae53 100644 --- a/apps/ios/SimpleXChat/AppGroup.swift +++ b/apps/ios/SimpleXChat/AppGroup.swift @@ -83,9 +83,9 @@ public enum AppState: String { public var canSuspend: Bool { switch self { - case .active: true - case .bgRefresh: true - default: false + case .active: return true + case .bgRefresh: return true + default: return false } } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt index 58850ce05..1abc823c0 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt @@ -943,6 +943,9 @@ object ChatController { val r = sendCmd(CC.ApiUpdateProfile(userId, profile)) if (r is CR.UserProfileNoChange) return profile to emptyList() if (r is CR.UserProfileUpdated) return r.toProfile to r.updateSummary.changedContacts + if (r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorStore && r.chatError.storeError is StoreError.DuplicateName) { + AlertManager.shared.showAlertMsg(generalGetString(MR.strings.failed_to_create_user_duplicate_title), generalGetString(MR.strings.failed_to_create_user_duplicate_desc)) + } Log.e(TAG, "apiUpdateProfile bad response: ${r.responseType} ${r.details}") return null } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/UserProfileView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/UserProfileView.kt index 38c9e58ad..ea4ef79d4 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/UserProfileView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/UserProfileView.kt @@ -42,8 +42,8 @@ fun UserProfileView(chatModel: ChatModel, close: () -> Unit) { val (newProfile, _) = updated chatModel.updateCurrentUser(newProfile) profile = newProfile + close() } - close() } } )