commit d0c67237dd1f483fa726b0dd541e43e7bf4b7b8a
parent 13138805747054e94d2946fd0802deb23cfa525e
Author: William Casarin <jb55@jb55.com>
Date: Sun, 14 May 2023 00:27:50 -0700
nwc: remove requests from postbox
Since these are ephemeral events, there will never be command results,
so we need to remove them manually on NWC responses or else it will keep
trying to send them.
We should probably handle this for all ephemeral events in the postbox
somehow. We probably shouldn't use the postbox for ephemeral events
without response events.
Diffstat:
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift
@@ -145,6 +145,14 @@ class HomeModel: ObservableObject {
return
}
+ // since command results are not returned for ephemeral events,
+ // remove the request from the postbox which is likely failing over and over
+ if damus_state.postbox.remove_relayer(relay_id: nwc.relay.id, event_id: resp.req_id) {
+ print("nwc: got response, removed \(resp.req_id) from the postbox")
+ } else {
+ print("nwc: \(resp.req_id) not found in the postbox, nothing to remove")
+ }
+
if resp.response.error == nil {
nwc_success(zapcache: self.damus_state.zaps, evcache: self.damus_state.events, resp: resp)
return
diff --git a/damus/Util/PostBox.swift b/damus/Util/PostBox.swift
@@ -104,16 +104,18 @@ class PostBox {
remove_relayer(relay_id: relay_id, event_id: cr.event_id)
}
- func remove_relayer(relay_id: String, event_id: String) {
+ @discardableResult
+ func remove_relayer(relay_id: String, event_id: String) -> Bool {
guard let ev = self.events[event_id] else {
- return
- }
- ev.remaining = ev.remaining.filter {
- $0.relay != relay_id
+ return false
}
+ let prev_count = ev.remaining.count
+ ev.remaining = ev.remaining.filter { $0.relay != relay_id }
+ let after_count = ev.remaining.count
if ev.remaining.count == 0 {
self.events.removeValue(forKey: event_id)
}
+ return prev_count != after_count
}
private func flush_event(_ event: PostedEvent, to_relay: Relayer? = nil) {
@@ -147,3 +149,5 @@ class PostBox {
}
}
}
+
+