damus

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

commit 9e0b9debb457424433066d06798b2ad4d93ba0be
parent 379de6ff8e3ae921a92502fc1e98da57cf81f635
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Wed, 11 Sep 2024 15:05:03 -0700

Improve local contact list handling

Unless the user signed up after changes from Github issue #2057, the contact list delegate would never be set due to a logic error, which means latest_contact_event_changed would never get called and the app would never save a local contact list reference to pull from — which caused issues when switching to different relays.

Testing
--------

PASS

Device: iPhone 15 simulator
iOS: 17.5
Setup: Manually removed UserSettingsStore::latest_contact_event_id_hex value to replicate the entry condition for the bug
Steps:
1. Add new relay (relay.zap.store)
2. Remove all other relays
3. Attempt to add relay. Ensure new relay can be added
4. Remove all relays
5. Add the `wss://notify-staging.damus.io` relay (which will not save any events)
6. Restart app
7. Try to add a new relay. Ensure a new relay can be added
8. Make a test post. Ensure the new test post is posted successfully.

Changelog-Fixed: Fixed some scenarios where the contact list would never be saved locally and cause issues when switching relays.
Closes: https://github.com/damus-io/damus/issues/2293
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>

Diffstat:
Mdamus/Models/HomeModel.swift | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -127,11 +127,11 @@ class HomeModel: ContactsDelegate { /// This loads the latest contact event we have on file from NostrDB. This should be called as soon as we get the new DamusState /// Loading the latest contact list event into our `Contacts` instance from storage is important to avoid getting into weird states when the network is unreliable or when relays delete such information func load_latest_contact_event_from_damus_state() { + damus_state.contacts.delegate = self guard let latest_contact_event_id_hex = damus_state.settings.latest_contact_event_id_hex else { return } guard let latest_contact_event_id = NoteId(hex: latest_contact_event_id_hex) else { return } guard let latest_contact_event: NdbNote = damus_state.ndb.lookup_note( latest_contact_event_id)?.unsafeUnownedValue?.to_owned() else { return } process_contact_event(state: damus_state, ev: latest_contact_event) - damus_state.contacts.delegate = self } // MARK: - ContactsDelegate functions