mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-29 05:29:08 +00:00
* android, desktop: settings navigation reorganization
Restructure the root Settings screen into two top-level sections and
fold previously-scattered items into three new sub-screens.
Root:
- Appearance, Your privacy, Chat data
- Help & support, Migrate to another device, Advanced settings
Your privacy (renamed from Privacy & security): keeps Device,
link previews / remove tracking, auto-accept images, blur media,
contact requests from groups. Adds a "More privacy" sub-screen.
More privacy (new): show last messages, message draft, encrypt local
files, protect IP address (with original dynamic footer preserved),
notification preview mode (moved from Notifications), and delivery
receipts.
Help & support (new): merges Help and Support SimpleX Chat sections
into Help / About (with App version) / Contact / Support the project.
Advanced settings (new): Network & servers, Notifications (Android),
Audio & video calls; then Developer tools, Restart and Shutdown
(Android), App update channel (desktop). Notifications is hidden on
desktop because the screen is empty after Show preview moves to
More privacy.
Chat data is the new top-level menu label for the existing
Database passphrase & export screen.
* android, desktop: trim settings reorg diff
- Remove 5 dead strings from base/strings.xml (privacy_and_security,
database_passphrase_and_export, settings_section_title_chat_database,
settings_section_title_support, settings_section_title_app) — no
Kotlin references after the reorg.
- Drop the now single-variant CurrentPage enum in
NotificationsSettingsView; replace with a direct callback.
- Read userDisplayName locally in HelpAndSupportView instead of
threading it through SettingsLayout/SettingsView/Preview.
* android, desktop: remove orphan locale strings
Companion to 442a368c9 which removed 5 dead keys from base/strings.xml.
The :common:adjustFormatting task enforces that every locale string has
a corresponding base entry, so these orphans broke the build. Removed
across 35 locale files (154 lines).
Keys removed:
- privacy_and_security
- database_passphrase_and_export
- settings_section_title_chat_database
- settings_section_title_support
- settings_section_title_app
* Revert "android, desktop: remove orphan locale strings"
This reverts commit 0ad5fc9308a3599d15bf50ca1980002ae0e467b2.
* android, desktop: restore base strings for removed keys
Counterpart to revert of 0ad5fc930: re-add the 5 base entries that
442a368c9 had deleted so the locale files (restored by the prior revert)
are no longer orphaned. Translation keys must not be removed once
introduced — the values can change but the keys stay.
Keys restored to base with their master English values:
- database_passphrase_and_export
- privacy_and_security
- settings_section_title_chat_database
- settings_section_title_support
- settings_section_title_app
* android, desktop: keep share-button helpers in SettingsView
ContributeItem, RateAppItem, StarOnGithubItem were moved from
SettingsView.kt to HelpAndSupportView.kt as part of the reorg.
Move them back: just drop the `private` modifier (one-word edit
per function) so HelpAndSupportView can call them in place. Saves
~60 lines of diff churn vs the move + matches the file's existing
pattern where helpers like AppVersionItem, ChatPreferencesItem,
ChatLockItem, etc. are all public top-level @Composable.
* android, desktop: inline HelpAndSupportView into SettingsView.kt
HelpAndSupportView is the only call site of SettingsView.kt's
share-button helpers; placing it as a top-level @Composable in
SettingsView.kt keeps the help/about/contact/support flow next to
the other settings entry points and removes the need for a new file.
Three imports (BuildConfigCommon, SimpleXInfo, WhatsNewView) that
the reorg was deleting from SettingsView.kt stay in place. Saves
~35 lines of diff and one new file.
* android, desktop: inline AdvancedSettingsView into SettingsView.kt
Same treatment as HelpAndSupportView in the previous commit:
AdvancedSettingsView is only reached from SettingsLayout, so the
function and its expect declaration live as top-level @Composable
in SettingsView.kt instead of a new file. NetworkAndServersView
import that the reorg was deleting from SettingsView.kt stays.
The .android.kt / .desktop.kt actuals are unchanged and keep
implementing the (now relocated) expect. Saves ~15 lines and a file.
* ios: settings navigation reorganization
Mirror the multiplatform reorg on iOS:
Root SettingsView: collapse the 5 sections into 2 unlabeled groups —
{Appearance, Your privacy, Chat data} and {Help & support, Migrate to
another device, Advanced settings}. "Privacy & security" becomes
"Your privacy"; the database row label becomes "Chat data".
PrivacySettings: keeps Device, link previews / remove tracking,
auto-accept images, blur media, contact requests from groups. Adds a
"More privacy" link.
MorePrivacy (new, inlined in PrivacySettings.swift): show last
messages, message draft, encrypt local files, protect IP address
(with original dynamic footer preserved), notification preview mode
(moved from NotificationsView), delivery receipts. Own state and
private helpers for the moved set* functions.
HelpAndSupportView (new, inlined in SettingsView.swift): merges Help
and Support sections into Help / About (with App version) / Contact /
Support the project.
AdvancedSettingsView (new, inlined in SettingsView.swift): Network &
servers, Notifications, Audio & video calls, Developer tools. iOS has
no Restart/Shutdown (Android-only) or App update channel (desktop).
NotificationsView: "Show preview" navigation removed — it now lives
in MorePrivacy. notificationsIcon() promoted to a free function so
AdvancedSettingsView can render the notifications status badge.
* android, desktop: keep platform file names as SettingsView.{android,desktop}.kt
Revert the file renames from {Advanced}SettingsView.{android,desktop}.kt.
Function rename SettingsSectionApp → AdvancedSettingsAppSection stays
inside each file; only the file path returns to its original name. No
behavior change; diff stat now shows two in-place modifications instead
of renames.
* ios: keep PrivacySettings/SettingsView state in place, use inline destinations
Restructure the iOS reorg to avoid moving state, helpers, and the alert
enum out of PrivacySettings — and to avoid moving notificationsIcon
out of SettingsView. The Help & Support, Advanced Settings, and
More Privacy "screens" become private computed properties on their
parent struct, so all @AppStorage, @State, set* helpers, and the
PrivacySettingsViewAlert enum stay UNCHANGED from master. NavigationLink
destinations reference the computed properties directly.
Net iOS diff vs master: 220+/154- (was 361+/259-) — saves ~245 lines.
* simplex settings
* android, desktop: mirror iOS settings reorganization
- inline Advanced settings section into the main settings list (Network &
servers, Notifications, Audio & video calls, App version); remove the
separate Advanced settings page
- reorder first section: Appearance, Your privacy, Help & support, Chat data,
Migrate; merge About SimpleX Chat into the Help section
- move the developer/maintenance section under App version (VersionInfoView);
load core version inside the view so it always opens (Developer tools and
Shutdown stay reachable even if the version request fails)
- keep "Developer tools" label (not renamed to "Developer")
- replace the Restart row with Cancel/Restart/Shutdown options in the
Shutdown dialog
- split DatabaseView: "Chat data" page (messages TTL, Database passphrase &
export, Files & media) and a sub-page with passphrase/export/import/delete
and the Run chat toggle; rename title to "Chat data"
- align delivery receipts alert wording with the renamed "Your privacy" settings
* android, desktop: simplify settings reorg internals
- VersionInfoView: drop the section/card wrapping, keep the original plain
version-text layout; load core version in-view so the screen always opens
- DatabaseView: make the "Database passphrase & export" sub-page a
self-contained DatabaseManagementView that owns its own state, mirroring the
DatabaseView/DatabaseLayout pattern instead of threading params through a modal
* android, desktop: show App version screen as a card screen
VersionInfoView now hosts a settings section (Developer tools / updates), so
open it with cardScreen = true like the other settings screens — otherwise the
section renders without the card box around it.
* android, desktop: show "Rate the app" only on mobile
The action opens a Play Store link, which does nothing on desktop (the
market:// scheme has no handler and the web fallback never fires). Gate it to
Android, like the Contribute item.
* android, desktop: move Shutdown to settings above app version
Move the Shutdown action out of the app version screen into the main
advanced settings section, just above the app version row. It stays
Android only (desktop is closed via the window) through an
AppShutdownItem expect/actual.
* android, desktop: show app version info in its own card
Wrap the version info block on the app version screen in a section card,
matching iOS and the rest of the card-screen settings.
* fix background
---------
Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
514 lines
19 KiB
Swift
514 lines
19 KiB
Swift
//
|
|
// NetworkServersView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by Evgeny on 02/08/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
// Spec: spec/architecture.md
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
private enum NetworkAlert: Identifiable {
|
|
case error(err: String)
|
|
|
|
var id: String {
|
|
switch self {
|
|
case let .error(err): return "error \(err)"
|
|
}
|
|
}
|
|
}
|
|
|
|
private enum NetworkAndServersSheet: Identifiable {
|
|
case showConditions
|
|
|
|
var id: String {
|
|
switch self {
|
|
case .showConditions: return "showConditions"
|
|
}
|
|
}
|
|
}
|
|
|
|
struct NetworkAndServers: View {
|
|
@Environment(\.dismiss) var dismiss: DismissAction
|
|
@EnvironmentObject var m: ChatModel
|
|
@Environment(\.colorScheme) var colorScheme: ColorScheme
|
|
@EnvironmentObject var theme: AppTheme
|
|
@EnvironmentObject var ss: SaveableSettings
|
|
@State private var sheetItem: NetworkAndServersSheet? = nil
|
|
@State private var justOpened = true
|
|
@State private var showSaveDialog = false
|
|
|
|
var body: some View {
|
|
VStack {
|
|
List {
|
|
let conditionsAction = m.conditions.conditionsAction
|
|
let anyOperatorEnabled = ss.servers.userServers.contains(where: { $0.operator?.enabled ?? false })
|
|
Section {
|
|
ForEach(ss.servers.userServers.enumerated().map { $0 }, id: \.element.id) { idx, userOperatorServers in
|
|
if let serverOperator = userOperatorServers.operator {
|
|
serverOperatorView(idx, serverOperator)
|
|
} else {
|
|
EmptyView()
|
|
}
|
|
}
|
|
|
|
if let conditionsAction = conditionsAction, anyOperatorEnabled {
|
|
conditionsButton(conditionsAction)
|
|
}
|
|
} header: {
|
|
Text("Preset servers")
|
|
.foregroundColor(theme.colors.secondary)
|
|
} footer: {
|
|
switch conditionsAction {
|
|
case let .review(_, deadline, _):
|
|
if let deadline = deadline, anyOperatorEnabled {
|
|
Text("Conditions will be accepted on: \(conditionsTimestamp(deadline)).")
|
|
.foregroundColor(theme.colors.secondary)
|
|
}
|
|
default:
|
|
EmptyView()
|
|
}
|
|
}
|
|
|
|
Section {
|
|
if let idx = ss.servers.userServers.firstIndex(where: { $0.operator == nil }) {
|
|
NavigationLink {
|
|
YourServersView(
|
|
userServers: $ss.servers.userServers,
|
|
serverErrors: $ss.servers.serverErrors,
|
|
serverWarnings: $ss.servers.serverWarnings,
|
|
operatorIndex: idx
|
|
)
|
|
.navigationTitle("Your servers")
|
|
.modifier(ThemedBackground(grouped: true))
|
|
} label: {
|
|
HStack {
|
|
Text("Your servers")
|
|
|
|
if ss.servers.userServers[idx] != ss.servers.currUserServers[idx] {
|
|
Spacer()
|
|
unsavedChangesIndicator()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
NavigationLink {
|
|
AdvancedNetworkSettings()
|
|
.navigationTitle("Advanced settings")
|
|
.modifier(ThemedBackground(grouped: true))
|
|
} label: {
|
|
Text("Advanced network settings")
|
|
}
|
|
} header: {
|
|
Text("Messages & files")
|
|
.foregroundColor(theme.colors.secondary)
|
|
}
|
|
|
|
Section {
|
|
Button("Save servers", action: { saveServers($ss.servers.currUserServers, $ss.servers.userServers) })
|
|
.disabled(!serversCanBeSaved(ss.servers.currUserServers, ss.servers.userServers, ss.servers.serverErrors))
|
|
} footer: {
|
|
if let errStr = globalServersError(ss.servers.serverErrors) {
|
|
ServersErrorView(errStr: errStr)
|
|
} else if !ss.servers.serverErrors.isEmpty {
|
|
ServersErrorView(errStr: NSLocalizedString("Errors in servers configuration.", comment: "servers error"))
|
|
}
|
|
if let warnStr = globalServersWarning(ss.servers.serverWarnings) {
|
|
ServersWarningView(warnStr: warnStr)
|
|
}
|
|
}
|
|
|
|
Section(header: Text("Network connection").foregroundColor(theme.colors.secondary)) {
|
|
HStack {
|
|
Text(m.networkInfo.networkType.text)
|
|
Spacer()
|
|
Image(systemName: "circle.fill").foregroundColor(m.networkInfo.online ? .green : .red)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
// this condition is needed to prevent re-setting the servers when exiting single server view
|
|
if justOpened {
|
|
do {
|
|
ss.servers.currUserServers = try await getUserServers()
|
|
ss.servers.userServers = ss.servers.currUserServers
|
|
ss.servers.serverErrors = []
|
|
ss.servers.serverWarnings = []
|
|
validateServers_($ss.servers.userServers, $ss.servers.serverErrors, $ss.servers.serverWarnings)
|
|
} catch let error {
|
|
await MainActor.run {
|
|
showAlert(
|
|
NSLocalizedString("Error loading servers", comment: "alert title"),
|
|
message: responseError(error)
|
|
)
|
|
}
|
|
}
|
|
justOpened = false
|
|
}
|
|
}
|
|
.modifier(BackButton(disabled: Binding.constant(false)) {
|
|
if serversCanBeSaved(ss.servers.currUserServers, ss.servers.userServers, ss.servers.serverErrors) {
|
|
showSaveDialog = true
|
|
} else {
|
|
dismiss()
|
|
}
|
|
})
|
|
.confirmationDialog("Save servers?", isPresented: $showSaveDialog, titleVisibility: .visible) {
|
|
Button("Save") {
|
|
saveServers($ss.servers.currUserServers, $ss.servers.userServers)
|
|
dismiss()
|
|
}
|
|
Button("Exit without saving") { dismiss() }
|
|
}
|
|
.sheet(item: $sheetItem) { item in
|
|
switch item {
|
|
case .showConditions:
|
|
UsageConditionsView(
|
|
currUserServers: $ss.servers.currUserServers,
|
|
userServers: $ss.servers.userServers
|
|
)
|
|
.modifier(ThemedBackground(grouped: true))
|
|
}
|
|
}
|
|
}
|
|
|
|
private func serverOperatorView(_ operatorIndex: Int, _ serverOperator: ServerOperator) -> some View {
|
|
NavigationLink() {
|
|
OperatorView(
|
|
currUserServers: $ss.servers.currUserServers,
|
|
userServers: $ss.servers.userServers,
|
|
serverErrors: $ss.servers.serverErrors,
|
|
serverWarnings: $ss.servers.serverWarnings,
|
|
operatorIndex: operatorIndex,
|
|
useOperator: serverOperator.enabled
|
|
)
|
|
.navigationBarTitle("\(serverOperator.tradeName) servers")
|
|
.modifier(ThemedBackground(grouped: true))
|
|
.navigationBarTitleDisplayMode(.large)
|
|
} label: {
|
|
HStack {
|
|
Image(serverOperator.logo(colorScheme))
|
|
.resizable()
|
|
.scaledToFit()
|
|
.grayscale(serverOperator.enabled ? 0.0 : 1.0)
|
|
.frame(width: 24, height: 24)
|
|
Text(serverOperator.tradeName)
|
|
.foregroundColor(serverOperator.enabled ? theme.colors.onBackground : theme.colors.secondary)
|
|
|
|
if ss.servers.userServers[operatorIndex] != ss.servers.currUserServers[operatorIndex] {
|
|
Spacer()
|
|
unsavedChangesIndicator()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func unsavedChangesIndicator() -> some View {
|
|
Image(systemName: "pencil")
|
|
.foregroundColor(theme.colors.secondary)
|
|
.symbolRenderingMode(.monochrome)
|
|
.frame(maxWidth: 24, maxHeight: 24, alignment: .center)
|
|
}
|
|
|
|
private func conditionsButton(_ conditionsAction: UsageConditionsAction) -> some View {
|
|
Button {
|
|
sheetItem = .showConditions
|
|
} label: {
|
|
switch conditionsAction {
|
|
case .review:
|
|
Text("Review conditions")
|
|
case .accepted:
|
|
Text("Accepted conditions")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct UsageConditionsView: View {
|
|
@Environment(\.dismiss) var dismiss: DismissAction
|
|
@EnvironmentObject var theme: AppTheme
|
|
@Binding var currUserServers: [UserOperatorServers]
|
|
@Binding var userServers: [UserOperatorServers]
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 20) {
|
|
switch ChatModel.shared.conditions.conditionsAction {
|
|
|
|
case .none:
|
|
regularConditionsHeader()
|
|
.padding(.top)
|
|
.padding(.top)
|
|
ConditionsTextView()
|
|
.padding(.bottom)
|
|
.padding(.bottom)
|
|
|
|
case let .review(operators, deadline, _):
|
|
HStack {
|
|
Text("Updated conditions").font(.largeTitle).bold()
|
|
}
|
|
.padding(.top)
|
|
.padding(.top)
|
|
|
|
Text("Conditions will be accepted for the operator(s): **\(operators.map { $0.legalName_ }.joined(separator: ", "))**.")
|
|
ConditionsTextView()
|
|
VStack(spacing: 8) {
|
|
acceptConditionsButton(operators.map { $0.operatorId })
|
|
if let deadline = deadline {
|
|
Text("Conditions will be automatically accepted for enabled operators on: \(conditionsTimestamp(deadline)).")
|
|
.foregroundColor(theme.colors.secondary)
|
|
.font(.footnote)
|
|
.multilineTextAlignment(.center)
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
.padding(.horizontal, 32)
|
|
conditionsDiffButton(.footnote)
|
|
} else {
|
|
conditionsDiffButton()
|
|
.padding(.top)
|
|
}
|
|
}
|
|
.padding(.bottom)
|
|
.padding(.bottom)
|
|
|
|
|
|
case let .accepted(operators):
|
|
regularConditionsHeader()
|
|
.padding(.top)
|
|
.padding(.top)
|
|
Text("Conditions are accepted for the operator(s): **\(operators.map { $0.legalName_ }.joined(separator: ", "))**.")
|
|
ConditionsTextView()
|
|
.padding(.bottom)
|
|
.padding(.bottom)
|
|
}
|
|
}
|
|
.padding(.horizontal, 25)
|
|
.frame(maxHeight: .infinity)
|
|
}
|
|
|
|
private func acceptConditionsButton(_ operatorIds: [Int64]) -> some View {
|
|
Button {
|
|
acceptForOperators(operatorIds)
|
|
} label: {
|
|
Text("Accept conditions")
|
|
}
|
|
.buttonStyle(OnboardingButtonStyle())
|
|
}
|
|
|
|
func acceptForOperators(_ operatorIds: [Int64]) {
|
|
Task {
|
|
do {
|
|
let conditionsId = ChatModel.shared.conditions.currentConditions.conditionsId
|
|
let r = try await acceptConditions(conditionsId: conditionsId, operatorIds: operatorIds)
|
|
await MainActor.run {
|
|
ChatModel.shared.conditions = r
|
|
updateOperatorsConditionsAcceptance($currUserServers, r.serverOperators)
|
|
updateOperatorsConditionsAcceptance($userServers, r.serverOperators)
|
|
dismiss()
|
|
}
|
|
} catch let error {
|
|
await MainActor.run {
|
|
showAlert(
|
|
NSLocalizedString("Error accepting conditions", comment: "alert title"),
|
|
message: responseError(error)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@ViewBuilder private func conditionsDiffButton(_ font: Font? = nil) -> some View {
|
|
let commit = ChatModel.shared.conditions.currentConditions.conditionsCommit
|
|
if let commitUrl = URL(string: "https://github.com/simplex-chat/simplex-chat/commit/\(commit)") {
|
|
ExternalLink(destination: commitUrl) {
|
|
HStack {
|
|
Text("Open changes")
|
|
Image(systemName: "arrow.up.right.circle")
|
|
}
|
|
.font(font)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func regularConditionsHeader() -> some View {
|
|
HStack {
|
|
Text("Conditions of use").font(.largeTitle).bold()
|
|
Spacer()
|
|
conditionsLinkButton()
|
|
}
|
|
}
|
|
|
|
|
|
func validateServers_(
|
|
_ userServers: Binding<[UserOperatorServers]>,
|
|
_ serverErrors: Binding<[UserServersError]>,
|
|
_ serverWarnings: Binding<[UserServersWarning]>? = nil
|
|
) {
|
|
let userServersToValidate = userServers.wrappedValue
|
|
Task {
|
|
do {
|
|
let (errs, warns) = try await validateServers(userServers: userServersToValidate)
|
|
await MainActor.run {
|
|
serverErrors.wrappedValue = errs
|
|
serverWarnings?.wrappedValue = warns
|
|
}
|
|
} catch let error {
|
|
logger.error("validateServers error: \(responseError(error))")
|
|
}
|
|
}
|
|
}
|
|
|
|
func serversCanBeSaved(
|
|
_ currUserServers: [UserOperatorServers],
|
|
_ userServers: [UserOperatorServers],
|
|
_ serverErrors: [UserServersError]
|
|
) -> Bool {
|
|
return userServers != currUserServers && serverErrors.isEmpty
|
|
}
|
|
|
|
struct ServersErrorView: View {
|
|
@EnvironmentObject var theme: AppTheme
|
|
var errStr: String
|
|
|
|
var body: some View {
|
|
HStack {
|
|
Image(systemName: "exclamationmark.circle")
|
|
.foregroundColor(.red)
|
|
Text(errStr)
|
|
.foregroundColor(theme.colors.secondary)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ServersWarningView: View {
|
|
@EnvironmentObject var theme: AppTheme
|
|
var warnStr: String
|
|
|
|
var body: some View {
|
|
HStack {
|
|
Image(systemName: "exclamationmark.triangle")
|
|
.foregroundColor(.orange)
|
|
Text(warnStr)
|
|
.foregroundColor(theme.colors.secondary)
|
|
}
|
|
}
|
|
}
|
|
|
|
func globalServersError(_ serverErrors: [UserServersError]) -> String? {
|
|
for err in serverErrors {
|
|
if let errStr = err.globalError {
|
|
return errStr
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func globalServersWarning(_ serverWarnings: [UserServersWarning]) -> String? {
|
|
for warn in serverWarnings {
|
|
switch warn {
|
|
case let .noChatRelays(user):
|
|
let text = NSLocalizedString("No chat relays enabled.", comment: "servers warning")
|
|
if let user = user {
|
|
return String.localizedStringWithFormat(
|
|
NSLocalizedString("For chat profile %@:", comment: "servers warning"),
|
|
user.localDisplayName
|
|
) + " " + text
|
|
} else { return text }
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func bindingForChatRelays(_ userServers: Binding<[UserOperatorServers]>, _ opIndex: Int) -> Binding<[UserChatRelay]> {
|
|
Binding(
|
|
get: { userServers[opIndex].wrappedValue.chatRelays },
|
|
set: { userServers[opIndex].wrappedValue.chatRelays = $0 }
|
|
)
|
|
}
|
|
|
|
func globalSMPServersError(_ serverErrors: [UserServersError]) -> String? {
|
|
for err in serverErrors {
|
|
if let errStr = err.globalSMPError {
|
|
return errStr
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func globalXFTPServersError(_ serverErrors: [UserServersError]) -> String? {
|
|
for err in serverErrors {
|
|
if let errStr = err.globalXFTPError {
|
|
return errStr
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func findDuplicateHosts(_ serverErrors: [UserServersError]) -> Set<String> {
|
|
let duplicateHostsList = serverErrors.compactMap { err in
|
|
if case let .duplicateServer(_, _, duplicateHost) = err {
|
|
return duplicateHost
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
return Set(duplicateHostsList)
|
|
}
|
|
|
|
func findDuplicateRelayAddresses(_ serverErrors: [UserServersError]) -> Set<String> {
|
|
Set(serverErrors.compactMap { err in
|
|
if case let .duplicateChatRelayAddress(_, duplicateAddress) = err { return duplicateAddress }
|
|
else { return nil }
|
|
})
|
|
}
|
|
|
|
|
|
func saveServers(_ currUserServers: Binding<[UserOperatorServers]>, _ userServers: Binding<[UserOperatorServers]>) {
|
|
let userServersToSave = userServers.wrappedValue
|
|
Task {
|
|
do {
|
|
try await setUserServers(userServers: userServersToSave)
|
|
// Get updated servers to learn new server ids (otherwise it messes up delete of newly added and saved servers)
|
|
do {
|
|
let updatedServers = try await getUserServers()
|
|
let updatedOperators = try await getServerOperators()
|
|
await MainActor.run {
|
|
ChatModel.shared.conditions = updatedOperators
|
|
currUserServers.wrappedValue = updatedServers
|
|
userServers.wrappedValue = updatedServers
|
|
}
|
|
} catch let error {
|
|
logger.error("saveServers getUserServers error: \(responseError(error))")
|
|
await MainActor.run {
|
|
currUserServers.wrappedValue = userServersToSave
|
|
}
|
|
}
|
|
} catch let error {
|
|
logger.error("saveServers setUserServers error: \(responseError(error))")
|
|
await MainActor.run {
|
|
showAlert(
|
|
NSLocalizedString("Error saving servers", comment: "alert title"),
|
|
message: responseError(error)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func updateOperatorsConditionsAcceptance(_ usvs: Binding<[UserOperatorServers]>, _ updatedOperators: [ServerOperator]) {
|
|
for i in 0..<usvs.wrappedValue.count {
|
|
if let updatedOperator = updatedOperators.first(where: { $0.operatorId == usvs.wrappedValue[i].operator?.operatorId }) {
|
|
usvs.wrappedValue[i].operator?.conditionsAcceptance = updatedOperator.conditionsAcceptance
|
|
}
|
|
}
|
|
}
|
|
|
|
struct NetworkServersView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
NetworkAndServers()
|
|
}
|
|
}
|