damus

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

commit 6bca9eb2bedddbf108b1f095bf76f8ee1af960ad
parent 23bb7c7f18679e81177a6a9100d2c569189d8834
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  8 Jun 2022 13:49:04 -0700

new account fixes

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Models/FollowersModel.swift | 2++
Mdamus/Models/FollowingModel.swift | 2++
Mdamus/Models/HomeModel.swift | 11+++++++++--
Mdamus/Models/ProfileModel.swift | 23++++++++++++++++-------
Mdamus/Models/SearchHomeModel.swift | 2++
Mdamus/Models/SearchModel.swift | 3+++
Mdamus/Nostr/NostrResponse.swift | 4++++
Mdamus/Views/ProfilePictureSelector.swift | 6++++--
Mdamus/Views/SaveKeysView.swift | 2++
9 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/damus/Models/FollowersModel.swift b/damus/Models/FollowersModel.swift @@ -64,6 +64,8 @@ class FollowersModel: ObservableObject { } case .notice(let msg): print("followingmodel notice: \(msg)") + case .eose: + break } } } diff --git a/damus/Models/FollowingModel.swift b/damus/Models/FollowingModel.swift @@ -64,6 +64,8 @@ class FollowingModel { } case .notice(let msg): print("followingmodel notice: \(msg)") + case .eose: + break } } } diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -176,6 +176,9 @@ class HomeModel: ObservableObject { case .notice(let msg): //self.events.insert(NostrEvent(content: "NOTICE from \(relay_id): \(msg)", pubkey: "system"), at: 0) print(msg) + + case .eose: + break } } } @@ -395,11 +398,15 @@ func process_metadata_event(profiles: Profiles, ev: NostrEvent) { func process_contact_event(pool: RelayPool, contacts: Contacts, pubkey: String, ev: NostrEvent) { load_our_contacts(contacts: contacts, our_pubkey: pubkey, ev: ev) - load_our_relays(pool: pool, ev: ev) + load_our_relays(our_pubkey: pubkey, pool: pool, ev: ev) add_contact_if_friend(contacts: contacts, ev: ev) } -func load_our_relays(pool: RelayPool, ev: NostrEvent) { +func load_our_relays(our_pubkey: String, pool: RelayPool, ev: NostrEvent) { + guard ev.pubkey == our_pubkey else { + return + } + guard let decoded = decode_json_relays(ev.content) else { return } diff --git a/damus/Models/ProfileModel.swift b/damus/Models/ProfileModel.swift @@ -17,6 +17,7 @@ class ProfileModel: ObservableObject { var seen_event: Set<String> = Set() var sub_id = UUID().description + var prof_subid = UUID().description func get_follow_target() -> FollowTarget { if let contacts = contacts { @@ -33,24 +34,30 @@ class ProfileModel: ObservableObject { func unsubscribe() { print("unsubscribing from profile \(pubkey) with sub_id \(sub_id)") damus.pool.unsubscribe(sub_id: sub_id) + damus.pool.unsubscribe(sub_id: prof_subid) } func subscribe() { + var text_filter = NostrFilter.filter_kinds([ + NostrKind.text.rawValue + ]) + var profile_filter = NostrFilter.filter_kinds([ - NostrKind.text.rawValue, - NostrKind.boost.rawValue, - NostrKind.metadata.rawValue, NostrKind.contacts.rawValue, + NostrKind.metadata.rawValue, + NostrKind.boost.rawValue, NostrKind.like.rawValue ]) + profile_filter.authors = [pubkey] - profile_filter.limit = 1000 - let filters = [profile_filter] + text_filter.authors = [pubkey] + text_filter.limit = 1000 print("subscribing to profile \(pubkey) with sub_id \(sub_id)") - print_filters(relay_id: "profile", filters: [filters]) - damus.pool.subscribe(sub_id: sub_id, filters: filters, handler: handle_event) + print_filters(relay_id: "profile", filters: [[text_filter], [profile_filter]]) + damus.pool.subscribe(sub_id: sub_id, filters: [text_filter], handler: handle_event) + damus.pool.subscribe(sub_id: prof_subid, filters: [profile_filter], handler: handle_event) } func handle_profile_contact_event(_ ev: NostrEvent) { @@ -86,6 +93,8 @@ class ProfileModel: ObservableObject { add_event(ev) case .notice(let notice): notify(.notice, notice) + case .eose: + break } } } diff --git a/damus/Models/SearchHomeModel.swift b/damus/Models/SearchHomeModel.swift @@ -51,6 +51,8 @@ class SearchHomeModel: ObservableObject { } case .notice(let msg): print("search home notice: \(msg)") + case .eose: + break } } } diff --git a/damus/Models/SearchModel.swift b/damus/Models/SearchModel.swift @@ -91,6 +91,9 @@ func handle_subid_event(pool: RelayPool, sub_id: String, relay_id: String, ev: N pool.reconnect(to: [relay_id]) } break + + case .eose: + break } } } diff --git a/damus/Nostr/NostrResponse.swift b/damus/Nostr/NostrResponse.swift @@ -10,6 +10,7 @@ import Foundation enum NostrResponse: Decodable { case event(String, NostrEvent) case notice(String) + case eose init(from decoder: Decoder) throws { var container = try decoder.unkeyedContainer() @@ -32,6 +33,9 @@ enum NostrResponse: Decodable { let msg = try container.decode(String.self) self = .notice(msg) return + } else if typ == "EOSE" { + self = .eose + return } throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "expected EVENT or NOTICE, got \(typ)")) diff --git a/damus/Views/ProfilePictureSelector.swift b/damus/Views/ProfilePictureSelector.swift @@ -13,11 +13,13 @@ struct ProfilePictureSelector: View { var body: some View { let highlight: Highlight = .custom(Color.white, 2.0) ZStack { - ProfilePicView(pubkey: pubkey, size: 80.0, highlight: highlight, image_cache: ImageCache(), profiles: Profiles()) - + /* Image(systemName: "camera") .font(.title) .foregroundColor(.white) + */ + + ProfilePicView(pubkey: pubkey, size: 80.0, highlight: highlight, image_cache: ImageCache(), profiles: Profiles()) } } } diff --git a/damus/Views/SaveKeysView.swift b/damus/Views/SaveKeysView.swift @@ -121,6 +121,8 @@ struct SaveKeysView: View { print(msg) case .event: print("event in signup?") + case .eose: + break } } }