From 4e5aa3dcbc083b57e63ecc46d5f806f7741ce726 Mon Sep 17 00:00:00 2001 From: JRoberts <8711996+jr-simplex@users.noreply.github.com> Date: Thu, 17 Nov 2022 12:59:13 +0400 Subject: [PATCH] ios: adjust preferences UX; fix group profile not updating; fix servers api (#1377) --- apps/ios/Shared/Model/SimpleXAPI.swift | 2 +- apps/ios/Shared/Views/Chat/ChatInfoView.swift | 31 ++++++----- .../Views/Chat/ContactPreferencesView.swift | 4 +- .../Views/Chat/Group/GroupChatInfoView.swift | 52 +++++++++++-------- .../Views/Chat/Group/GroupLinkView.swift | 4 -- .../Chat/Group/GroupPreferencesView.swift | 4 +- .../Views/Chat/Group/GroupProfileView.swift | 7 +-- .../Views/UserSettings/PreferencesView.swift | 4 +- apps/ios/SimpleXChat/APITypes.swift | 4 +- 9 files changed, 56 insertions(+), 56 deletions(-) diff --git a/apps/ios/Shared/Model/SimpleXAPI.swift b/apps/ios/Shared/Model/SimpleXAPI.swift index 8335c7dfc4..4ee70bc0bc 100644 --- a/apps/ios/Shared/Model/SimpleXAPI.swift +++ b/apps/ios/Shared/Model/SimpleXAPI.swift @@ -311,7 +311,7 @@ func apiDeleteToken(token: DeviceToken) async throws { func getUserSMPServers() throws -> [String] { let r = chatSendCmdSync(.getUserSMPServers) - if case let .userSMPServers(smpServers) = r { return smpServers } + if case let .userSMPServers(smpServers, _) = r { return smpServers.map { $0.server } } throw r } diff --git a/apps/ios/Shared/Views/Chat/ChatInfoView.swift b/apps/ios/Shared/Views/Chat/ChatInfoView.swift index 3f2e3f8ffa..da609d10bd 100644 --- a/apps/ios/Shared/Views/Chat/ChatInfoView.swift +++ b/apps/ios/Shared/Views/Chat/ChatInfoView.swift @@ -99,20 +99,8 @@ struct ChatInfoView: View { } } - Section("Preferences") { - NavigationLink { - ContactPreferencesView( - contact: $contact, - featuresAllowed: contactUserPrefsToFeaturesAllowed(contact.mergedPreferences), - currentFeaturesAllowed: contactUserPrefsToFeaturesAllowed(contact.mergedPreferences) - ) - .navigationBarTitle("Contact preferences") - .navigationBarTitleDisplayMode(.large) - } label: { - settingsRow("switch.2") { - Text("Contact preferences") - } - } + Section { + contactPreferencesButton() } Section("Servers") { @@ -208,6 +196,21 @@ struct ChatInfoView: View { } } + func contactPreferencesButton() -> some View { + NavigationLink { + ContactPreferencesView( + contact: $contact, + featuresAllowed: contactUserPrefsToFeaturesAllowed(contact.mergedPreferences), + currentFeaturesAllowed: contactUserPrefsToFeaturesAllowed(contact.mergedPreferences) + ) + .navigationBarTitle("Contact preferences") + .navigationBarTitleDisplayMode(.large) + } label: { + Label("Contact preferences", systemImage: "switch.2") + .foregroundColor(.accentColor) + } + } + func networkStatusRow() -> some View { HStack { Text("Network status") diff --git a/apps/ios/Shared/Views/Chat/ContactPreferencesView.swift b/apps/ios/Shared/Views/Chat/ContactPreferencesView.swift index 32fe15c41c..8e12e16ea4 100644 --- a/apps/ios/Shared/Views/Chat/ContactPreferencesView.swift +++ b/apps/ios/Shared/Views/Chat/ContactPreferencesView.swift @@ -11,7 +11,6 @@ import SimpleXChat struct ContactPreferencesView: View { @EnvironmentObject var chatModel: ChatModel - @Environment(\.dismiss) var dismiss: DismissAction @Binding var contact: Contact @State var featuresAllowed: ContactFeaturesAllowed @State var currentFeaturesAllowed: ContactFeaturesAllowed @@ -25,7 +24,7 @@ struct ContactPreferencesView: View { featureSection(.voice, user.fullPreferences.voice.allow, contact.mergedPreferences.voice, $featuresAllowed.voice) Section { - Button("Reset", role: .destructive) { featuresAllowed = currentFeaturesAllowed } + Button("Reset") { featuresAllowed = currentFeaturesAllowed } Button("Save (and notify contact)") { savePreferences() } } .disabled(currentFeaturesAllowed == featuresAllowed) @@ -67,7 +66,6 @@ struct ContactPreferencesView: View { contact = toContact chatModel.updateContact(toContact) currentFeaturesAllowed = featuresAllowed - dismiss() } } } catch { diff --git a/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift b/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift index d3028bb2e5..a53b618873 100644 --- a/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift +++ b/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift @@ -19,7 +19,6 @@ struct GroupChatInfoView: View { @State private var groupLink: String? @State private var showAddMembersSheet: Bool = false @State private var selectedMember: GroupMember? = nil - @State private var showGroupProfile: Bool = false @State private var connectionStats: ConnectionStats? @AppStorage(DEFAULT_DEVELOPER_TOOLS) private var developerTools = false @@ -43,21 +42,12 @@ struct GroupChatInfoView: View { .listRowBackground(Color.clear) Section { - NavigationLink { - GroupPreferencesView( - groupInfo: $groupInfo, - preferences: groupInfo.fullGroupPreferences, - currentPreferences: groupInfo.fullGroupPreferences - ) - .navigationBarTitle("Group preferences") - .navigationBarTitleDisplayMode(.large) - } label: { - settingsRow("switch.2") { - Text("Group preferences") - } + if groupInfo.canEdit { + editGroupButton() } + groupPreferencesButton() } header: { - Text("Preferences") + Text("") } footer: { Text("Only group owners can change group preferences.") } @@ -97,14 +87,8 @@ struct GroupChatInfoView: View { }) { _ in GroupMemberInfoView(groupInfo: groupInfo, member: $selectedMember, connectionStats: $connectionStats) } - .sheet(isPresented: $showGroupProfile) { - GroupProfileView(groupId: groupInfo.apiId, groupProfile: groupInfo.groupProfile) - } Section { - if groupInfo.canEdit { - editGroupButton() - } clearChatButton() if groupInfo.canDelete { deleteGroupButton() @@ -209,18 +193,40 @@ struct GroupChatInfoView: View { private func groupLinkButton() -> some View { NavigationLink { GroupLinkView(groupId: groupInfo.groupId, groupLink: $groupLink) - .navigationBarTitleDisplayMode(.inline) + .navigationBarTitle("Group link") + .navigationBarTitleDisplayMode(.large) } label: { Label("Group link", systemImage: "link") .foregroundColor(.accentColor) } } + func groupPreferencesButton() -> some View { + NavigationLink { + GroupPreferencesView( + groupInfo: $groupInfo, + preferences: groupInfo.fullGroupPreferences, + currentPreferences: groupInfo.fullGroupPreferences + ) + .navigationBarTitle("Group preferences") + .navigationBarTitleDisplayMode(.large) + } label: { + Label("Group preferences", systemImage: "switch.2") + .foregroundColor(.accentColor) + } + } + func editGroupButton() -> some View { - Button { - showGroupProfile = true + NavigationLink { + GroupProfileView( + groupInfo: $groupInfo, + groupProfile: groupInfo.groupProfile + ) + .navigationBarTitle("Group profile") + .navigationBarTitleDisplayMode(.large) } label: { Label("Edit group profile", systemImage: "pencil") + .foregroundColor(.accentColor) } } diff --git a/apps/ios/Shared/Views/Chat/Group/GroupLinkView.swift b/apps/ios/Shared/Views/Chat/Group/GroupLinkView.swift index 5e4b5bee78..d9bd8e0c31 100644 --- a/apps/ios/Shared/Views/Chat/Group/GroupLinkView.swift +++ b/apps/ios/Shared/Views/Chat/Group/GroupLinkView.swift @@ -29,10 +29,6 @@ struct GroupLinkView: View { var body: some View { ScrollView { VStack (alignment: .leading) { - Text("Group link") - .font(.largeTitle) - .bold() - .padding(.bottom) Text("You can share a link or a QR code - anybody will be able to join the group. You won't lose members of the group if you later delete it.") .padding(.bottom) if let groupLink = groupLink { diff --git a/apps/ios/Shared/Views/Chat/Group/GroupPreferencesView.swift b/apps/ios/Shared/Views/Chat/Group/GroupPreferencesView.swift index dd546666de..97fa2111aa 100644 --- a/apps/ios/Shared/Views/Chat/Group/GroupPreferencesView.swift +++ b/apps/ios/Shared/Views/Chat/Group/GroupPreferencesView.swift @@ -11,7 +11,6 @@ import SimpleXChat struct GroupPreferencesView: View { @EnvironmentObject var chatModel: ChatModel - @Environment(\.dismiss) var dismiss: DismissAction @Binding var groupInfo: GroupInfo @State var preferences: FullGroupPreferences @State var currentPreferences: FullGroupPreferences @@ -24,7 +23,7 @@ struct GroupPreferencesView: View { if groupInfo.canEdit { Section { - Button("Reset", role: .destructive) { preferences = currentPreferences } + Button("Reset") { preferences = currentPreferences } Button("Save (and notify group members)") { savePreferences() } } .disabled(currentPreferences == preferences) @@ -66,7 +65,6 @@ struct GroupPreferencesView: View { groupInfo = gInfo chatModel.updateGroup(gInfo) currentPreferences = preferences - dismiss() } } catch { logger.error("GroupPreferencesView apiUpdateGroup error: \(responseError(error))") diff --git a/apps/ios/Shared/Views/Chat/Group/GroupProfileView.swift b/apps/ios/Shared/Views/Chat/Group/GroupProfileView.swift index 3d950aead6..32adf861f3 100644 --- a/apps/ios/Shared/Views/Chat/Group/GroupProfileView.swift +++ b/apps/ios/Shared/Views/Chat/Group/GroupProfileView.swift @@ -12,7 +12,7 @@ import SimpleXChat struct GroupProfileView: View { @EnvironmentObject var chatModel: ChatModel @Environment(\.dismiss) var dismiss: DismissAction - var groupId: Int64 + @Binding var groupInfo: GroupInfo @State var groupProfile: GroupProfile @State private var showChooseSource = false @State private var showImagePicker = false @@ -120,8 +120,9 @@ struct GroupProfileView: View { func saveProfile() { Task { do { - let gInfo = try await apiUpdateGroup(groupId, groupProfile) + let gInfo = try await apiUpdateGroup(groupInfo.groupId, groupProfile) await MainActor.run { + groupInfo = gInfo chatModel.updateGroup(gInfo) dismiss() } @@ -137,6 +138,6 @@ struct GroupProfileView: View { struct GroupProfileView_Previews: PreviewProvider { static var previews: some View { - GroupProfileView(groupId: 1, groupProfile: GroupProfile.sampleData) + GroupProfileView(groupInfo: Binding.constant(GroupInfo.sampleData), groupProfile: GroupProfile.sampleData) } } diff --git a/apps/ios/Shared/Views/UserSettings/PreferencesView.swift b/apps/ios/Shared/Views/UserSettings/PreferencesView.swift index 5db7c3724d..269839d29b 100644 --- a/apps/ios/Shared/Views/UserSettings/PreferencesView.swift +++ b/apps/ios/Shared/Views/UserSettings/PreferencesView.swift @@ -11,7 +11,6 @@ import SimpleXChat struct PreferencesView: View { @EnvironmentObject var chatModel: ChatModel - @Environment(\.dismiss) var dismiss: DismissAction @State var profile: LocalProfile @State var preferences: FullPreferences @State var currentPreferences: FullPreferences @@ -23,7 +22,7 @@ struct PreferencesView: View { featureSection(.voice, $preferences.voice.allow) Section { - Button("Reset", role: .destructive) { preferences = currentPreferences } + Button("Reset") { preferences = currentPreferences } Button("Save (and notify contacts)") { savePreferences() } } .disabled(currentPreferences == preferences) @@ -59,7 +58,6 @@ struct PreferencesView: View { chatModel.currentUser?.fullPreferences = preferences } currentPreferences = preferences - dismiss() } } } catch { diff --git a/apps/ios/SimpleXChat/APITypes.swift b/apps/ios/SimpleXChat/APITypes.swift index 518c7390a6..83c1dd2d74 100644 --- a/apps/ios/SimpleXChat/APITypes.swift +++ b/apps/ios/SimpleXChat/APITypes.swift @@ -294,7 +294,7 @@ public enum ChatResponse: Decodable, Error { case chatSuspended case apiChats(chats: [ChatData]) case apiChat(chat: ChatData) - case userSMPServers(smpServers: [String]) + case userSMPServers(smpServers: [ServerCfg], presetSMPServers: [String]) case sMPTestResult(smpTestFailure: SMPTestFailure?) case chatItemTTL(chatItemTTL: Int64?) case networkConfig(networkConfig: NetCfg) @@ -500,7 +500,7 @@ public enum ChatResponse: Decodable, Error { case .chatSuspended: return noDetails case let .apiChats(chats): return String(describing: chats) case let .apiChat(chat): return String(describing: chat) - case let .userSMPServers(smpServers): return String(describing: smpServers) + case let .userSMPServers(smpServers, _): return String(describing: smpServers) case let .sMPTestResult(smpTestFailure): return String(describing: smpTestFailure) case let .chatItemTTL(chatItemTTL): return String(describing: chatItemTTL) case let .networkConfig(networkConfig): return String(describing: networkConfig)