damus

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

commit 538ce45c2c89dd3a058742fdf252bebfc1ce4937
parent aea271182e7ac7395db49f2b7547d04848015273
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 27 Dec 2022 14:14:49 -0800

Show npub abbreviations instead of hex

Changelog-Changed: Show npub abbreviations instead of old-style hex

Diffstat:
Mdamus/Nostr/Nostr.swift | 3++-
Mdamus/Util/Keys.swift | 7+++++++
Mdamus/Views/MentionView.swift | 3++-
Mdamus/Views/NoteContentView.swift | 4++--
Mdamus/Views/ProfileName.swift | 1-
Mdamus/Views/ProfileView.swift | 4++--
6 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/damus/Nostr/Nostr.swift b/damus/Nostr/Nostr.swift @@ -89,7 +89,8 @@ struct Profile: Codable { } static func displayName(profile: Profile?, pubkey: String) -> String { - return profile?.name ?? abbrev_pubkey(pubkey) + let pk = bech32_nopre_pubkey(pubkey) ?? pubkey + return profile?.name ?? abbrev_pubkey(pk) } } diff --git a/damus/Util/Keys.swift b/damus/Util/Keys.swift @@ -66,6 +66,13 @@ func bech32_pubkey(_ pubkey: String) -> String? { return bech32_encode(hrp: "npub", bytes) } +func bech32_nopre_pubkey(_ pubkey: String) -> String? { + guard let bytes = hex_decode(pubkey) else { + return nil + } + return bech32_encode(hrp: "", bytes) +} + func bech32_note_id(_ evid: String) -> String? { guard let bytes = hex_decode(evid) else { return nil diff --git a/damus/Views/MentionView.swift b/damus/Views/MentionView.swift @@ -14,7 +14,8 @@ struct MentionView: View { var body: some View { switch mention.type { case .pubkey: - PubkeyView(pubkey: mention.ref.ref_id, relay: mention.ref.relay_id) + let pk = bech32_pubkey(mention.ref.ref_id) ?? mention.ref.ref_id + PubkeyView(pubkey: pk, relay: mention.ref.relay_id) case .event: Text("< e >") //EventBlockView(pubkey: mention.ref.ref_id, relay: mention.ref.relay_id) diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift @@ -115,8 +115,8 @@ func mention_str(_ m: Mention, profiles: Profiles) -> String { let disp = Profile.displayName(profile: profile, pubkey: pk) return "[@\(disp)](nostr:\(encode_pubkey_uri(m.ref)))" case .event: - let evid = m.ref.ref_id - return "[&\(abbrev_pubkey(evid))](nostr:\(encode_event_id_uri(m.ref)))" + let bevid = bech32_note_id(m.ref.ref_id) ?? m.ref.ref_id + return "[@\(abbrev_pubkey(bevid))](nostr:\(encode_event_id_uri(m.ref)))" } } diff --git a/damus/Views/ProfileName.swift b/damus/Views/ProfileName.swift @@ -73,7 +73,6 @@ struct ProfileName: View { var body: some View { HStack { - Text(prefix + String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey))) .font(.body) .fontWeight(prefix == "@" ? .none : .bold) diff --git a/damus/Views/ProfileView.swift b/damus/Views/ProfileView.swift @@ -161,12 +161,12 @@ struct ProfileView: View { let data = damus_state.profiles.lookup(id: profile.pubkey) HStack(alignment: .center) { - ProfilePicView(pubkey: profile.pubkey, size: PFP_SIZE, highlight: .custom(Color.black, 2), profiles: damus_state.profiles) + ProfilePicView(pubkey: profile.pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles) .onTapGesture { is_zoomed.toggle() } .sheet(isPresented: $is_zoomed) { - ProfilePicView(pubkey: profile.pubkey, size: zoom_size, highlight: .custom(Color.black, 2), profiles: damus_state.profiles) + ProfilePicView(pubkey: profile.pubkey, size: zoom_size, highlight: .none, profiles: damus_state.profiles) } Spacer()