damus

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

commit baed6adf491c6e80d3c8befbca80c0b8d6adbca3
parent f068833c5e654baed8bae4a6b8f8235fc65ed8d3
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 10 May 2023 11:41:17 -0700

refactor: ensure make_metadata_event has full keypair

Diffstat:
Mdamus/ContentView.swift | 15+++++----------
Mdamus/Nostr/NostrEvent.swift | 8++------
Mdamus/Views/Profile/EditMetadataView.swift | 3++-
Mdamus/Views/SaveKeysView.swift | 5+++--
4 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -434,20 +434,15 @@ struct ContentView: View { let hide = notif.object as! Bool home.filter_events() - guard let damus_state else { - return - } - - guard let profile = damus_state.profiles.lookup(id: damus_state.pubkey) else { + guard let damus_state, + let profile = damus_state.profiles.lookup(id: damus_state.pubkey), + let keypair = damus_state.keypair.to_full() + else { return } profile.reactions = !hide - - guard let profile_ev = make_metadata_event(keypair: damus_state.keypair, metadata: profile) else { - return - } - + let profile_ev = make_metadata_event(keypair: keypair, metadata: profile) damus_state.postbox.send(profile_ev) } .alert(NSLocalizedString("Deleted Account", comment: "Alert message to indicate this is a deleted account"), isPresented: $is_deleted_account) { diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift @@ -468,11 +468,7 @@ func make_first_contact_event(keypair: Keypair) -> NostrEvent? { return ev } -func make_metadata_event(keypair: Keypair, metadata: Profile) -> NostrEvent? { - guard let privkey = keypair.privkey else { - return nil - } - +func make_metadata_event(keypair: FullKeypair, metadata: Profile) -> NostrEvent { let metadata_json = encode_json(metadata)! let ev = NostrEvent(content: metadata_json, pubkey: keypair.pubkey, @@ -480,7 +476,7 @@ func make_metadata_event(keypair: Keypair, metadata: Profile) -> NostrEvent? { tags: []) ev.calculate_id() - ev.sign(privkey: privkey) + ev.sign(privkey: keypair.privkey) return ev } diff --git a/damus/Views/Profile/EditMetadataView.swift b/damus/Views/Profile/EditMetadataView.swift @@ -60,9 +60,10 @@ struct EditMetadataView: View { func save() { let profile = to_profile() - guard let metadata_ev = make_metadata_event(keypair: damus_state.keypair, metadata: profile) else { + guard let keypair = damus_state.keypair.to_full() else { return } + let metadata_ev = make_metadata_event(keypair: keypair, metadata: profile) damus_state.postbox.send(metadata_ev) } diff --git a/damus/Views/SaveKeysView.swift b/damus/Views/SaveKeysView.swift @@ -112,12 +112,13 @@ struct SaveKeysView: View { switch wsev { case .connected: let metadata = create_account_to_metadata(account) - let metadata_ev = make_metadata_event(keypair: account.keypair, metadata: metadata) let contacts_ev = make_first_contact_event(keypair: account.keypair) - if let metadata_ev { + if let keypair = account.keypair.to_full() { + let metadata_ev = make_metadata_event(keypair: keypair, metadata: metadata) self.pool.send(.event(metadata_ev)) } + if let contacts_ev { self.pool.send(.event(contacts_ev)) }