nip05: hide nip05 username if it matches the username
This commit is contained in:
@@ -12,14 +12,16 @@ struct NIP05Badge: View {
|
|||||||
let pubkey: String
|
let pubkey: String
|
||||||
let contacts: Contacts
|
let contacts: Contacts
|
||||||
let show_domain: Bool
|
let show_domain: Bool
|
||||||
|
let profiles: Profiles
|
||||||
|
|
||||||
@Environment(\.openURL) var openURL
|
@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.nip05 = nip05
|
||||||
self.pubkey = pubkey
|
self.pubkey = pubkey
|
||||||
self.contacts = contacts
|
self.contacts = contacts
|
||||||
self.show_domain = show_domain
|
self.show_domain = show_domain
|
||||||
|
self.profiles = profiles
|
||||||
}
|
}
|
||||||
|
|
||||||
var nip05_color: Bool {
|
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 {
|
var nip05_string: String {
|
||||||
if nip05.username == "_" {
|
if nip05.username == "_" || username_matches_nip05 {
|
||||||
return nip05.host
|
return nip05.host
|
||||||
} else {
|
} else {
|
||||||
return "\(nip05.username)@\(nip05.host)"
|
return "\(nip05.username)@\(nip05.host)"
|
||||||
@@ -87,13 +99,13 @@ struct NIP05Badge_Previews: PreviewProvider {
|
|||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let test_state = test_damus_state()
|
let test_state = test_damus_state()
|
||||||
VStack {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ struct ProfileName: View {
|
|||||||
.font(.body)
|
.font(.body)
|
||||||
.fontWeight(prefix == "@" ? .none : .bold)
|
.fontWeight(prefix == "@" ? .none : .bold)
|
||||||
if let nip05 = current_nip05 {
|
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 {
|
if let friend = friend_type, current_nip05 == nil {
|
||||||
FriendIcon(friend: friend)
|
FriendIcon(friend: friend)
|
||||||
|
|||||||
Reference in New Issue
Block a user