contacts: save the users' latest contact event ID
... to a persistent setting, and try to load it from NostrDB on app start. This commit causes the user's contact list event ID to be saved persistently as a user-specific setting, and to be loaded immediately after startup from the local NostrDB instance. This helps improve reliability around contact lists, since we previously relied on fetching that contact list from other relays. Eventually we will not need the event ID to be stored at all, as we will be able to query NostrDB, but for now having the latest event ID persistently stored will allow us to get around this limitation in the cleanest possible way (i.e. without having to store the event itself into another mechanism, and migrating it later to NostrDB) Other notes: - It uses a mechanism similar to other user settings, so it is pubkey-specific and should handle login/logout cases Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Reviewed-by: William Casarin <jb55@jb55.com> Link: 20240422230912.65056-2-daniel@daquino.me Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
43630cbfa6
commit
43a5bbd53a
@@ -7,7 +7,6 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
class Contacts {
|
||||
private var friends: Set<Pubkey> = Set()
|
||||
private var friend_of_friends: Set<Pubkey> = Set()
|
||||
@@ -15,7 +14,13 @@ class Contacts {
|
||||
private var pubkey_to_our_friends = [Pubkey : Set<Pubkey>]()
|
||||
|
||||
let our_pubkey: Pubkey
|
||||
var event: NostrEvent?
|
||||
var delegate: ContactsDelegate? = nil
|
||||
var event: NostrEvent? {
|
||||
didSet {
|
||||
guard let event else { return }
|
||||
self.delegate?.latest_contact_event_changed(new_event: event)
|
||||
}
|
||||
}
|
||||
|
||||
init(our_pubkey: Pubkey) {
|
||||
self.our_pubkey = our_pubkey
|
||||
@@ -88,3 +93,8 @@ class Contacts {
|
||||
return Array((pubkey_to_our_friends[pubkey] ?? Set()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Delegate protocol for `Contacts`. Use this to listen to significant updates from a `Contacts` instance
|
||||
protocol ContactsDelegate {
|
||||
func latest_contact_event_changed(new_event: NostrEvent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user