commit 841c49238fce2aa870a7bdf1f51d2de76b57ddce
parent 22f2aba96979c0f36d2b7165db08635db43774f4
Author: Daniel D’Aquino <daniel@daquino.me>
Date: Fri, 21 Mar 2025 15:06:21 -0300
Fix thread parent event loading regression
This fixes a regression where ThreadModel would no longer look at
NostrDB saved notes for parent events, causing some instability on
thread loading — especially in poor networking conditions.
This was fixed by adding a call that searches for parent events in
EventCache/NostrDB each time an event is added to the ThreadModel.
That `add_event` function is the ideal spot to place the call because it
is the only interface used for all information updates incoming to the
ThreadModel, including:
- anytime an event is loaded from the network into the thread model.
- when the ThreadModel is first initialized, with an initial event.
Fixes: 74d5bee1f6c4c3807fbdd41458a36dd059c896ad
Changelog-Fixed: Fixed an issue where threads would not load properly
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Diffstat:
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/damus/Models/ThreadModel.swift b/damus/Models/ThreadModel.swift
@@ -136,6 +136,16 @@ class ThreadModel: ObservableObject {
event_map.add(event: ev)
+ // Add all parent events that we have on EventCache (and subsequently on NostrDB)
+ // This helps ensure we include as many locally-stored notes as possible — even on poor networking conditions
+ damus_state.events.parent_events(event: ev, keypair: damus_state.keypair).forEach {
+ // Note: Nostr threads are cryptographically guaranteeed to be acyclic graphs, which means there is no risk of infinite recursion in this call
+ add_event(
+ $0, // The `lookup` function in `parent_events` turns the event into an "owned" object, so we do not need to clone here
+ keypair: damus_state.keypair
+ )
+ }
+
// Publish changes
objectWillChange.send()
}