* 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>
86 lines
2.8 KiB
Swift
86 lines
2.8 KiB
Swift
//
|
|
// GroupPreferencesView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by JRoberts on 16.11.2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
struct GroupPreferencesView: View {
|
|
@EnvironmentObject var chatModel: ChatModel
|
|
@Binding var groupInfo: GroupInfo
|
|
@State var preferences: FullGroupPreferences
|
|
@State var currentPreferences: FullGroupPreferences
|
|
|
|
var body: some View {
|
|
VStack {
|
|
List {
|
|
featureSection(.fullDelete, $preferences.fullDelete.enable)
|
|
featureSection(.directMessages, $preferences.directMessages.enable)
|
|
featureSection(.voice, $preferences.voice.enable)
|
|
|
|
if groupInfo.canEdit {
|
|
Section {
|
|
Button("Reset") { preferences = currentPreferences }
|
|
Button("Save (and notify group members)") { savePreferences() }
|
|
}
|
|
.disabled(currentPreferences == preferences)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func featureSection(_ feature: GroupFeature, _ enableFeature: Binding<GroupFeatureEnabled>) -> some View {
|
|
Section {
|
|
if (groupInfo.canEdit) {
|
|
settingsRow(feature.icon) {
|
|
Picker(feature.text, selection: enableFeature) {
|
|
ForEach(GroupFeatureEnabled.values) { enable in
|
|
Text(enable.text)
|
|
}
|
|
}
|
|
.frame(height: 36)
|
|
}
|
|
}
|
|
else {
|
|
settingsRow(feature.icon) {
|
|
infoRow(feature.text, enableFeature.wrappedValue.text)
|
|
}
|
|
}
|
|
} footer: {
|
|
Text(feature.enableDescription(enableFeature.wrappedValue, groupInfo.canEdit))
|
|
.frame(height: 36, alignment: .topLeading)
|
|
}
|
|
}
|
|
|
|
private func savePreferences() {
|
|
Task {
|
|
do {
|
|
var gp = groupInfo.groupProfile
|
|
gp.groupPreferences = toGroupPreferences(preferences)
|
|
let gInfo = try await apiUpdateGroup(groupInfo.groupId, gp)
|
|
await MainActor.run {
|
|
groupInfo = gInfo
|
|
chatModel.updateGroup(gInfo)
|
|
currentPreferences = preferences
|
|
}
|
|
} catch {
|
|
logger.error("GroupPreferencesView apiUpdateGroup error: \(responseError(error))")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct GroupPreferencesView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
GroupPreferencesView(
|
|
groupInfo: Binding.constant(GroupInfo.sampleData),
|
|
preferences: FullGroupPreferences.sampleData,
|
|
currentPreferences: FullGroupPreferences.sampleData
|
|
)
|
|
}
|
|
}
|