Show npub abbreviations instead of hex
Changelog-Changed: Show npub abbreviations instead of old-style hex
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)))"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user