From 538ce45c2c89dd3a058742fdf252bebfc1ce4937 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 27 Dec 2022 14:14:49 -0800 Subject: [PATCH] Show npub abbreviations instead of hex Changelog-Changed: Show npub abbreviations instead of old-style hex --- damus/Nostr/Nostr.swift | 3 ++- damus/Util/Keys.swift | 7 +++++++ damus/Views/MentionView.swift | 3 ++- damus/Views/NoteContentView.swift | 4 ++-- damus/Views/ProfileName.swift | 1 - damus/Views/ProfileView.swift | 4 ++-- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/damus/Nostr/Nostr.swift b/damus/Nostr/Nostr.swift index 909cb3f6..7cdb1ccd 100644 --- 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 index e7b00093..d741cba5 100644 --- 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 index 66b4382c..e0fbbb05 100644 --- 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 index 55c87942..4439f2a2 100644 --- 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 index 4b0dce7b..6bd1edbe 100644 --- 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 index 1fde3367..6e804539 100644 --- 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()