mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-29 04:39:53 +00:00
* ios: marked deleted chat items; full deletion preference * text_, menu, backend * android types * more android types * fix * refactor ios * restore previews * box * refactor menu * revert unnecessary content.text changes * Update apps/ios/Shared/Views/Chat/ChatItem/CIVoiceView.swift Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> * revert layered framed items * clever framed view * improve look * restore previews * restore previews * refactor * refactoring, almost looks good * look * add previews * more previews * remove preview of legacy item * ChatItemDeleted * flip if * remove text_ * refactor * abstract pref property * move marked deleted * revert pref change * undo menu * fix - change to constants * undo pref logic Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
78 lines
2.6 KiB
Swift
78 lines
2.6 KiB
Swift
//
|
|
// PreferencesView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by Evgeny on 13/11/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
struct PreferencesView: View {
|
|
@EnvironmentObject var chatModel: ChatModel
|
|
@State var profile: LocalProfile
|
|
@State var preferences: FullPreferences
|
|
@State var currentPreferences: FullPreferences
|
|
|
|
var body: some View {
|
|
VStack {
|
|
List {
|
|
featureSection(.fullDelete, $preferences.fullDelete.allow)
|
|
featureSection(.voice, $preferences.voice.allow)
|
|
|
|
Section {
|
|
Button("Reset") { preferences = currentPreferences }
|
|
Button("Save (and notify contacts)") { savePreferences() }
|
|
}
|
|
.disabled(currentPreferences == preferences)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func featureSection(_ feature: ChatFeature, _ allowFeature: Binding<FeatureAllowed>) -> some View {
|
|
Section {
|
|
settingsRow(feature.icon) {
|
|
Picker(feature.text, selection: allowFeature) {
|
|
ForEach(FeatureAllowed.values) { allow in
|
|
Text(allow.text)
|
|
}
|
|
}
|
|
.frame(height: 36)
|
|
}
|
|
} footer: {
|
|
Text(feature.allowDescription(allowFeature.wrappedValue))
|
|
.frame(height: 36, alignment: .topLeading)
|
|
}
|
|
}
|
|
|
|
private func savePreferences() {
|
|
Task {
|
|
do {
|
|
var p = fromLocalProfile(profile)
|
|
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
|
|
}
|
|
currentPreferences = preferences
|
|
}
|
|
}
|
|
} catch {
|
|
logger.error("PreferencesView apiUpdateProfile error: \(responseError(error))")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct PreferencesView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
PreferencesView(
|
|
profile: LocalProfile(profileId: 1, displayName: "alice", fullName: "", localAlias: ""),
|
|
preferences: FullPreferences.sampleData,
|
|
currentPreferences: FullPreferences.sampleData
|
|
)
|
|
}
|
|
}
|