From 841c49238fce2aa870a7bdf1f51d2de76b57ddce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Fri, 21 Mar 2025 15:06:21 -0300 Subject: [PATCH] Fix thread parent event loading regression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- damus/Models/ThreadModel.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/damus/Models/ThreadModel.swift b/damus/Models/ThreadModel.swift index d95c880c..67d68592 100644 --- 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() }