Switch from bluecheck to purplecheck

This commit also refactors a bunch of crap

Changelog-Changed: Switch from bluecheck to purplecheck
This commit is contained in:
William Casarin
2023-01-04 10:06:19 -08:00
parent 89c857d3e9
commit 5ba5a68628
9 changed files with 62 additions and 68 deletions

View File

@@ -86,7 +86,7 @@ struct ChatView: View {
VStack(alignment: .leading) {
if just_started {
HStack {
ProfileName(pubkey: event.pubkey, profile: damus_state.profiles.lookup(id: event.pubkey), contacts: damus_state.contacts, show_friend_confirmed: true, profiles: damus_state.profiles)
ProfileName(pubkey: event.pubkey, profile: damus_state.profiles.lookup(id: event.pubkey), damus: damus_state, show_friend_confirmed: true)
.foregroundColor(colorScheme == .dark ? id_to_color(event.pubkey) : Color.black)
//.shadow(color: Color.black, radius: 2)
Text("\(format_relative_time(event.created_at))")

View File

@@ -40,7 +40,7 @@ struct DMChatView: View {
HStack {
ProfilePicView(pubkey: pubkey, size: 24, highlight: .none, profiles: damus_state.profiles)
ProfileName(pubkey: pubkey, profile: profile, contacts: damus_state.contacts, show_friend_confirmed: true, profiles: damus_state.profiles)
ProfileName(pubkey: pubkey, profile: profile, damus: damus_state, show_friend_confirmed: true)
}
}
.buttonStyle(PlainButtonStyle())

View File

@@ -176,7 +176,7 @@ struct EventView: View {
Image(systemName: "arrow.2.squarepath")
.font(.footnote.weight(.bold))
.foregroundColor(Color.gray)
ProfileName(pubkey: event.pubkey, profile: prof, contacts: damus.contacts, show_friend_confirmed: true, profiles: damus.profiles)
ProfileName(pubkey: event.pubkey, profile: prof, damus: damus, show_friend_confirmed: true)
.font(.footnote.weight(.bold))
.foregroundColor(Color.gray)
Text("Boosted")
@@ -227,7 +227,7 @@ struct EventView: View {
}
}
EventProfileName(pubkey: pubkey, profile: profile, contacts: damus.contacts, show_friend_confirmed: show_friend_icon, profiles: damus.profiles, size: size)
EventProfileName(pubkey: pubkey, profile: profile, damus: damus, show_friend_confirmed: show_friend_icon, size: size)
if size != .selected {
Text("\(format_relative_time(event.created_at))")
.font(eventviewsize_to_font(size))

View File

@@ -24,7 +24,7 @@ struct FollowUserView: View {
VStack(alignment: .leading) {
let profile = damus_state.profiles.lookup(id: target.pubkey)
ProfileName(pubkey: target.pubkey, profile: profile, contacts: damus_state.contacts, show_friend_confirmed: false, profiles: damus_state.profiles)
ProfileName(pubkey: target.pubkey, profile: profile, damus: damus_state, show_friend_confirmed: false)
if let about = profile?.about {
Text(FollowUserView.markdown.process(about))
.lineLimit(3)

View File

@@ -7,58 +7,59 @@
import SwiftUI
func get_friend_icon(contacts: Contacts, pubkey: String, show_confirmed: Bool) -> String? {
if !show_confirmed {
return nil
}
if contacts.is_friend_or_self(pubkey) {
return "person.fill.checkmark"
}
if contacts.is_friend_of_friend(pubkey) {
return "person.fill.and.arrow.left.and.arrow.right"
}
return nil
}
struct ProfileName: View {
let damus_state: DamusState
let pubkey: String
let profile: Profile?
let contacts: Contacts
let prefix: String
let show_friend_confirmed: Bool
let profiles: Profiles
@State var display_name: String?
@State var nip05: NIP05?
init(pubkey: String, profile: Profile?, contacts: Contacts, show_friend_confirmed: Bool, profiles: Profiles) {
init(pubkey: String, profile: Profile?, damus: DamusState, show_friend_confirmed: Bool) {
self.pubkey = pubkey
self.profile = profile
self.prefix = ""
self.contacts = contacts
self.show_friend_confirmed = show_friend_confirmed
self.profiles = profiles
self.damus_state = damus
}
init(pubkey: String, profile: Profile?, prefix: String, contacts: Contacts, show_friend_confirmed: Bool, profiles: Profiles) {
init(pubkey: String, profile: Profile?, prefix: String, damus: DamusState, show_friend_confirmed: Bool) {
self.pubkey = pubkey
self.profile = profile
self.prefix = prefix
self.contacts = contacts
self.damus_state = damus
self.show_friend_confirmed = show_friend_confirmed
self.profiles = profiles
}
var friend_icon: String? {
if !show_friend_confirmed {
return nil
}
if self.contacts.is_friend(self.pubkey) {
return "person.fill.checkmark"
}
if self.contacts.is_friend_of_friend(self.pubkey) {
return "person.fill.and.arrow.left.and.arrow.right"
}
return nil
}
var nip05_color: Color {
contacts.is_friend(pubkey) ? .blue : .yellow
return get_friend_icon(contacts: damus_state.contacts, pubkey: pubkey, show_confirmed: show_friend_confirmed)
}
var current_nip05: NIP05? {
nip05 ?? profiles.is_validated(pubkey)
nip05 ?? damus_state.profiles.is_validated(pubkey)
}
var nip05_color: Color {
return get_nip05_color(pubkey: pubkey, contacts: damus_state.contacts)
}
var body: some View {
@@ -83,68 +84,49 @@ struct ProfileName: View {
return
}
display_name = Profile.displayName(profile: update.profile, pubkey: pubkey)
nip05 = profiles.is_validated(pubkey)
nip05 = damus_state.profiles.is_validated(pubkey)
}
}
}
/// Profile Name used when displaying an event in the timeline
struct EventProfileName: View {
let damus_state: DamusState
let pubkey: String
let profile: Profile?
let contacts: Contacts
let prefix: String
let show_friend_confirmed: Bool
let profiles: Profiles
@State var display_name: String?
@State var nip05: NIP05?
let size: EventViewKind
init(pubkey: String, profile: Profile?, contacts: Contacts, show_friend_confirmed: Bool, profiles: Profiles, size: EventViewKind = .normal) {
init(pubkey: String, profile: Profile?, damus: DamusState, show_friend_confirmed: Bool, size: EventViewKind = .normal) {
self.damus_state = damus
self.pubkey = pubkey
self.profile = profile
self.prefix = ""
self.contacts = contacts
self.show_friend_confirmed = show_friend_confirmed
self.size = size
self.profiles = profiles
}
init(pubkey: String, profile: Profile?, prefix: String, contacts: Contacts, show_friend_confirmed: Bool, profiles: Profiles, size: EventViewKind = .normal) {
init(pubkey: String, profile: Profile?, prefix: String, damus: DamusState, show_friend_confirmed: Bool, size: EventViewKind = .normal) {
self.damus_state = damus
self.pubkey = pubkey
self.profile = profile
self.prefix = prefix
self.contacts = contacts
self.show_friend_confirmed = show_friend_confirmed
self.size = size
self.profiles = profiles
}
var friend_icon: String? {
if !show_friend_confirmed {
return nil
}
if self.contacts.is_friend(self.pubkey) {
return "person.fill.checkmark"
}
if self.contacts.is_friend_of_friend(self.pubkey) {
return "person.fill.and.arrow.left.and.arrow.right"
}
return nil
}
var nip05_color: Color {
contacts.is_friend(pubkey) ? .blue : .yellow
return get_friend_icon(contacts: damus_state.contacts, pubkey: pubkey, show_confirmed: show_friend_confirmed)
}
var current_nip05: NIP05? {
nip05 ?? profiles.is_validated(pubkey)
nip05 ?? damus_state.profiles.is_validated(pubkey)
}
var body: some View {
@@ -165,7 +147,7 @@ struct EventProfileName: View {
if let _ = current_nip05 {
Image(systemName: "checkmark.seal.fill")
.foregroundColor(nip05_color)
.foregroundColor(get_nip05_color(pubkey: pubkey, contacts: damus_state.contacts))
}
if let frend = friend_icon, current_nip05 == nil {
@@ -180,7 +162,11 @@ struct EventProfileName: View {
return
}
display_name = Profile.displayName(profile: update.profile, pubkey: pubkey)
nip05 = profiles.is_validated(pubkey)
nip05 = damus_state.profiles.is_validated(pubkey)
}
}
}
func get_nip05_color(pubkey: String, contacts: Contacts) -> Color {
return contacts.is_friend_or_self(pubkey) ? .accentColor : .yellow
}

View File

@@ -48,8 +48,7 @@ func follow_btn_enabled_state(_ fs: FollowState) -> Bool {
struct ProfileNameView: View {
let pubkey: String
let profile: Profile?
let contacts: Contacts
let profiles: Profiles
let damus: DamusState
var body: some View {
Group {
@@ -57,7 +56,7 @@ struct ProfileNameView: View {
VStack(alignment: .leading) {
Text(real_name)
.font(.title3.weight(.bold))
ProfileName(pubkey: pubkey, profile: profile, prefix: "@", contacts: contacts, show_friend_confirmed: true, profiles: profiles)
ProfileName(pubkey: pubkey, profile: profile, prefix: "@", damus: damus, show_friend_confirmed: true)
.font(.callout)
.foregroundColor(.gray)
KeyView(pubkey: pubkey)
@@ -65,7 +64,7 @@ struct ProfileNameView: View {
}
} else {
VStack(alignment: .leading) {
ProfileName(pubkey: pubkey, profile: profile, contacts: contacts, show_friend_confirmed: true, profiles: profiles)
ProfileName(pubkey: pubkey, profile: profile, damus: damus, show_friend_confirmed: true)
.font(.title3.weight(.bold))
KeyView(pubkey: pubkey)
.pubkey_context_menu(bech32_pubkey: pubkey)
@@ -228,7 +227,7 @@ struct ProfileView: View {
.offset(y: -15.0) // Increase if set a frame
}
ProfileNameView(pubkey: profile.pubkey, profile: data, contacts: damus_state.contacts, profiles: damus_state.profiles)
ProfileNameView(pubkey: profile.pubkey, profile: data, damus: damus_state)
//.padding(.bottom)
.padding(.top,-(pfp_size/2.0))
@@ -341,7 +340,7 @@ struct ProfileView_Previews: PreviewProvider {
func test_damus_state() -> DamusState {
let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"
let damus = DamusState(pool: RelayPool(), keypair: Keypair(pubkey: pubkey, privkey: "privkey"), likes: EventCounter(our_pubkey: pubkey), boosts: EventCounter(our_pubkey: pubkey), contacts: Contacts(), tips: TipCounter(our_pubkey: pubkey), profiles: Profiles(), dms: DirectMessagesModel(), previews: PreviewCache())
let damus = DamusState(pool: RelayPool(), keypair: Keypair(pubkey: pubkey, privkey: "privkey"), likes: EventCounter(our_pubkey: pubkey), boosts: EventCounter(our_pubkey: pubkey), contacts: Contacts(our_pubkey: pubkey), tips: TipCounter(our_pubkey: pubkey), profiles: Profiles(), dms: DirectMessagesModel(), previews: PreviewCache())
let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io")
let tsprof = TimestampedProfile(profile: prof, timestamp: 0)