commit 5ba5a686287755c462a84626469320a1545d2c73
parent 89c857d3e96e0c02548c0881418d47b8d47bcb78
Author: William Casarin <jb55@jb55.com>
Date: Wed, 4 Jan 2023 10:06:19 -0800
Switch from bluecheck to purplecheck
This commit also refactors a bunch of crap
Changelog-Changed: Switch from bluecheck to purplecheck
Diffstat:
9 files changed, 61 insertions(+), 67 deletions(-)
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -421,7 +421,7 @@ struct ContentView: View {
self.damus_state = DamusState(pool: pool, keypair: keypair,
likes: EventCounter(our_pubkey: pubkey),
boosts: EventCounter(our_pubkey: pubkey),
- contacts: Contacts(),
+ contacts: Contacts(our_pubkey: pubkey),
tips: TipCounter(our_pubkey: pubkey),
profiles: Profiles(),
dms: home.dms,
diff --git a/damus/Models/Contacts.swift b/damus/Models/Contacts.swift
@@ -11,8 +11,13 @@ import Foundation
class Contacts {
private var friends: Set<String> = Set()
private var friend_of_friends: Set<String> = Set()
+ let our_pubkey: String
var event: NostrEvent?
+ init(our_pubkey: String) {
+ self.our_pubkey = our_pubkey
+ }
+
func get_friendosphere() -> [String] {
var fs = get_friend_list()
fs.append(contentsOf: get_friend_of_friend_list())
@@ -56,6 +61,10 @@ class Contacts {
return friends.contains(pubkey)
}
+ func is_friend_or_self(_ pubkey: String) -> Bool {
+ return pubkey == our_pubkey || is_friend(pubkey)
+ }
+
func follow_state(_ pubkey: String) -> FollowState {
return is_friend(pubkey) ? .follows : .unfollows
}
diff --git a/damus/Models/DamusState.swift b/damus/Models/DamusState.swift
@@ -24,6 +24,6 @@ struct DamusState {
}
static var empty: DamusState {
- return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(), tips: TipCounter(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(), previews: PreviewCache())
+ return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), tips: TipCounter(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(), previews: PreviewCache())
}
}
diff --git a/damus/Views/ChatView.swift b/damus/Views/ChatView.swift
@@ -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))")
diff --git a/damus/Views/DMChatView.swift b/damus/Views/DMChatView.swift
@@ -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())
diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift
@@ -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))
diff --git a/damus/Views/FollowingView.swift b/damus/Views/FollowingView.swift
@@ -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)
diff --git a/damus/Views/ProfileName.swift b/damus/Views/ProfileName.swift
@@ -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
+ return get_friend_icon(contacts: damus_state.contacts, pubkey: pubkey, show_confirmed: show_friend_confirmed)
}
- var nip05_color: Color {
- contacts.is_friend(pubkey) ? .blue : .yellow
+ var current_nip05: NIP05? {
+ nip05 ?? damus_state.profiles.is_validated(pubkey)
}
- var current_nip05: NIP05? {
- nip05 ?? 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
+}
diff --git a/damus/Views/ProfileView.swift b/damus/Views/ProfileView.swift
@@ -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)