mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-01 20:08:57 +00:00
ios: restore scroll and update user profile in user profile menu (#1811)
* ios: Small UserPicker fixes * update scroll * update current user and update users list * refactor Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
co-authored by
Evgeny Poberezkin
parent
4cd396a0d2
commit
1d5c361b9a
@@ -275,6 +275,18 @@ final class ChatModel: ObservableObject {
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateCurrentUser(_ newProfile: Profile, _ preferences: FullPreferences? = nil) {
|
||||
if let current = currentUser {
|
||||
currentUser?.profile = toLocalProfile(current.profile.profileId, newProfile, "")
|
||||
if let preferences = preferences {
|
||||
currentUser?.fullPreferences = preferences
|
||||
}
|
||||
if let current = currentUser, let i = users.firstIndex(where: { $0.user.userId == current.userId }) {
|
||||
users[i].user = current
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addLiveDummy(_ chatInfo: ChatInfo) -> ChatItem {
|
||||
let cItem = ChatItem.liveDummy(chatInfo.chatType)
|
||||
withAnimation {
|
||||
|
||||
@@ -29,8 +29,9 @@ struct UserPicker: View {
|
||||
VStack(spacing: 0) {
|
||||
ScrollView {
|
||||
ScrollViewReader { sp in
|
||||
let users = m.users.sorted { u, _ in u.user.activeUser }
|
||||
VStack(spacing: 0) {
|
||||
ForEach(Array(m.users.sorted(by: { u, _ in u.user.activeUser }))) { u in
|
||||
ForEach(users) { u in
|
||||
userView(u)
|
||||
Divider()
|
||||
}
|
||||
@@ -49,8 +50,8 @@ struct UserPicker: View {
|
||||
}
|
||||
}
|
||||
.onChange(of: userPickerVisible) { visible in
|
||||
if visible {
|
||||
sp.scrollTo(0)
|
||||
if visible, let u = users.first {
|
||||
sp.scrollTo(u.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,10 +71,7 @@ struct PreferencesView: View {
|
||||
p.preferences = fullPreferencesToPreferences(preferences)
|
||||
if let newProfile = try await apiUpdateProfile(profile: p) {
|
||||
await MainActor.run {
|
||||
if let profileId = chatModel.currentUser?.profile.profileId {
|
||||
chatModel.currentUser?.profile = toLocalProfile(profileId, newProfile, "")
|
||||
chatModel.currentUser?.fullPreferences = preferences
|
||||
}
|
||||
chatModel.updateCurrentUser(newProfile, preferences)
|
||||
currentPreferences = preferences
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,9 +141,7 @@ struct UserProfile: View {
|
||||
do {
|
||||
if let newProfile = try await apiUpdateProfile(profile: profile) {
|
||||
DispatchQueue.main.async {
|
||||
if let profileId = chatModel.currentUser?.profile.profileId {
|
||||
chatModel.currentUser?.profile = toLocalProfile(profileId, newProfile, "")
|
||||
}
|
||||
chatModel.updateCurrentUser(newProfile)
|
||||
profile = newProfile
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user