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:
@@ -421,7 +421,7 @@ struct ContentView: View {
|
|||||||
self.damus_state = DamusState(pool: pool, keypair: keypair,
|
self.damus_state = DamusState(pool: pool, keypair: keypair,
|
||||||
likes: EventCounter(our_pubkey: pubkey),
|
likes: EventCounter(our_pubkey: pubkey),
|
||||||
boosts: EventCounter(our_pubkey: pubkey),
|
boosts: EventCounter(our_pubkey: pubkey),
|
||||||
contacts: Contacts(),
|
contacts: Contacts(our_pubkey: pubkey),
|
||||||
tips: TipCounter(our_pubkey: pubkey),
|
tips: TipCounter(our_pubkey: pubkey),
|
||||||
profiles: Profiles(),
|
profiles: Profiles(),
|
||||||
dms: home.dms,
|
dms: home.dms,
|
||||||
|
|||||||
@@ -11,8 +11,13 @@ import Foundation
|
|||||||
class Contacts {
|
class Contacts {
|
||||||
private var friends: Set<String> = Set()
|
private var friends: Set<String> = Set()
|
||||||
private var friend_of_friends: Set<String> = Set()
|
private var friend_of_friends: Set<String> = Set()
|
||||||
|
let our_pubkey: String
|
||||||
var event: NostrEvent?
|
var event: NostrEvent?
|
||||||
|
|
||||||
|
init(our_pubkey: String) {
|
||||||
|
self.our_pubkey = our_pubkey
|
||||||
|
}
|
||||||
|
|
||||||
func get_friendosphere() -> [String] {
|
func get_friendosphere() -> [String] {
|
||||||
var fs = get_friend_list()
|
var fs = get_friend_list()
|
||||||
fs.append(contentsOf: get_friend_of_friend_list())
|
fs.append(contentsOf: get_friend_of_friend_list())
|
||||||
@@ -56,6 +61,10 @@ class Contacts {
|
|||||||
return friends.contains(pubkey)
|
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 {
|
func follow_state(_ pubkey: String) -> FollowState {
|
||||||
return is_friend(pubkey) ? .follows : .unfollows
|
return is_friend(pubkey) ? .follows : .unfollows
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,6 @@ struct DamusState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static var empty: 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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ struct ChatView: View {
|
|||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
if just_started {
|
if just_started {
|
||||||
HStack {
|
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)
|
.foregroundColor(colorScheme == .dark ? id_to_color(event.pubkey) : Color.black)
|
||||||
//.shadow(color: Color.black, radius: 2)
|
//.shadow(color: Color.black, radius: 2)
|
||||||
Text("\(format_relative_time(event.created_at))")
|
Text("\(format_relative_time(event.created_at))")
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ struct DMChatView: View {
|
|||||||
HStack {
|
HStack {
|
||||||
ProfilePicView(pubkey: pubkey, size: 24, highlight: .none, profiles: damus_state.profiles)
|
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())
|
.buttonStyle(PlainButtonStyle())
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ struct EventView: View {
|
|||||||
Image(systemName: "arrow.2.squarepath")
|
Image(systemName: "arrow.2.squarepath")
|
||||||
.font(.footnote.weight(.bold))
|
.font(.footnote.weight(.bold))
|
||||||
.foregroundColor(Color.gray)
|
.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))
|
.font(.footnote.weight(.bold))
|
||||||
.foregroundColor(Color.gray)
|
.foregroundColor(Color.gray)
|
||||||
Text("Boosted")
|
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 {
|
if size != .selected {
|
||||||
Text("\(format_relative_time(event.created_at))")
|
Text("\(format_relative_time(event.created_at))")
|
||||||
.font(eventviewsize_to_font(size))
|
.font(eventviewsize_to_font(size))
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ struct FollowUserView: View {
|
|||||||
|
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
let profile = damus_state.profiles.lookup(id: target.pubkey)
|
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 {
|
if let about = profile?.about {
|
||||||
Text(FollowUserView.markdown.process(about))
|
Text(FollowUserView.markdown.process(about))
|
||||||
.lineLimit(3)
|
.lineLimit(3)
|
||||||
|
|||||||
@@ -7,58 +7,59 @@
|
|||||||
|
|
||||||
import SwiftUI
|
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 {
|
struct ProfileName: View {
|
||||||
|
let damus_state: DamusState
|
||||||
let pubkey: String
|
let pubkey: String
|
||||||
let profile: Profile?
|
let profile: Profile?
|
||||||
let contacts: Contacts
|
|
||||||
let prefix: String
|
let prefix: String
|
||||||
|
|
||||||
let show_friend_confirmed: Bool
|
let show_friend_confirmed: Bool
|
||||||
let profiles: Profiles
|
|
||||||
|
|
||||||
@State var display_name: String?
|
@State var display_name: String?
|
||||||
@State var nip05: NIP05?
|
@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.pubkey = pubkey
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
self.prefix = ""
|
self.prefix = ""
|
||||||
self.contacts = contacts
|
|
||||||
self.show_friend_confirmed = show_friend_confirmed
|
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.pubkey = pubkey
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
self.contacts = contacts
|
self.damus_state = damus
|
||||||
self.show_friend_confirmed = show_friend_confirmed
|
self.show_friend_confirmed = show_friend_confirmed
|
||||||
self.profiles = profiles
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var friend_icon: String? {
|
var friend_icon: String? {
|
||||||
if !show_friend_confirmed {
|
return get_friend_icon(contacts: damus_state.contacts, pubkey: pubkey, show_confirmed: 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var current_nip05: NIP05? {
|
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 {
|
var body: some View {
|
||||||
@@ -83,68 +84,49 @@ struct ProfileName: View {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
display_name = Profile.displayName(profile: update.profile, pubkey: pubkey)
|
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
|
/// Profile Name used when displaying an event in the timeline
|
||||||
struct EventProfileName: View {
|
struct EventProfileName: View {
|
||||||
|
let damus_state: DamusState
|
||||||
let pubkey: String
|
let pubkey: String
|
||||||
let profile: Profile?
|
let profile: Profile?
|
||||||
let contacts: Contacts
|
|
||||||
let prefix: String
|
let prefix: String
|
||||||
|
|
||||||
let show_friend_confirmed: Bool
|
let show_friend_confirmed: Bool
|
||||||
let profiles: Profiles
|
|
||||||
|
|
||||||
@State var display_name: String?
|
@State var display_name: String?
|
||||||
@State var nip05: NIP05?
|
@State var nip05: NIP05?
|
||||||
|
|
||||||
let size: EventViewKind
|
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.pubkey = pubkey
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
self.prefix = ""
|
self.prefix = ""
|
||||||
self.contacts = contacts
|
|
||||||
self.show_friend_confirmed = show_friend_confirmed
|
self.show_friend_confirmed = show_friend_confirmed
|
||||||
self.size = size
|
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.pubkey = pubkey
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
self.contacts = contacts
|
|
||||||
self.show_friend_confirmed = show_friend_confirmed
|
self.show_friend_confirmed = show_friend_confirmed
|
||||||
self.size = size
|
self.size = size
|
||||||
self.profiles = profiles
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var friend_icon: String? {
|
var friend_icon: String? {
|
||||||
if !show_friend_confirmed {
|
return get_friend_icon(contacts: damus_state.contacts, pubkey: pubkey, show_confirmed: 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var current_nip05: NIP05? {
|
var current_nip05: NIP05? {
|
||||||
nip05 ?? profiles.is_validated(pubkey)
|
nip05 ?? damus_state.profiles.is_validated(pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -165,7 +147,7 @@ struct EventProfileName: View {
|
|||||||
|
|
||||||
if let _ = current_nip05 {
|
if let _ = current_nip05 {
|
||||||
Image(systemName: "checkmark.seal.fill")
|
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 {
|
if let frend = friend_icon, current_nip05 == nil {
|
||||||
@@ -180,7 +162,11 @@ struct EventProfileName: View {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
display_name = Profile.displayName(profile: update.profile, pubkey: pubkey)
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ func follow_btn_enabled_state(_ fs: FollowState) -> Bool {
|
|||||||
struct ProfileNameView: View {
|
struct ProfileNameView: View {
|
||||||
let pubkey: String
|
let pubkey: String
|
||||||
let profile: Profile?
|
let profile: Profile?
|
||||||
let contacts: Contacts
|
let damus: DamusState
|
||||||
let profiles: Profiles
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Group {
|
Group {
|
||||||
@@ -57,7 +56,7 @@ struct ProfileNameView: View {
|
|||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
Text(real_name)
|
Text(real_name)
|
||||||
.font(.title3.weight(.bold))
|
.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)
|
.font(.callout)
|
||||||
.foregroundColor(.gray)
|
.foregroundColor(.gray)
|
||||||
KeyView(pubkey: pubkey)
|
KeyView(pubkey: pubkey)
|
||||||
@@ -65,7 +64,7 @@ struct ProfileNameView: View {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
VStack(alignment: .leading) {
|
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))
|
.font(.title3.weight(.bold))
|
||||||
KeyView(pubkey: pubkey)
|
KeyView(pubkey: pubkey)
|
||||||
.pubkey_context_menu(bech32_pubkey: pubkey)
|
.pubkey_context_menu(bech32_pubkey: pubkey)
|
||||||
@@ -228,7 +227,7 @@ struct ProfileView: View {
|
|||||||
.offset(y: -15.0) // Increase if set a frame
|
.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(.bottom)
|
||||||
.padding(.top,-(pfp_size/2.0))
|
.padding(.top,-(pfp_size/2.0))
|
||||||
|
|
||||||
@@ -341,7 +340,7 @@ struct ProfileView_Previews: PreviewProvider {
|
|||||||
|
|
||||||
func test_damus_state() -> DamusState {
|
func test_damus_state() -> DamusState {
|
||||||
let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"
|
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 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)
|
let tsprof = TimestampedProfile(profile: prof, timestamp: 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user