damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit d4068f8d52358f67e2ade1e247b64ccde644508b
parent 7d410bff346a27ea6803ef3178bbbdb09fef01d6
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 30 Jan 2023 15:49:03 -0800

Move Relay configuration to its own section on the sidebar

Changelog-Changed: Moved relay config to its own sidebar entry

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 20++++++++++++++++----
Mdamus/Views/ConfigView.swift | 78------------------------------------------------------------------------------
Rdamus/Views/RecommendedRelayView.swift -> damus/Views/Relays/RecommendedRelayView.swift | 0
Adamus/Views/Relays/RelayConfigView.swift | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rdamus/Views/RelayView.swift -> damus/Views/Relays/RelayView.swift | 0
Mdamus/Views/SideMenuView.swift | 6++++++
6 files changed, 131 insertions(+), 82 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -118,6 +118,7 @@ 4C99737B28C92A9200E53835 /* ChatroomMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C99737A28C92A9200E53835 /* ChatroomMetadata.swift */; }; 4CA2EFA0280E37AC0044ACD8 /* TimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */; }; 4CAAD8AD298851D000060CEA /* AccountDeletion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CAAD8AC298851D000060CEA /* AccountDeletion.swift */; }; + 4CAAD8B029888AD200060CEA /* RelayConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CAAD8AF29888AD200060CEA /* RelayConfigView.swift */; }; 4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */; }; 4CACA9DC280C38C000D9BBE8 /* Profiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9DB280C38C000D9BBE8 /* Profiles.swift */; }; 4CB55EF3295E5D59007FD187 /* RecommendedRelayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */; }; @@ -175,8 +176,8 @@ 4CF0ABF029857E9200D66079 /* Bech32Object.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CF0ABEF29857E9200D66079 /* Bech32Object.swift */; }; 4CF0ABF62985CD5500D66079 /* UserSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CF0ABF52985CD5500D66079 /* UserSearch.swift */; }; 4FE60CDD295E1C5E00105A1F /* Wallet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE60CDC295E1C5E00105A1F /* Wallet.swift */; }; - 5C513FCC2984ACA60072348F /* QRCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C513FCB2984ACA60072348F /* QRCodeView.swift */; }; 5C513FBA297F72980072348F /* CustomPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C513FB9297F72980072348F /* CustomPicker.swift */; }; + 5C513FCC2984ACA60072348F /* QRCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C513FCB2984ACA60072348F /* QRCodeView.swift */; }; 6439E014296790CF0020672B /* ProfileZoomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6439E013296790CF0020672B /* ProfileZoomView.swift */; }; 647D9A8D2968520300A295DE /* SideMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647D9A8C2968520300A295DE /* SideMenuView.swift */; }; 64FBD06F296255C400D9D3B2 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64FBD06E296255C400D9D3B2 /* Theme.swift */; }; @@ -380,6 +381,7 @@ 4C99737A28C92A9200E53835 /* ChatroomMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatroomMetadata.swift; sourceTree = "<group>"; }; 4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineView.swift; sourceTree = "<group>"; }; 4CAAD8AC298851D000060CEA /* AccountDeletion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountDeletion.swift; sourceTree = "<group>"; }; + 4CAAD8AF29888AD200060CEA /* RelayConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayConfigView.swift; sourceTree = "<group>"; }; 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyView.swift; sourceTree = "<group>"; }; 4CACA9DB280C38C000D9BBE8 /* Profiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profiles.swift; sourceTree = "<group>"; }; 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendedRelayView.swift; sourceTree = "<group>"; }; @@ -440,8 +442,8 @@ 4CF0ABEF29857E9200D66079 /* Bech32Object.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bech32Object.swift; sourceTree = "<group>"; }; 4CF0ABF52985CD5500D66079 /* UserSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSearch.swift; sourceTree = "<group>"; }; 4FE60CDC295E1C5E00105A1F /* Wallet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wallet.swift; sourceTree = "<group>"; }; - 5C513FCB2984ACA60072348F /* QRCodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeView.swift; sourceTree = "<group>"; }; 5C513FB9297F72980072348F /* CustomPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomPicker.swift; sourceTree = "<group>"; }; + 5C513FCB2984ACA60072348F /* QRCodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeView.swift; sourceTree = "<group>"; }; 6439E013296790CF0020672B /* ProfileZoomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileZoomView.swift; sourceTree = "<group>"; }; 647D9A8C2968520300A295DE /* SideMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenuView.swift; sourceTree = "<group>"; }; 64FBD06E296255C400D9D3B2 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; }; @@ -602,6 +604,7 @@ 4C75EFA227FA576C0006080F /* Views */ = { isa = PBXGroup; children = ( + 4CAAD8AE29888A9B00060CEA /* Relays */, 4CF0ABF42985CD4200D66079 /* Posting */, 4CF0ABDF2981A83000D66079 /* Muting */, 4CC7AAEE297F11B300430951 /* Events */, @@ -636,8 +639,6 @@ 4C8682862814DE470026224F /* ProfileView.swift */, 4C3AC7A42836987600E1F516 /* MainTabView.swift */, 4C363A8B28236B92006E126D /* PubkeyView.swift */, - 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */, - 4C06670028FC7C5900038D2A /* RelayView.swift */, 4C0A3F94280F6C78000448DE /* ReplyQuoteView.swift */, 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */, F7F0BA262978E54D009531F3 /* ParicipantsView.swift */, @@ -709,6 +710,16 @@ path = Util; sourceTree = "<group>"; }; + 4CAAD8AE29888A9B00060CEA /* Relays */ = { + isa = PBXGroup; + children = ( + 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */, + 4C06670028FC7C5900038D2A /* RelayView.swift */, + 4CAAD8AF29888AD200060CEA /* RelayConfigView.swift */, + ); + path = Relays; + sourceTree = "<group>"; + }; 4CB88387296AF97C00DC99E7 /* ActionBar */ = { isa = PBXGroup; children = ( @@ -1139,6 +1150,7 @@ 4C3EA66528FF5F6800C48A62 /* mem.c in Sources */, 4CF0ABE52981EE0C00D66079 /* EULAView.swift in Sources */, 4CBCA930297DB57F00EC6B2F /* WebsiteLink.swift in Sources */, + 4CAAD8B029888AD200060CEA /* RelayConfigView.swift in Sources */, 4C3EA64128FF553900C48A62 /* hash_u5.c in Sources */, 5C513FCC2984ACA60072348F /* QRCodeView.swift in Sources */, 4C3EA64F28FF59F200C48A62 /* tal.c in Sources */, diff --git a/damus/Views/ConfigView.swift b/damus/Views/ConfigView.swift @@ -11,16 +11,13 @@ import Kingfisher struct ConfigView: View { let state: DamusState @Environment(\.dismiss) var dismiss - @State var show_add_relay: Bool = false @State var confirm_logout: Bool = false @State var confirm_delete_account: Bool = false - @State var new_relay: String = "" @State var show_privkey: Bool = false @State var show_libretranslate_api_key: Bool = false @State var privkey: String @State var privkey_copied: Bool = false @State var pubkey_copied: Bool = false - @State var relays: [RelayDescriptor] @State var delete_text: String = "" @EnvironmentObject var user_settings: UserSettingsStore @@ -29,7 +26,6 @@ struct ConfigView: View { init(state: DamusState) { self.state = state _privkey = State(initialValue: self.state.keypair.privkey_bech32 ?? "") - _relays = State(initialValue: state.pool.descriptors) } // TODO: (jb55) could be more general but not gonna worry about it atm @@ -45,41 +41,9 @@ struct ConfigView: View { } } - var recommended: [RelayDescriptor] { - let rs: [RelayDescriptor] = [] - return BOOTSTRAP_RELAYS.reduce(into: rs) { (xs, x) in - if let _ = state.pool.get_relay(x) { - } else { - xs.append(RelayDescriptor(url: URL(string: x)!, info: .rw)) - } - } - } - var body: some View { ZStack(alignment: .leading) { Form { - Section { - List(Array(relays), id: \.url) { relay in - RelayView(state: state, relay: relay.url.absoluteString) - } - } header: { - HStack { - Text("Relays", comment: "Header text for relay server list for configuration.") - Spacer() - Button(action: { show_add_relay = true }) { - Image(systemName: "plus") - .foregroundColor(.accentColor) - } - } - } - - if recommended.count > 0 { - Section(NSLocalizedString("Recommended Relays", comment: "Section title for recommend relay servers that could be added as part of configuration")) { - List(recommended, id: \.url) { r in - RecommendedRelayView(damus: state, relay: r.url.absoluteString) - } - } - } Section(NSLocalizedString("Public Account ID", comment: "Section title for the user's public account ID.")) { HStack { @@ -209,51 +173,9 @@ struct ConfigView: View { } message: { Text("Make sure your nsec account key is saved before you logout or you will lose access to this account", comment: "Reminder message in alert to get customer to verify that their private security account key is saved saved before logging out.") } - .sheet(isPresented: $show_add_relay) { - AddRelayView(show_add_relay: $show_add_relay, relay: $new_relay) { m_relay in - guard var relay = m_relay else { - return - } - - if relay.starts(with: "wss://") == false && relay.starts(with: "ws://") == false { - relay = "wss://" + relay - } - - guard let url = URL(string: relay) else { - return - } - - guard let ev = state.contacts.event else { - return - } - - guard let privkey = state.keypair.privkey else { - return - } - - let info = RelayInfo.rw - - guard (try? state.pool.add_relay(url, info: info)) != nil else { - return - } - - state.pool.connect(to: [relay]) - - guard let new_ev = add_relay(ev: ev, privkey: privkey, current_relays: state.pool.descriptors, relay: relay, info: info) else { - return - } - - process_contact_event(pool: state.pool, contacts: state.contacts, pubkey: state.pubkey, ev: ev) - - state.pool.send(.event(new_ev)) - } - } .onReceive(handle_notify(.switched_timeline)) { _ in dismiss() } - .onReceive(handle_notify(.relays_changed)) { _ in - self.relays = state.pool.descriptors - } } } diff --git a/damus/Views/RecommendedRelayView.swift b/damus/Views/Relays/RecommendedRelayView.swift diff --git a/damus/Views/Relays/RelayConfigView.swift b/damus/Views/Relays/RelayConfigView.swift @@ -0,0 +1,109 @@ +// +// RelayConfigView.swift +// damus +// +// Created by William Casarin on 2023-01-30. +// + +import SwiftUI + +struct RelayConfigView: View { + let state: DamusState + @State var new_relay: String = "" + @State var show_add_relay: Bool = false + @State var relays: [RelayDescriptor] + + init(state: DamusState) { + self.state = state + _relays = State(initialValue: state.pool.descriptors) + } + + var recommended: [RelayDescriptor] { + let rs: [RelayDescriptor] = [] + return BOOTSTRAP_RELAYS.reduce(into: rs) { (xs, x) in + if let _ = state.pool.get_relay(x) { + } else { + xs.append(RelayDescriptor(url: URL(string: x)!, info: .rw)) + } + } + } + + var body: some View { + MainContent + .onReceive(handle_notify(.relays_changed)) { _ in + self.relays = state.pool.descriptors + } + .sheet(isPresented: $show_add_relay) { + AddRelayView(show_add_relay: $show_add_relay, relay: $new_relay) { m_relay in + guard var relay = m_relay else { + return + } + + if relay.starts(with: "wss://") == false && relay.starts(with: "ws://") == false { + relay = "wss://" + relay + } + + guard let url = URL(string: relay) else { + return + } + + guard let ev = state.contacts.event else { + return + } + + guard let privkey = state.keypair.privkey else { + return + } + + let info = RelayInfo.rw + + guard (try? state.pool.add_relay(url, info: info)) != nil else { + return + } + + state.pool.connect(to: [relay]) + + guard let new_ev = add_relay(ev: ev, privkey: privkey, current_relays: state.pool.descriptors, relay: relay, info: info) else { + return + } + + process_contact_event(pool: state.pool, contacts: state.contacts, pubkey: state.pubkey, ev: ev) + + state.pool.send(.event(new_ev)) + } + } + } + + var MainContent: some View { + Form { + Section { + List(Array(relays), id: \.url) { relay in + RelayView(state: state, relay: relay.url.absoluteString) + } + } header: { + HStack { + Text("Relays", comment: "Header text for relay server list for configuration.") + Spacer() + Button(action: { show_add_relay = true }) { + Image(systemName: "plus") + .foregroundColor(.accentColor) + } + } + } + + if recommended.count > 0 { + Section(NSLocalizedString("Recommended Relays", comment: "Section title for recommend relay servers that could be added as part of configuration")) { + List(recommended, id: \.url) { r in + RecommendedRelayView(damus: state, relay: r.url.absoluteString) + } + } + } + } + } +} + +struct RelayConfigView_Previews: PreviewProvider { + static var previews: some View { + RelayConfigView(state: test_damus_state()) + } +} diff --git a/damus/Views/RelayView.swift b/damus/Views/Relays/RelayView.swift diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift @@ -115,6 +115,12 @@ struct SideMenuView: View { .foregroundColor(textColor()) } + NavigationLink(destination: RelayConfigView(state: damus_state)) { + Label(NSLocalizedString("Relays", comment: "Sidebar menu label for Relays view."), systemImage: "network") + .font(.title2) + .foregroundColor(textColor()) + } + NavigationLink(destination: ConfigView(state: damus_state).environmentObject(user_settings)) { Label(NSLocalizedString("Settings", comment: "Sidebar menu label for accessing the app settings"), systemImage: "gear") .font(.title2)