commit 7d17b9b4765a4b8e9e1ea42863307f3df2365181
parent d04f1c68670a028e0689e2385d0efd3bc1df6b93
Author: William Casarin <jb55@jb55.com>
Date: Mon, 17 Jul 2023 13:17:29 -0700
nip05: hide nip05 username if it matches the username
Diffstat:
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/damus/Components/NIP05Badge.swift b/damus/Components/NIP05Badge.swift
@@ -12,14 +12,16 @@ struct NIP05Badge: View {
let pubkey: String
let contacts: Contacts
let show_domain: Bool
-
+ let profiles: Profiles
+
@Environment(\.openURL) var openURL
- init(nip05: NIP05, pubkey: String, contacts: Contacts, show_domain: Bool) {
+ init(nip05: NIP05, pubkey: String, contacts: Contacts, show_domain: Bool, profiles: Profiles) {
self.nip05 = nip05
self.pubkey = pubkey
self.contacts = contacts
self.show_domain = show_domain
+ self.profiles = profiles
}
var nip05_color: Bool {
@@ -42,8 +44,18 @@ struct NIP05Badge: View {
}
}
+ var username_matches_nip05: Bool {
+ guard let profile = profiles.lookup(id: pubkey),
+ let name = profile.name
+ else {
+ return false
+ }
+
+ return name.lowercased() == nip05.username.lowercased()
+ }
+
var nip05_string: String {
- if nip05.username == "_" {
+ if nip05.username == "_" || username_matches_nip05 {
return nip05.host
} else {
return "\(nip05.username)@\(nip05.host)"
@@ -87,13 +99,13 @@ struct NIP05Badge_Previews: PreviewProvider {
static var previews: some View {
let test_state = test_damus_state()
VStack {
- NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true)
+ NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, profiles: test_state.profiles)
- NIP05Badge(nip05: NIP05(username: "_", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true)
+ NIP05Badge(nip05: NIP05(username: "_", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, profiles: test_state.profiles)
- NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true)
+ NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, profiles: test_state.profiles)
- NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: Contacts(our_pubkey: "sdkfjsdf"), show_domain: true)
+ NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: Contacts(our_pubkey: "sdkfjsdf"), show_domain: true, profiles: test_state.profiles)
}
}
}
diff --git a/damus/Views/Profile/ProfileName.swift b/damus/Views/Profile/ProfileName.swift
@@ -85,7 +85,7 @@ struct ProfileName: View {
.font(.body)
.fontWeight(prefix == "@" ? .none : .bold)
if let nip05 = current_nip05 {
- NIP05Badge(nip05: nip05, pubkey: pubkey, contacts: damus_state.contacts, show_domain: show_nip5_domain)
+ NIP05Badge(nip05: nip05, pubkey: pubkey, contacts: damus_state.contacts, show_domain: show_nip5_domain, profiles: damus_state.profiles)
}
if let friend = friend_type, current_nip05 == nil {
FriendIcon(friend: friend)