damus

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

commit a4d4954abdb007d9f059c5afdee9bb0302899d98
parent 735376b00f18216127e32a559c764b665708714a
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 14 Apr 2023 11:45:10 -0700

Fix relay signal indicator, properly show how many relays you are connected to

Changelog-Fixed: Fix relay signal indicator, properly show how many relays you are connected to

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 7++++---
Mdamus/ContentView.swift | 8+-------
Mdamus/Models/HomeModel.swift | 12+++++++-----
Mdamus/Nostr/RelayPool.swift | 4++++
Adamus/Views/Relays/SignalView.swift | 34++++++++++++++++++++++++++++++++++
5 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -192,6 +192,7 @@ 4CCEB7B029B5415A0078AA28 /* SearchingProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CCEB7AF29B5415A0078AA28 /* SearchingProfileView.swift */; }; 4CD348EF29C3659D00497EB2 /* ImageUploadModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD348EE29C3659D00497EB2 /* ImageUploadModel.swift */; }; 4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD7641A28A1641400B6928F /* EndBlock.swift */; }; + 4CDA128A29E9D10C0006FA5A /* SignalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDA128929E9D10C0006FA5A /* SignalView.swift */; }; 4CE0E2AF29A2E82100DB4CA2 /* EventHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE0E2AE29A2E82100DB4CA2 /* EventHolder.swift */; }; 4CE0E2B229A3DF6900DB4CA2 /* LoadMoreButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE0E2B129A3DF6900DB4CA2 /* LoadMoreButton.swift */; }; 4CE0E2B629A3ED5500DB4CA2 /* InnerTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE0E2B529A3ED5500DB4CA2 /* InnerTimelineView.swift */; }; @@ -330,9 +331,6 @@ 3A41E55A299D52BE001FA465 /* id */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = id; path = id.lproj/Localizable.strings; sourceTree = "<group>"; }; 3A41E55B299D52BE001FA465 /* id */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = id; path = id.lproj/Localizable.stringsdict; sourceTree = "<group>"; }; 3A48E7AF29DFBE9D006E787E /* MutedThreadsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutedThreadsManager.swift; sourceTree = "<group>"; }; - 3A4F3320297CCFEE004B5F72 /* fr-FR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "fr-FR"; path = "fr-FR.lproj/InfoPlist.strings"; sourceTree = "<group>"; }; - 3A4F3321297CCFEE004B5F72 /* fr-FR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "fr-FR"; path = "fr-FR.lproj/Localizable.strings"; sourceTree = "<group>"; }; - 3A4F3322297CCFEE004B5F72 /* fr-FR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "fr-FR"; path = "fr-FR.lproj/Localizable.stringsdict"; sourceTree = "<group>"; }; 3A5C4575296A879E0032D398 /* es-419 */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "es-419"; path = "es-419.lproj/Localizable.stringsdict"; sourceTree = "<group>"; }; 3A5CAE1D298DC0DB00B5334F /* zh-CN */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-CN"; path = "zh-CN.lproj/InfoPlist.strings"; sourceTree = "<group>"; }; 3A5CAE1E298DC0DB00B5334F /* zh-CN */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-CN"; path = "zh-CN.lproj/Localizable.strings"; sourceTree = "<group>"; }; @@ -601,6 +599,7 @@ 4CCEB7AF29B5415A0078AA28 /* SearchingProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchingProfileView.swift; sourceTree = "<group>"; }; 4CD348EE29C3659D00497EB2 /* ImageUploadModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageUploadModel.swift; sourceTree = "<group>"; }; 4CD7641A28A1641400B6928F /* EndBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndBlock.swift; sourceTree = "<group>"; }; + 4CDA128929E9D10C0006FA5A /* SignalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignalView.swift; sourceTree = "<group>"; }; 4CE0E2AE29A2E82100DB4CA2 /* EventHolder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventHolder.swift; sourceTree = "<group>"; }; 4CE0E2B129A3DF6900DB4CA2 /* LoadMoreButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadMoreButton.swift; sourceTree = "<group>"; }; 4CE0E2B529A3ED5500DB4CA2 /* InnerTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InnerTimelineView.swift; sourceTree = "<group>"; }; @@ -1022,6 +1021,7 @@ 4CE8794D2996B16A00F758CC /* RelayToggle.swift */, 4CE8794F2996B2BD00F758CC /* RelayStatus.swift */, 4CE879512996B68900F758CC /* RelayType.swift */, + 4CDA128929E9D10C0006FA5A /* SignalView.swift */, ); path = Relays; sourceTree = "<group>"; @@ -1494,6 +1494,7 @@ 7C902AE32981D55B002AB16E /* ZoomableScrollView.swift in Sources */, 4CE8794C2995B59E00F758CC /* RelayMetadatas.swift in Sources */, 4C363A8C28236B92006E126D /* PubkeyView.swift in Sources */, + 4CDA128A29E9D10C0006FA5A /* SignalView.swift in Sources */, 4C5C7E68284ED36500A22DF5 /* SearchHomeModel.swift in Sources */, 4C54AA0C29A5543C003E4487 /* ZapGroup.swift in Sources */, 4C75EFB728049D990006080F /* RelayPool.swift in Sources */, diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -267,13 +267,7 @@ struct ContentView: View { ToolbarItem(placement: .navigationBarTrailing) { HStack(alignment: .center) { - if home.signal.signal != home.signal.max_signal { - NavigationLink(destination: RelayConfigView(state: damus_state!)) { - Text("\(home.signal.signal)/\(home.signal.max_signal)", comment: "Fraction of how many of the user's relay servers that are operational.") - .font(.callout) - .foregroundColor(.gray) - } - } + SignalView(state: damus_state!, signal: home.signal) // maybe expand this to other timelines in the future if selected_timeline == .search { diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -41,13 +41,15 @@ class HomeModel: ObservableObject { let dms_subid = UUID().description let init_subid = UUID().description let profiles_subid = UUID().description + + var loading: Bool = false + var signal = SignalModel() + @Published var new_events: NewEventsBits = NewEventsBits() @Published var notifications = NotificationsModel() @Published var dms: DirectMessagesModel @Published var events = EventHolder() - @Published var loading: Bool = false - @Published var signal: SignalModel = SignalModel() init() { self.damus_state = DamusState.empty @@ -299,7 +301,7 @@ class HomeModel: ObservableObject { break } - update_signal_from_pool(signal: signal, pool: damus_state.pool) + update_signal_from_pool(signal: self.signal, pool: damus_state.pool) print("ws_event \(ev)") @@ -557,8 +559,8 @@ func update_signal_from_pool(signal: SignalModel, pool: RelayPool) { signal.max_signal = pool.relays.count } - if signal.signal != pool.num_connecting { - signal.signal = signal.max_signal - pool.num_connecting + if signal.signal != pool.num_connected { + signal.signal = pool.num_connected } } diff --git a/damus/Nostr/RelayPool.swift b/damus/Nostr/RelayPool.swift @@ -52,6 +52,10 @@ class RelayPool { var num_connecting: Int { return relays.reduce(0) { n, r in n + (r.connection.isConnecting ? 1 : 0) } } + + var num_connected: Int { + return relays.reduce(0) { n, r in n + (r.connection.isConnected ? 1 : 0) } + } func remove_handler(sub_id: String) { self.handlers = handlers.filter { $0.sub_id != sub_id } diff --git a/damus/Views/Relays/SignalView.swift b/damus/Views/Relays/SignalView.swift @@ -0,0 +1,34 @@ +// +// SignalView.swift +// damus +// +// Created by William Casarin on 2023-04-14. +// + +import SwiftUI + +struct SignalView: View { + let state: DamusState + @ObservedObject var signal: SignalModel + + var body: some View { + Group { + if signal.signal != signal.max_signal { + NavigationLink(destination: RelayConfigView(state: state)) { + Text("\(signal.signal)/\(signal.max_signal)", comment: "Fraction of how many of the user's relay servers that are operational.") + .font(.callout) + .foregroundColor(.gray) + } + } else { + Text("") + } + } + + } +} + +struct SignalView_Previews: PreviewProvider { + static var previews: some View { + SignalView(state: test_damus_state(), signal: SignalModel(signal: 5, max_signal: 10)) + } +}