ios: adjust preferences UX; fix group profile not updating; fix servers api (#1377)

This commit is contained in:
JRoberts
2022-11-17 12:59:13 +04:00
committed by GitHub
parent 56f3874a93
commit 4e5aa3dcbc
9 changed files with 56 additions and 56 deletions

View File

@@ -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
}

View File

@@ -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")

View File

@@ -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 {

View File

@@ -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)
}
}

View File

@@ -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 {

View File

@@ -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))")

View File

@@ -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)
}
}

View File

@@ -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 {

View File

@@ -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)