-
Notifications
You must be signed in to change notification settings - Fork 299
Restore signal indicator #3773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore signal indicator #3773
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ class RelayPool { | |
| var message_received_function: (((String, RelayDescriptor)) -> Void)? | ||
| var message_sent_function: (((String, Relay)) -> Void)? | ||
| var delegate: Delegate? | ||
| @MainActor | ||
| private(set) var signal: SignalModel = SignalModel() | ||
|
|
||
| /// Tracks active leases on ephemeral relays to prevent premature cleanup. | ||
|
|
@@ -125,6 +126,18 @@ class RelayPool { | |
| return relays.reduce(0) { n, r in n + (r.connection.isConnected ? 1 : 0) } | ||
| } | ||
|
|
||
| @MainActor | ||
| func update_signal() { | ||
| let connected = num_connected | ||
| let total = relays.count | ||
| if signal.signal != connected { | ||
| signal.signal = connected | ||
| } | ||
| if signal.max_signal != total { | ||
| signal.max_signal = total | ||
| } | ||
| } | ||
|
Comment on lines
+129
to
+139
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Add docstring to document the method's purpose and behavior. This new method lacks documentation. According to coding guidelines, all added or modified code must have docstring coverage. 📝 Proposed docstring+ /// Updates the signal model with current relay connection statistics.
+ ///
+ /// Computes the number of connected relays and total relay count, then updates
+ /// `signal.signal` and `signal.max_signal` if the values have changed.
+ /// This reduces unnecessary publishes to observers when values are unchanged.
`@MainActor`
func update_signal() {As per coding guidelines: "Ensure docstring coverage for any code added or modified" 🤖 Prompt for AI Agents |
||
|
|
||
| func remove_handler(sub_id: String) { | ||
| self.handlers = handlers.filter { | ||
| if $0.sub_id != sub_id { | ||
|
|
@@ -183,6 +196,7 @@ class RelayPool { | |
|
|
||
| i += 1 | ||
| } | ||
| update_signal() | ||
| } | ||
|
|
||
| /// Acquires a lease on ephemeral relays to prevent them from being cleaned up | ||
|
|
@@ -269,6 +283,7 @@ class RelayPool { | |
| @MainActor | ||
| private func appendRelayToList(relay: Relay) { | ||
| self.relays.append(relay) | ||
| update_signal() | ||
| } | ||
|
|
||
| /// Ensures the given relay URLs are connected, adding them as ephemeral relays if not already in the pool. | ||
|
|
@@ -761,6 +776,7 @@ class RelayPool { | |
| run_queue(relay_id) | ||
| await self.resubscribeAll(relayId: relay_id) | ||
| } | ||
| await update_signal() | ||
| } | ||
|
|
||
| // Handle auth | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Add docstring to document the property's purpose.
This new computed property lacks documentation. According to coding guidelines, all added or modified code must have docstring coverage.
📝 Proposed docstring
As per coding guidelines: "Ensure docstring coverage for any code added or modified"
📝 Committable suggestion
🤖 Prompt for AI Agents