commit 22cad4b07233695c28c70edad1a8eb2079dd0604
parent a59cb04ce0b36bc6860e7b8c81a242b935429df4
Author: William Casarin <jb55@jb55.com>
Date: Tue, 9 Aug 2022 16:48:47 -0700
wot: show friend icons is some views
easier to detect if someone is trying to fake us out
Changelog-Added: Friend icons next to names on some views. Check is friend. Arrows are friend-of-friends
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
13 files changed, 61 insertions(+), 25 deletions(-)
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -90,7 +90,7 @@ struct ContentView: View {
var PostingTimelineView: some View {
ZStack {
if let damus = self.damus_state {
- TimelineView(events: $home.events, loading: $home.loading, damus: damus)
+ TimelineView(events: $home.events, loading: $home.loading, damus: damus, show_friend_icon: false)
}
if privkey != nil {
PostButtonContainer {
@@ -119,7 +119,7 @@ struct ContentView: View {
PostingTimelineView
case .notifications:
- TimelineView(events: $home.notifications, loading: $home.loading, damus: damus)
+ TimelineView(events: $home.notifications, loading: $home.loading, damus: damus, show_friend_icon: true)
.navigationTitle("Notifications")
case .dms:
diff --git a/damus/Views/ChatView.swift b/damus/Views/ChatView.swift
@@ -85,7 +85,7 @@ struct ChatView: View {
VStack(alignment: .leading) {
if just_started {
HStack {
- ProfileName(pubkey: event.pubkey, profile: damus_state.profiles.lookup(id: event.pubkey))
+ ProfileName(pubkey: event.pubkey, profile: damus_state.profiles.lookup(id: event.pubkey), contacts: damus_state.contacts, 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
@@ -39,7 +39,7 @@ struct DMChatView: View {
HStack {
ProfilePicView(pubkey: pubkey, size: 24, highlight: .none, image_cache: damus_state.image_cache, profiles: damus_state.profiles)
- ProfileName(pubkey: pubkey, profile: profile)
+ ProfileName(pubkey: pubkey, profile: profile, contacts: damus_state.contacts, show_friend_confirmed: true)
}
}
.buttonStyle(PlainButtonStyle())
diff --git a/damus/Views/DirectMessagesView.swift b/damus/Views/DirectMessagesView.swift
@@ -27,7 +27,7 @@ struct DirectMessagesView: View {
let chat = DMChatView(damus_state: damus_state, pubkey: tup.0)
.environmentObject(tup.1)
NavigationLink(destination: chat) {
- EventView(damus: damus_state, event: ev, pubkey: tup.0)
+ EventView(damus: damus_state, event: ev, pubkey: tup.0, show_friend_icon: true)
}
.buttonStyle(PlainButtonStyle())
} else {
diff --git a/damus/Views/EventDetailView.swift b/damus/Views/EventDetailView.swift
@@ -71,7 +71,7 @@ struct EventDetailView: View {
toggle_thread_view()
}
case .event(let ev, let highlight):
- EventView(event: ev, highlight: highlight, has_action_bar: true, damus: damus)
+ EventView(event: ev, highlight: highlight, has_action_bar: true, damus: damus, show_friend_icon: true)
.onTapGesture {
if thread.initial_event.id == ev.id {
toggle_thread_view()
diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift
@@ -42,31 +42,35 @@ struct EventView: View {
let has_action_bar: Bool
let damus: DamusState
let pubkey: String
+ let show_friend_icon: Bool
@EnvironmentObject var action_bar: ActionBarModel
- init(event: NostrEvent, highlight: Highlight, has_action_bar: Bool, damus: DamusState) {
+ init(event: NostrEvent, highlight: Highlight, has_action_bar: Bool, damus: DamusState, show_friend_icon: Bool) {
self.event = event
self.highlight = highlight
self.has_action_bar = has_action_bar
self.damus = damus
self.pubkey = event.pubkey
+ self.show_friend_icon = show_friend_icon
}
- init(damus: DamusState, event: NostrEvent) {
+ init(damus: DamusState, event: NostrEvent, show_friend_icon: Bool) {
self.event = event
self.highlight = .none
self.has_action_bar = false
self.damus = damus
self.pubkey = event.pubkey
+ self.show_friend_icon = show_friend_icon
}
- init(damus: DamusState, event: NostrEvent, pubkey: String) {
+ init(damus: DamusState, event: NostrEvent, pubkey: String, show_friend_icon: Bool) {
self.event = event
self.highlight = .none
self.has_action_bar = false
self.damus = damus
self.pubkey = pubkey
+ self.show_friend_icon = show_friend_icon
}
var body: some View {
@@ -81,7 +85,7 @@ struct EventView: View {
HStack {
Label("", systemImage: "arrow.2.squarepath")
.foregroundColor(Color.gray)
- ProfileName(pubkey: event.pubkey, profile: damus.profiles.lookup(id: event.pubkey))
+ ProfileName(pubkey: event.pubkey, profile: damus.profiles.lookup(id: event.pubkey), contacts: damus.contacts, show_friend_confirmed: show_friend_icon)
.foregroundColor(Color.gray)
Text(" Boosted")
.foregroundColor(Color.gray)
@@ -113,7 +117,7 @@ struct EventView: View {
VStack(alignment: .leading) {
HStack(alignment: .center) {
- ProfileName(pubkey: pubkey, profile: profile)
+ ProfileName(pubkey: pubkey, profile: profile, contacts: damus.contacts, show_friend_confirmed: show_friend_icon)
Text("\(format_relative_time(event.created_at))")
.foregroundColor(.gray)
}
diff --git a/damus/Views/FollowingView.swift b/damus/Views/FollowingView.swift
@@ -22,7 +22,7 @@ struct FollowUserView: View {
VStack(alignment: .leading) {
let profile = damus_state.profiles.lookup(id: target.pubkey)
- ProfileName(pubkey: target.pubkey, profile: profile)
+ ProfileName(pubkey: target.pubkey, profile: profile, contacts: damus_state.contacts, show_friend_confirmed: false)
if let about = profile.flatMap { $0.about } {
Text(about)
}
diff --git a/damus/Views/ProfileName.swift b/damus/Views/ProfileName.swift
@@ -10,6 +10,7 @@ import SwiftUI
struct ProfileFullName: View {
let pubkey: String
let profile: Profile?
+ let contacts: Contacts
@State var display_name: String?
@@ -18,11 +19,11 @@ struct ProfileFullName: View {
if let real_name = profile?.display_name {
Text(real_name)
.bold()
- ProfileName(pubkey: pubkey, profile: profile, prefix: "@")
+ ProfileName(pubkey: pubkey, profile: profile, prefix: "@", contacts: contacts, show_friend_confirmed: true)
.font(.footnote)
.foregroundColor(.gray)
} else {
- ProfileName(pubkey: pubkey, profile: profile)
+ ProfileName(pubkey: pubkey, profile: profile, contacts: contacts, show_friend_confirmed: true)
}
}
}
@@ -31,20 +32,43 @@ struct ProfileFullName: View {
struct ProfileName: View {
let pubkey: String
let profile: Profile?
+ let contacts: Contacts
let prefix: String
+ let show_friend_confirmed: Bool
+
@State var display_name: String?
- init(pubkey: String, profile: Profile?) {
+ init(pubkey: String, profile: Profile?, contacts: Contacts, show_friend_confirmed: Bool) {
self.pubkey = pubkey
self.profile = profile
self.prefix = ""
+ self.contacts = contacts
+ self.show_friend_confirmed = show_friend_confirmed
}
- init(pubkey: String, profile: Profile?, prefix: String) {
+ init(pubkey: String, profile: Profile?, prefix: String, contacts: Contacts, show_friend_confirmed: Bool) {
self.pubkey = pubkey
self.profile = profile
self.prefix = prefix
+ self.contacts = contacts
+ self.show_friend_confirmed = show_friend_confirmed
+ }
+
+ 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 body: some View {
@@ -52,6 +76,11 @@ struct ProfileName: View {
Text(prefix + String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey)))
//.foregroundColor(hex_to_rgb(pubkey))
.fontWeight(prefix == "@" ? .none : .bold)
+ if let frend = friend_icon {
+ Label("", systemImage: frend)
+ .foregroundColor(.gray)
+ .font(.footnote)
+ }
}
.onReceive(handle_notify(.profile_updated)) { notif in
let update = notif.object as! ProfileUpdate
diff --git a/damus/Views/ProfileView.swift b/damus/Views/ProfileView.swift
@@ -48,6 +48,7 @@ func follow_btn_enabled_state(_ fs: FollowState) -> Bool {
struct ProfileNameView: View {
let pubkey: String
let profile: Profile?
+ let contacts: Contacts
var body: some View {
Group {
@@ -55,12 +56,12 @@ struct ProfileNameView: View {
VStack(alignment: .leading) {
Text(real_name)
.font(.title)
- ProfileName(pubkey: pubkey, profile: profile, prefix: "@")
+ ProfileName(pubkey: pubkey, profile: profile, prefix: "@", contacts: contacts, show_friend_confirmed: true)
.font(.callout)
.foregroundColor(.gray)
}
} else {
- ProfileName(pubkey: pubkey, profile: profile)
+ ProfileName(pubkey: pubkey, profile: profile, contacts: contacts, show_friend_confirmed: true)
}
}
}
@@ -94,7 +95,7 @@ struct ProfileView: View {
HStack(alignment: .center) {
ProfilePicView(pubkey: profile.pubkey, size: PFP_SIZE, highlight: .custom(Color.black, 2), image_cache: damus_state.image_cache, profiles: damus_state.profiles)
- ProfileNameView(pubkey: profile.pubkey, profile: data)
+ ProfileNameView(pubkey: profile.pubkey, profile: data, contacts: damus_state.contacts)
Spacer()
@@ -146,7 +147,7 @@ struct ProfileView: View {
Divider()
- InnerTimelineView(events: $profile.events, damus: damus_state)
+ InnerTimelineView(events: $profile.events, damus: damus_state, show_friend_icon: false)
}
.frame(maxHeight: .infinity, alignment: .topLeading)
}
diff --git a/damus/Views/ReplyView.swift b/damus/Views/ReplyView.swift
@@ -33,7 +33,7 @@ struct ReplyView: View {
.foregroundColor(.gray)
.font(.footnote)
}
- EventView(event: replying_to, highlight: .none, has_action_bar: false, damus: damus)
+ EventView(event: replying_to, highlight: .none, has_action_bar: false, damus: damus, show_friend_icon: true)
PostView(references: gather_reply_ids(our_pubkey: damus.pubkey, from: replying_to))
}
.padding()
diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift
@@ -39,7 +39,7 @@ struct SearchHomeView: View {
}
var GlobalContent: some View {
- TimelineView(events: $model.events, loading: $model.loading, damus: damus_state)
+ TimelineView(events: $model.events, loading: $model.loading, damus: damus_state, show_friend_icon: true)
}
var SearchContent: some View {
diff --git a/damus/Views/SearchView.swift b/damus/Views/SearchView.swift
@@ -13,7 +13,7 @@ struct SearchView: View {
@Environment(\.dismiss) var dismiss
var body: some View {
- TimelineView(events: $search.events, loading: $search.loading, damus: appstate)
+ TimelineView(events: $search.events, loading: $search.loading, damus: appstate, show_friend_icon: true)
.navigationBarTitle(describe_search(search.search))
.padding([.leading, .trailing], 6)
.onReceive(handle_notify(.switched_timeline)) { obj in
diff --git a/damus/Views/TimelineView.swift b/damus/Views/TimelineView.swift
@@ -15,6 +15,7 @@ enum TimelineAction {
struct InnerTimelineView: View {
@Binding var events: [NostrEvent]
let damus: DamusState
+ let show_friend_icon: Bool
var body: some View {
LazyVStack {
@@ -22,7 +23,7 @@ struct InnerTimelineView: View {
let tv = ThreadView(thread: ThreadModel(event: ev, pool: damus.pool, privkey: damus.keypair.privkey), damus: damus, is_chatroom: has_hashtag(ev.tags, hashtag: "chat"))
NavigationLink(destination: tv) {
- EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus)
+ EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus, show_friend_icon: show_friend_icon)
}
.isDetailLink(true)
.buttonStyle(PlainButtonStyle())
@@ -36,6 +37,7 @@ struct TimelineView: View {
@Binding var loading: Bool
let damus: DamusState
+ let show_friend_icon: Bool
var body: some View {
MainContent
@@ -48,7 +50,7 @@ struct TimelineView: View {
ProgressView()
.progressViewStyle(.circular)
}
- InnerTimelineView(events: $events, damus: damus)
+ InnerTimelineView(events: $events, damus: damus, show_friend_icon: show_friend_icon)
}
.onReceive(NotificationCenter.default.publisher(for: .scroll_to_top)) { _ in
guard let event = events.first else {