* 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>
87 lines
3.1 KiB
Swift
87 lines
3.1 KiB
Swift
//
|
|
// ContactPreferencesView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by Evgeny on 13/11/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
struct ContactPreferencesView: View {
|
|
@EnvironmentObject var chatModel: ChatModel
|
|
@Binding var contact: Contact
|
|
@State var featuresAllowed: ContactFeaturesAllowed
|
|
@State var currentFeaturesAllowed: ContactFeaturesAllowed
|
|
|
|
var body: some View {
|
|
let user: User = chatModel.currentUser!
|
|
|
|
VStack {
|
|
List {
|
|
featureSection(.fullDelete, user.fullPreferences.fullDelete.allow, contact.mergedPreferences.fullDelete, $featuresAllowed.fullDelete)
|
|
featureSection(.voice, user.fullPreferences.voice.allow, contact.mergedPreferences.voice, $featuresAllowed.voice)
|
|
|
|
Section {
|
|
Button("Reset") { featuresAllowed = currentFeaturesAllowed }
|
|
Button("Save (and notify contact)") { savePreferences() }
|
|
}
|
|
.disabled(currentFeaturesAllowed == featuresAllowed)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func featureSection(_ feature: ChatFeature, _ userDefault: FeatureAllowed, _ pref: ContactUserPreference, _ allowFeature: Binding<ContactFeatureAllowed>) -> some View {
|
|
let enabled = FeatureEnabled.enabled(
|
|
user: Preference(allow: allowFeature.wrappedValue.allowed),
|
|
contact: pref.contactPreference
|
|
)
|
|
return Section {
|
|
Picker("You allow", selection: allowFeature) {
|
|
ForEach(ContactFeatureAllowed.values(userDefault)) { allow in
|
|
Text(allow.text)
|
|
}
|
|
}
|
|
.frame(height: 36)
|
|
infoRow("Contact allows", pref.contactPreference.allow.text)
|
|
} header: {
|
|
HStack {
|
|
Image(systemName: "\(feature.icon).fill")
|
|
.foregroundColor(enabled.forUser ? .green : enabled.forContact ? .yellow : .red)
|
|
Text(feature.text)
|
|
}
|
|
} footer: {
|
|
Text(feature.enabledDescription(enabled))
|
|
.frame(height: 36, alignment: .topLeading)
|
|
}
|
|
}
|
|
|
|
private func savePreferences() {
|
|
Task {
|
|
do {
|
|
let prefs = contactFeaturesAllowedToPrefs(featuresAllowed)
|
|
if let toContact = try await apiSetContactPrefs(contactId: contact.contactId, preferences: prefs) {
|
|
await MainActor.run {
|
|
contact = toContact
|
|
chatModel.updateContact(toContact)
|
|
currentFeaturesAllowed = featuresAllowed
|
|
}
|
|
}
|
|
} catch {
|
|
logger.error("ContactPreferencesView apiSetContactPrefs error: \(responseError(error))")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ContactPreferencesView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContactPreferencesView(
|
|
contact: Binding.constant(Contact.sampleData),
|
|
featuresAllowed: ContactFeaturesAllowed.sampleData,
|
|
currentFeaturesAllowed: ContactFeaturesAllowed.sampleData
|
|
)
|
|
}
|
|
}
|