mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-28 00:44:27 +00:00
wip
This commit is contained in:
@@ -264,6 +264,26 @@ final class ChatModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
func acceptConditionsForOperators(_ acceptForOperators: [ServerOperator], _ date: Date) {
|
||||
for serverOperator in acceptForOperators {
|
||||
if let i = serverOperators.firstIndex(where: { $0.operatorId == serverOperator.operatorId }) {
|
||||
var updatedOperator = serverOperators[i]
|
||||
updatedOperator.conditionsAcceptance = .accepted(date: date)
|
||||
serverOperators[i] = updatedOperator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func enableServerOperators(_ operatorsToEnable: [ServerOperator]) {
|
||||
for serverOperator in operatorsToEnable {
|
||||
if let i = serverOperators.firstIndex(where: { $0.operatorId == serverOperator.operatorId }) {
|
||||
var updatedOperator = serverOperators[i]
|
||||
updatedOperator.enabled = true
|
||||
serverOperators[i] = updatedOperator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateServerOperator(_ updatedOperator: ServerOperator) {
|
||||
if let i = serverOperators.firstIndex(where: { $0.operatorId == updatedOperator.operatorId }) {
|
||||
serverOperators[i] = updatedOperator
|
||||
|
||||
@@ -9,12 +9,24 @@
|
||||
import SwiftUI
|
||||
import SimpleXChat
|
||||
|
||||
private enum ChooseServerOperatorsSheet: Identifiable {
|
||||
case showConditions(conditionsAction: UsageConditionsAction)
|
||||
|
||||
var id: String {
|
||||
switch self {
|
||||
case .showConditions: return "showConditions"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ChooseServerOperators: View {
|
||||
@EnvironmentObject var theme: AppTheme
|
||||
@State private var showInfoSheet = false
|
||||
@State private var serverOperators: [ServerOperator] = []
|
||||
@State private var selectedOperators = Set<Int64>()
|
||||
@State private var customServersNavLinkActive = false
|
||||
@State private var sheetItem: ChooseServerOperatorsSheet? = nil
|
||||
@State private var conditionsAccepted = false
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
@@ -54,6 +66,25 @@ struct ChooseServerOperators: View {
|
||||
.sheet(isPresented: $showInfoSheet) {
|
||||
Text("Info")
|
||||
}
|
||||
.sheet(item: $sheetItem, onDismiss: onConditionsSheetDismissed) { item in
|
||||
switch item {
|
||||
case let .showConditions(conditionsAction):
|
||||
UsageConditionsView(conditionsAction: conditionsAction, conditionsAccepted: $conditionsAccepted)
|
||||
.modifier(ThemedBackground(grouped: true))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var acceptForOperators: [ServerOperator] { serverOperators.filter { selectedOperators.contains($0.operatorId) } }
|
||||
|
||||
private func onConditionsSheetDismissed() {
|
||||
if conditionsAccepted {
|
||||
ChatModel.shared.enableServerOperators(acceptForOperators)
|
||||
withAnimation {
|
||||
onboardingStageDefault.set(.step4_SetNotificationsMode)
|
||||
ChatModel.shared.onboardingStage = .step4_SetNotificationsMode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,10 +192,7 @@ struct ChooseServerOperators: View {
|
||||
Spacer()
|
||||
|
||||
Button {
|
||||
withAnimation {
|
||||
onboardingStageDefault.set(.step4_SetNotificationsMode)
|
||||
ChatModel.shared.onboardingStage = .step4_SetNotificationsMode
|
||||
}
|
||||
sheetItem = .showConditions(conditionsAction: .reviewUpdatedConditions(acceptForOperators: acceptForOperators, deadline: nil))
|
||||
} label: {
|
||||
Text("Review conditions")
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ struct NetworkAndServers: View {
|
||||
@EnvironmentObject var theme: AppTheme
|
||||
@State private var serverOperators: [ServerOperator] = []
|
||||
@State private var sheetItem: NetworkAndServersSheet? = nil
|
||||
@State private var conditionsAccepted = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@@ -112,15 +113,21 @@ struct NetworkAndServers: View {
|
||||
.onAppear {
|
||||
serverOperators = ChatModel.shared.serverOperators
|
||||
}
|
||||
.sheet(item: $sheetItem, onDismiss: { serverOperators = ChatModel.shared.serverOperators }) { item in
|
||||
.sheet(item: $sheetItem, onDismiss: onConditionsSheetDismissed) { item in
|
||||
switch item {
|
||||
case let .showConditions(conditionsAction):
|
||||
UsageConditionsView(conditionsAction: conditionsAction)
|
||||
UsageConditionsView(conditionsAction: conditionsAction, conditionsAccepted: $conditionsAccepted)
|
||||
.modifier(ThemedBackground(grouped: true))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func onConditionsSheetDismissed() {
|
||||
if conditionsAccepted {
|
||||
serverOperators = ChatModel.shared.serverOperators
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func serverOperatorView(
|
||||
_ serverOperator: Binding<ServerOperator>,
|
||||
_ smpServers: [ServerCfg],
|
||||
|
||||
@@ -351,6 +351,7 @@ struct UsageConditionsView: View {
|
||||
@Environment(\.dismiss) var dismiss: DismissAction
|
||||
@EnvironmentObject var theme: AppTheme
|
||||
var conditionsAction: UsageConditionsAction
|
||||
@Binding var conditionsAccepted: Bool
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 20) {
|
||||
@@ -368,7 +369,7 @@ struct UsageConditionsView: View {
|
||||
|
||||
conditionsTextView()
|
||||
|
||||
acceptConditionsButton()
|
||||
acceptConditionsButton(acceptForOperators)
|
||||
.padding(.bottom)
|
||||
|
||||
case let .viewAcceptedConditions(acceptedForOperators):
|
||||
@@ -385,7 +386,7 @@ struct UsageConditionsView: View {
|
||||
.frame(maxHeight: .infinity)
|
||||
}
|
||||
|
||||
private func acceptConditionsButton() -> some View {
|
||||
private func acceptConditionsButton(_ acceptForOperators: [ServerOperator]) -> some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
@@ -393,7 +394,8 @@ struct UsageConditionsView: View {
|
||||
// Should call api to save state here, not when saving all servers
|
||||
// (It's counterintuitive to lose to closed sheet or Reset)
|
||||
let date = Date.now
|
||||
ChatModel.shared.acceptConditionsForEnabledOperators(date)
|
||||
ChatModel.shared.acceptConditionsForOperators(acceptForOperators, date)
|
||||
conditionsAccepted = true
|
||||
dismiss()
|
||||
} label: {
|
||||
Text("Accept conditions")
|
||||
|
||||
Reference in New Issue
Block a user