Browse Source

Show npub abbreviations instead of hex

Changelog-Changed: Show npub abbreviations instead of old-style hex
post-button-style
William Casarin 2 years ago
parent
commit
538ce45c2c
  1. 3
      damus/Nostr/Nostr.swift
  2. 7
      damus/Util/Keys.swift
  3. 3
      damus/Views/MentionView.swift
  4. 4
      damus/Views/NoteContentView.swift
  5. 1
      damus/Views/ProfileName.swift
  6. 4
      damus/Views/ProfileView.swift

3
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)
}
}

7
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

3
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)

4
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)))"
}
}

1
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)

4
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()

Loading…
Cancel
Save