damus

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

commit 289d55b918919cb5174fb20eaa9421d4cebfaf51
parent 771fa845e377313c4b0587c8bc082f623f92887c
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 10 Feb 2023 09:35:59 -0800

Show paid or global relay type next to relay status

Changelog-Added: Show if relay is paid

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 12++++++++++++
Mdamus/Views/RelayFilterView.swift | 17+----------------
Mdamus/Views/Relays/RelayDetailView.swift | 7++-----
Adamus/Views/Relays/RelayStatus.swift | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Adamus/Views/Relays/RelayToggle.swift | 42++++++++++++++++++++++++++++++++++++++++++
Adamus/Views/Relays/RelayType.swift | 27+++++++++++++++++++++++++++
Mdamus/Views/Relays/RelayView.swift | 47++++++++++++-----------------------------------
7 files changed, 146 insertions(+), 56 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -169,6 +169,9 @@ 4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE6DF1527F8DEBF00C66700 /* RelayConnection.swift */; }; 4CE8794829941DA700F758CC /* RelayFilters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8794729941DA700F758CC /* RelayFilters.swift */; }; 4CE8794C2995B59E00F758CC /* RelayMetadatas.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8794B2995B59E00F758CC /* RelayMetadatas.swift */; }; + 4CE8794E2996B16A00F758CC /* RelayToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8794D2996B16A00F758CC /* RelayToggle.swift */; }; + 4CE879502996B2BD00F758CC /* RelayStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8794F2996B2BD00F758CC /* RelayStatus.swift */; }; + 4CE879522996B68900F758CC /* RelayType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE879512996B68900F758CC /* RelayType.swift */; }; 4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */; }; 4CEE2AF1280B216B00AB5EEF /* EventDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */; }; 4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */; }; @@ -461,6 +464,9 @@ 4CE6DF1527F8DEBF00C66700 /* RelayConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayConnection.swift; sourceTree = "<group>"; }; 4CE8794729941DA700F758CC /* RelayFilters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayFilters.swift; sourceTree = "<group>"; }; 4CE8794B2995B59E00F758CC /* RelayMetadatas.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayMetadatas.swift; sourceTree = "<group>"; }; + 4CE8794D2996B16A00F758CC /* RelayToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayToggle.swift; sourceTree = "<group>"; }; + 4CE8794F2996B2BD00F758CC /* RelayStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayStatus.swift; sourceTree = "<group>"; }; + 4CE879512996B68900F758CC /* RelayType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayType.swift; sourceTree = "<group>"; }; 4CEE2AE72804F57C00AB5EEF /* libsecp256k1.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsecp256k1.a; sourceTree = "<group>"; }; 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrRequest.swift; sourceTree = "<group>"; }; 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventDetailView.swift; sourceTree = "<group>"; }; @@ -771,6 +777,9 @@ 4C06670028FC7C5900038D2A /* RelayView.swift */, 4CAAD8AF29888AD200060CEA /* RelayConfigView.swift */, F7908E91298B0F0700AB113A /* RelayDetailView.swift */, + 4CE8794D2996B16A00F758CC /* RelayToggle.swift */, + 4CE8794F2996B2BD00F758CC /* RelayStatus.swift */, + 4CE879512996B68900F758CC /* RelayType.swift */, ); path = Relays; sourceTree = "<group>"; @@ -1219,6 +1228,7 @@ 4CC7AAF8297F1CEE00430951 /* EventProfile.swift in Sources */, 64FBD06F296255C400D9D3B2 /* Theme.swift in Sources */, 4C3EA64928FF597700C48A62 /* bech32.c in Sources */, + 4CE879522996B68900F758CC /* RelayType.swift in Sources */, 4C90BD162839DB54008EE7EF /* NostrMetadata.swift in Sources */, 4C3A1D3729637E0500558C0F /* PreviewCache.swift in Sources */, 4C3EA67528FF7A5A00C48A62 /* take.c in Sources */, @@ -1280,6 +1290,7 @@ 4C3BEFDA281DCA1400B3DE84 /* LikeCounter.swift in Sources */, 4CB88389296AF99A00DC99E7 /* EventDetailBar.swift in Sources */, 4CF0ABDE2981A69500D66079 /* MutelistModel.swift in Sources */, + 4CE8794E2996B16A00F758CC /* RelayToggle.swift in Sources */, 4C3AC79B28306D7B00E1F516 /* Contacts.swift in Sources */, 4C3EA63D28FF52D600C48A62 /* bolt11.c in Sources */, 4CB55EF3295E5D59007FD187 /* RecommendedRelayView.swift in Sources */, @@ -1300,6 +1311,7 @@ 4FE60CDD295E1C5E00105A1F /* Wallet.swift in Sources */, 3AA247FF297E3D900090C62D /* RepostsView.swift in Sources */, 3AE45AF6297BB2E700C1D842 /* LibreTranslateServer.swift in Sources */, + 4CE879502996B2BD00F758CC /* RelayStatus.swift in Sources */, 4C99737B28C92A9200E53835 /* ChatroomMetadata.swift in Sources */, 4CC7AAF4297F18B400430951 /* ReplyDescription.swift in Sources */, 4C75EFA427FA577B0006080F /* PostView.swift in Sources */, diff --git a/damus/Views/RelayFilterView.swift b/damus/Views/RelayFilterView.swift @@ -25,18 +25,6 @@ struct RelayFilterView: View { return state.pool.descriptors } - func toggle_binding(relay_id: String) -> Binding<Bool> { - return Binding(get: { - !state.relay_filters.is_filtered(timeline: timeline, relay_id: relay_id) - }, set: { on in - if !on { - state.relay_filters.insert(timeline: timeline, relay_id: relay_id) - } else { - state.relay_filters.remove(timeline: timeline, relay_id: relay_id) - } - }) - } - var body: some View { Text("To filter your \(timeline.rawValue) feed, please choose applicable relays from the list below:") .padding() @@ -44,10 +32,7 @@ struct RelayFilterView: View { .padding(.bottom, 0) List(Array(relays), id: \.url) { relay in - //RelayView(state: state, relay: relay.url.absoluteString) - let relay_id = relay.url.absoluteString - Toggle(relay_id, isOn: toggle_binding(relay_id: relay_id)) - .toggleStyle(SwitchToggleStyle(tint: .accentColor)) + RelayToggle(state: state, timeline: timeline, relay_id: relay.url.absoluteString) } } } diff --git a/damus/Views/Relays/RelayDetailView.swift b/damus/Views/Relays/RelayDetailView.swift @@ -13,7 +13,6 @@ struct RelayDetailView: View { let nip11: RelayMetadata @State private var errorString: String? - @State var conn_color: Color @Environment(\.dismiss) var dismiss @@ -34,9 +33,7 @@ struct RelayDetailView: View { HStack { Text(relay) Spacer() - Circle() - .frame(width: 8.0, height: 8.0) - .foregroundColor(conn_color) + RelayStatus(pool: state.pool, relay: relay) } } Section(NSLocalizedString("Description", comment: "Label to display relay description.")) { @@ -92,6 +89,6 @@ struct RelayDetailView: View { struct RelayDetailView_Previews: PreviewProvider { static var previews: some View { let metadata = RelayMetadata(name: "name", description: "desc", pubkey: "pubkey", contact: "contact", supported_nips: [1,2,3], software: "software", version: "version", limitation: Limitations.empty) - RelayDetailView(state: test_damus_state(), relay: "relay", nip11: metadata, conn_color: .green) + RelayDetailView(state: test_damus_state(), relay: "relay", nip11: metadata) } } diff --git a/damus/Views/Relays/RelayStatus.swift b/damus/Views/Relays/RelayStatus.swift @@ -0,0 +1,50 @@ +// +// RelayStatus.swift +// damus +// +// Created by William Casarin on 2023-02-10. +// + +import SwiftUI + +struct RelayStatus: View { + let pool: RelayPool + let relay: String + + let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect() + + @State var conn_color: Color = .gray + + func update_connection_color() { + for relay in pool.relays { + if relay.id == self.relay { + let c = relay.connection + if c.isConnected { + conn_color = .green + } else if c.isConnecting || c.isReconnecting { + conn_color = .yellow + } else { + conn_color = .red + } + } + } + } + + var body: some View { + Circle() + .frame(width: 8.0, height: 8.0) + .foregroundColor(conn_color) + .onReceive(timer) { _ in + update_connection_color() + } + .onAppear() { + update_connection_color() + } + } +} + +struct RelayStatus_Previews: PreviewProvider { + static var previews: some View { + RelayStatus(pool: test_damus_state().pool, relay: "relay") + } +} diff --git a/damus/Views/Relays/RelayToggle.swift b/damus/Views/Relays/RelayToggle.swift @@ -0,0 +1,42 @@ +// +// RelayToggle.swift +// damus +// +// Created by William Casarin on 2023-02-10. +// + +import SwiftUI + +struct RelayToggle: View { + let state: DamusState + let timeline: Timeline + let relay_id: String + + func toggle_binding(relay_id: String) -> Binding<Bool> { + return Binding(get: { + !state.relay_filters.is_filtered(timeline: timeline, relay_id: relay_id) + }, set: { on in + if !on { + state.relay_filters.insert(timeline: timeline, relay_id: relay_id) + } else { + state.relay_filters.remove(timeline: timeline, relay_id: relay_id) + } + }) + } + + var body: some View { + HStack { + RelayStatus(pool: state.pool, relay: relay_id) + RelayType(is_paid: state.relay_metadata.lookup(relay_id: relay_id)?.is_paid ?? false) + Toggle(relay_id, isOn: toggle_binding(relay_id: relay_id)) + .toggleStyle(SwitchToggleStyle(tint: .accentColor)) + } + } +} + +struct RelayToggle_Previews: PreviewProvider { + static var previews: some View { + RelayToggle(state: test_damus_state(), timeline: .search, relay_id: "wss://jb55.com") + .padding() + } +} diff --git a/damus/Views/Relays/RelayType.swift b/damus/Views/Relays/RelayType.swift @@ -0,0 +1,27 @@ +// +// RelayType.swift +// damus +// +// Created by William Casarin on 2023-02-10. +// + +import SwiftUI + +struct RelayType: View { + let is_paid: Bool + + var body: some View { + + Image(systemName: is_paid ? "dollarsign.circle.fill" : "globe.americas.fill") + .foregroundColor(is_paid ? Color("DamusGreen") : .gray) + } +} + +struct RelayType_Previews: PreviewProvider { + static var previews: some View { + VStack { + RelayType(is_paid: false) + RelayType(is_paid: true) + } + } +} diff --git a/damus/Views/Relays/RelayView.swift b/damus/Views/Relays/RelayView.swift @@ -11,45 +11,22 @@ struct RelayView: View { let state: DamusState let relay: String - let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect() - @State var conn_color: Color = .gray - - func update_connection_color() { - for relay in state.pool.relays { - if relay.id == self.relay { - let c = relay.connection - if c.isConnected { - conn_color = .green - } else if c.isConnecting || c.isReconnecting { - conn_color = .yellow - } else { - conn_color = .red - } - } - } - } - var body: some View { - HStack { - Circle() - .frame(width: 8.0, height: 8.0) - .foregroundColor(conn_color) - if let meta = state.relay_metadata.lookup(relay_id: relay) { - NavigationLink { - RelayDetailView(state: state, relay: relay, nip11: meta, conn_color: conn_color) - } label: { + Group { + HStack { + RelayStatus(pool: state.pool, relay: relay) + RelayType(is_paid: state.relay_metadata.lookup(relay_id: relay)?.is_paid ?? false) + if let meta = state.relay_metadata.lookup(relay_id: relay) { + NavigationLink { + RelayDetailView(state: state, relay: relay, nip11: meta) + } label: { + Text(relay) + } + } else { Text(relay) } - } else { - Text(relay) } } - .onReceive(timer) { _ in - update_connection_color() - } - .onAppear() { - update_connection_color() - } .swipeActions { if let privkey = state.keypair.privkey { RemoveAction(privkey: privkey) @@ -94,6 +71,6 @@ struct RelayView: View { struct RelayView_Previews: PreviewProvider { static var previews: some View { - RelayView(state: test_damus_state(), relay: "wss://relay.damus.io", conn_color: .red) + RelayView(state: test_damus_state(), relay: "wss://relay.damus.io") } }