From 9e0b9debb457424433066d06798b2ad4d93ba0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Wed, 11 Sep 2024 15:05:03 -0700 Subject: [PATCH] Improve local contact list handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- damus/Models/HomeModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift index aa375707..003a4367 100644 --- 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