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>
This commit is contained in:
parent
10f79aae66
commit
1dcd2760b0
@ -720,8 +720,9 @@ func apiUpdateProfile(profile: Profile) async throws -> (Profile, [Contact])? {
|
|||||||
let userId = try currentUserId("apiUpdateProfile")
|
let userId = try currentUserId("apiUpdateProfile")
|
||||||
let r = await chatSendCmd(.apiUpdateProfile(userId: userId, profile: profile))
|
let r = await chatSendCmd(.apiUpdateProfile(userId: userId, profile: profile))
|
||||||
switch r {
|
switch r {
|
||||||
case .userProfileNoChange: return nil
|
case .userProfileNoChange: return (profile, [])
|
||||||
case let .userProfileUpdated(_, _, toProfile, updateSummary): return (toProfile, updateSummary.changedContacts)
|
case let .userProfileUpdated(_, _, toProfile, updateSummary): return (toProfile, updateSummary.changedContacts)
|
||||||
|
case .chatCmdError(_, .errorStore(.duplicateName)): return nil;
|
||||||
default: throw r
|
default: throw r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ struct ChatInfoView: View {
|
|||||||
}
|
}
|
||||||
.actionSheet(isPresented: $showDeleteContactActionSheet) {
|
.actionSheet(isPresented: $showDeleteContactActionSheet) {
|
||||||
if contact.ready && contact.active {
|
if contact.ready && contact.active {
|
||||||
ActionSheet(
|
return ActionSheet(
|
||||||
title: Text("Delete contact?\nThis cannot be undone!"),
|
title: Text("Delete contact?\nThis cannot be undone!"),
|
||||||
buttons: [
|
buttons: [
|
||||||
.destructive(Text("Delete and notify contact")) { deleteContact(notify: true) },
|
.destructive(Text("Delete and notify contact")) { deleteContact(notify: true) },
|
||||||
@ -251,7 +251,7 @@ struct ChatInfoView: View {
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
ActionSheet(
|
return ActionSheet(
|
||||||
title: Text("Delete contact?\nThis cannot be undone!"),
|
title: Text("Delete contact?\nThis cannot be undone!"),
|
||||||
buttons: [
|
buttons: [
|
||||||
.destructive(Text("Delete")) { deleteContact() },
|
.destructive(Text("Delete")) { deleteContact() },
|
||||||
|
@ -78,7 +78,7 @@ struct ChatListNavLink: View {
|
|||||||
.frame(height: rowHeights[dynamicTypeSize])
|
.frame(height: rowHeights[dynamicTypeSize])
|
||||||
.actionSheet(isPresented: $showDeleteContactActionSheet) {
|
.actionSheet(isPresented: $showDeleteContactActionSheet) {
|
||||||
if contact.ready && contact.active {
|
if contact.ready && contact.active {
|
||||||
ActionSheet(
|
return ActionSheet(
|
||||||
title: Text("Delete contact?\nThis cannot be undone!"),
|
title: Text("Delete contact?\nThis cannot be undone!"),
|
||||||
buttons: [
|
buttons: [
|
||||||
.destructive(Text("Delete and notify contact")) { Task { await deleteChat(chat, notify: true) } },
|
.destructive(Text("Delete and notify contact")) { Task { await deleteChat(chat, notify: true) } },
|
||||||
@ -87,7 +87,7 @@ struct ChatListNavLink: View {
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
ActionSheet(
|
return ActionSheet(
|
||||||
title: Text("Delete contact?\nThis cannot be undone!"),
|
title: Text("Delete contact?\nThis cannot be undone!"),
|
||||||
buttons: [
|
buttons: [
|
||||||
.destructive(Text("Delete")) { Task { await deleteChat(chat) } },
|
.destructive(Text("Delete")) { Task { await deleteChat(chat) } },
|
||||||
|
@ -174,11 +174,13 @@ struct UserProfile: View {
|
|||||||
chatModel.updateCurrentUser(newProfile)
|
chatModel.updateCurrentUser(newProfile)
|
||||||
profile = newProfile
|
profile = newProfile
|
||||||
}
|
}
|
||||||
|
editProfile = false
|
||||||
|
} else {
|
||||||
|
alert = .duplicateUserError
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
logger.error("UserProfile apiUpdateProfile error: \(responseError(error))")
|
logger.error("UserProfile apiUpdateProfile error: \(responseError(error))")
|
||||||
}
|
}
|
||||||
editProfile = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,9 +83,9 @@ public enum AppState: String {
|
|||||||
|
|
||||||
public var canSuspend: Bool {
|
public var canSuspend: Bool {
|
||||||
switch self {
|
switch self {
|
||||||
case .active: true
|
case .active: return true
|
||||||
case .bgRefresh: true
|
case .bgRefresh: return true
|
||||||
default: false
|
default: return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -943,6 +943,9 @@ object ChatController {
|
|||||||
val r = sendCmd(CC.ApiUpdateProfile(userId, profile))
|
val r = sendCmd(CC.ApiUpdateProfile(userId, profile))
|
||||||
if (r is CR.UserProfileNoChange) return profile to emptyList()
|
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.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}")
|
Log.e(TAG, "apiUpdateProfile bad response: ${r.responseType} ${r.details}")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,8 @@ fun UserProfileView(chatModel: ChatModel, close: () -> Unit) {
|
|||||||
val (newProfile, _) = updated
|
val (newProfile, _) = updated
|
||||||
chatModel.updateCurrentUser(newProfile)
|
chatModel.updateCurrentUser(newProfile)
|
||||||
profile = newProfile
|
profile = newProfile
|
||||||
|
close()
|
||||||
}
|
}
|
||||||
close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user