damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 4b8f536a9b7b4d92ebadd387e926bdaf1988de60
parent 9e5209b48d0b38cdb9e6c593e544f0759e8bb3cf
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 11 Jan 2023 14:48:35 -0800

Refactor NIP05 badge into its own view

Also only make it clickable in profile view

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 4++++
Adamus/Components/NIP05Badge.swift | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdamus/Views/ProfileName.swift | 21+++------------------
3 files changed, 72 insertions(+), 18 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -116,6 +116,7 @@ 4CB55EF3295E5D59007FD187 /* RecommendedRelayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */; }; 4CB55EF5295E679D007FD187 /* UserRelaysView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB55EF4295E679D007FD187 /* UserRelaysView.swift */; }; 4CB8838629656C8B00DC99E7 /* NIP05.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB8838529656C8B00DC99E7 /* NIP05.swift */; }; + 4CB8838B296F6E1E00DC99E7 /* NIP05Badge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB8838A296F6E1E00DC99E7 /* NIP05Badge.swift */; }; 4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD7641A28A1641400B6928F /* EndBlock.swift */; }; 4CE4F8CD281352B30009DFBB /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F8CC281352B30009DFBB /* Notifications.swift */; }; 4CE4F9DE2852768D00C00DD9 /* ConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */; }; @@ -308,6 +309,7 @@ 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendedRelayView.swift; sourceTree = "<group>"; }; 4CB55EF4295E679D007FD187 /* UserRelaysView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRelaysView.swift; sourceTree = "<group>"; }; 4CB8838529656C8B00DC99E7 /* NIP05.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NIP05.swift; sourceTree = "<group>"; }; + 4CB8838A296F6E1E00DC99E7 /* NIP05Badge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NIP05Badge.swift; sourceTree = "<group>"; }; 4CD7641A28A1641400B6928F /* EndBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndBlock.swift; sourceTree = "<group>"; }; 4CE4F8CC281352B30009DFBB /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; }; 4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigView.swift; sourceTree = "<group>"; }; @@ -570,6 +572,7 @@ 4C06670528FCB08600038D2A /* ImageCarousel.swift */, 4C3EA67C28FFBBA200C48A62 /* InvoicesView.swift */, 4C3EA67E28FFC01D00C48A62 /* InvoiceView.swift */, + 4CB8838A296F6E1E00DC99E7 /* NIP05Badge.swift */, ); path = Components; sourceTree = "<group>"; @@ -841,6 +844,7 @@ 4C363A9A28283854006E126D /* Reply.swift in Sources */, BA693074295D649800ADDB87 /* UserSettingsStore.swift in Sources */, 4C90BD18283A9EE5008EE7EF /* LoginView.swift in Sources */, + 4CB8838B296F6E1E00DC99E7 /* NIP05Badge.swift in Sources */, 4C3EA66828FF5F9900C48A62 /* hex.c in Sources */, E9E4ED0B295867B900DD7078 /* ThreadV2View.swift in Sources */, 4C3BEFDC281DCE6100B3DE84 /* Liked.swift in Sources */, diff --git a/damus/Components/NIP05Badge.swift b/damus/Components/NIP05Badge.swift @@ -0,0 +1,65 @@ +// +// NIP05Badge.swift +// damus +// +// Created by William Casarin on 2023-01-11. +// + +import SwiftUI + +struct NIP05Badge: View { + let nip05: NIP05 + let pubkey: String + let contacts: Contacts + let show_domain: Bool + let clickable: Bool + + @Environment(\.openURL) var openURL + + init (nip05: NIP05, pubkey: String, contacts: Contacts, show_domain: Bool, clickable: Bool) { + self.nip05 = nip05 + self.pubkey = pubkey + self.contacts = contacts + self.show_domain = show_domain + self.clickable = clickable + } + + var nip05_color: Color { + return get_nip05_color(pubkey: pubkey, contacts: contacts) + } + + var body: some View { + HStack(spacing: 2) { + Image(systemName: "checkmark.seal.fill") + .font(.footnote) + .foregroundColor(nip05_color) + if show_domain { + if clickable { + Text(nip05.host) + .foregroundColor(nip05_color) + .onTapGesture { + if let nip5url = nip05.siteUrl { + openURL(nip5url) + } + } + } else { + Text(nip05.host) + .foregroundColor(nip05_color) + } + } + } + + } +} + +func get_nip05_color(pubkey: String, contacts: Contacts) -> Color { + return contacts.is_friend_or_self(pubkey) ? .accentColor : .gray +} + +struct NIP05Badge_Previews: PreviewProvider { + static var previews: some View { + let test_state = test_damus_state() + NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, clickable: false) + } +} + diff --git a/damus/Views/ProfileName.swift b/damus/Views/ProfileName.swift @@ -73,18 +73,7 @@ struct ProfileName: View { .font(.body) .fontWeight(prefix == "@" ? .none : .bold) if let nip05 = current_nip05 { - Image(systemName: "checkmark.seal.fill") - .foregroundColor(nip05_color) - - if show_nip5_domain { - Text(nip05.host) - .foregroundColor(nip05_color) - .onTapGesture { - if let nip5url = nip05.siteUrl { - openURL(nip5url) - } - } - } + NIP05Badge(nip05: nip05, pubkey: pubkey, contacts: damus_state.contacts, show_domain: show_nip5_domain, clickable: true) } if let friend = friend_icon, current_nip05 == nil { Image(systemName: friend) @@ -158,9 +147,8 @@ struct EventProfileName: View { .fontWeight(.bold) } - if let _ = current_nip05 { - Image(systemName: "checkmark.seal.fill") - .foregroundColor(get_nip05_color(pubkey: pubkey, contacts: damus_state.contacts)) + if let nip05 = current_nip05 { + NIP05Badge(nip05: nip05, pubkey: pubkey, contacts: damus_state.contacts, show_domain: false, clickable: false) } if let frend = friend_icon, current_nip05 == nil { @@ -180,6 +168,3 @@ struct EventProfileName: View { } } -func get_nip05_color(pubkey: String, contacts: Contacts) -> Color { - return contacts.is_friend_or_self(pubkey) ? .accentColor : .gray -}