add friends of friends, apply to all images

This commit is contained in:
radixrat
2022-12-24 09:56:23 -05:00
parent 63dd39c7e4
commit 1a2e9464af
13 changed files with 50 additions and 29 deletions

View File

@@ -121,7 +121,8 @@ struct TranslateView: View {
if let translated = translated_note {
// Render translated note.
let blocks = event.get_blocks(content: translated)
translated_artifacts = render_blocks(blocks: blocks, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey)
let show_images = should_show_images(contacts: damus_state.contacts, ev: event, our_pubkey: damus_state.pubkey)
translated_artifacts = render_blocks(blocks: blocks, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey, show_images: show_images)
}
checkingTranslationStatus = false

View File

@@ -17,7 +17,7 @@ struct UserView: View {
let pv = ProfileView(damus_state: damus_state, profile: pmodel, followers: followers)
NavigationLink(destination: pv) {
ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles)
ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles, contacts: damus_state.contacts)
VStack(alignment: .leading) {
let profile = damus_state.profiles.lookup(id: pubkey)

View File

@@ -11,6 +11,7 @@ import SwiftUI
enum RemoteImagePolicy: String, CaseIterable {
case everyone
case friendsOnly
case friendsOfFriends
case restricted
}
@@ -20,8 +21,10 @@ func remoteImagePolicyText(_ fs: RemoteImagePolicy) -> String {
return "Everyone"
case .friendsOnly:
return "Friends Only"
case .friendsOfFriends:
return "Friends of Friends"
case .restricted:
return "Restricted (no remote image)"
return "Block Images"
}
}
@@ -36,8 +39,8 @@ struct ConfigView: View {
@State var privkey_copied: Bool = false
@State var pubkey_copied: Bool = false
@State var delete_text: String = ""
@EnvironmentObject var user_settings: UserSettingsStore
@AppStorage("remote_image_policy") var remote_image_policy: RemoteImagePolicy = .everyone
@ObservedObject var settings: UserSettingsStore
@AppStorage("remote_image_policy") var remote_image_policy: RemoteImagePolicy = .friendsOfFriends
let generator = UIImpactFeedbackGenerator(style: .light)
@@ -147,13 +150,18 @@ struct ConfigView: View {
}
}
Section("Profile Image Loading Policy") {
Section(NSLocalizedString("Remote Image Loading Policy", comment: "Section title for remote image loading policy")) {
Menu {
Button {
self.remote_image_policy = .everyone
} label: {
Text(remoteImagePolicyText(.everyone))
}
Button {
self.remote_image_policy = .friendsOfFriends
} label: {
Text(remoteImagePolicyText(.friendsOfFriends))
}
Button {
self.remote_image_policy = .friendsOnly
} label: {

View File

@@ -120,7 +120,7 @@ struct EditMetadataView: View {
let pfp_size: CGFloat = 90.0
HStack(alignment: .center) {
ProfilePicView(pubkey: damus_state.pubkey, size: pfp_size, highlight: .custom(imageBorderColor(), 4.0), profiles: damus_state.profiles)
ProfilePicView(pubkey: damus_state.pubkey, size: pfp_size, highlight: .custom(imageBorderColor(), 4.0), profiles: damus_state.profiles, contacts: damus_state.contacts)
.offset(y: -(pfp_size/2.0)) // Increase if set a frame
Spacer()

View File

@@ -151,12 +151,18 @@ func should_show_images(contacts: Contacts, ev: NostrEvent, our_pubkey: String,
if ev.pubkey == our_pubkey {
return true
}
if contacts.is_in_friendosphere(ev.pubkey) {
let remote_image_policy: RemoteImagePolicy = RemoteImagePolicy(rawValue: UserDefaults.standard.string(forKey: "remote_image_policy") ?? "") ?? .friendsOfFriends
if remote_image_policy == .everyone ||
remote_image_policy == .friendsOnly && contacts.is_friend(ev.pubkey) ||
remote_image_policy == .friendsOfFriends && contacts.is_in_friendosphere(ev.pubkey) {
return true
}
if let boost_key = booster_pubkey, contacts.is_in_friendosphere(boost_key) {
if let boost_key = booster_pubkey, contacts.is_in_friendosphere(boost_key) && remote_image_policy != .restricted {
return true
}
return false
}

View File

@@ -35,7 +35,7 @@ struct EventProfile: View {
let pv = ProfileView(damus_state: damus_state, profile: pmodel, followers: FollowersModel(damus_state: damus_state, target: pubkey))
NavigationLink(destination: pv) {
ProfilePicView(pubkey: pubkey, size: pfp_size, highlight: .none, profiles: damus_state.profiles)
ProfilePicView(pubkey: pubkey, size: pfp_size, highlight: .none, profiles: damus_state.profiles, contacts: damus_state.contacts)
}
}

View File

@@ -65,7 +65,7 @@ struct NoteContentView: View {
var body: some View {
MainContent()
.onAppear() {
self.artifacts = render_note_content(ev: event, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey)
self.artifacts = render_note_content(ev: event, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey, show_images: show_images)
}
.onReceive(handle_notify(.profile_updated)) { notif in
let profile = notif.object as! ProfileUpdate
@@ -74,7 +74,7 @@ struct NoteContentView: View {
switch block {
case .mention(let m):
if m.type == .pubkey && m.ref.ref_id == profile.pubkey {
self.artifacts = render_note_content(ev: event, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey)
self.artifacts = render_note_content(ev: event, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey, show_images: show_images)
}
case .text: return
case .hashtag: return
@@ -261,12 +261,12 @@ struct NoteArtifacts {
}
}
func render_note_content(ev: NostrEvent, profiles: Profiles, privkey: String?) -> NoteArtifacts {
func render_note_content(ev: NostrEvent, profiles: Profiles, privkey: String?, show_images: Bool) -> NoteArtifacts {
let blocks = ev.blocks(privkey)
return render_blocks(blocks: blocks, profiles: profiles, privkey: privkey)
return render_blocks(blocks: blocks, profiles: profiles, privkey: privkey, show_images: show_images)
}
func render_blocks(blocks: [Block], profiles: Profiles, privkey: String?) -> NoteArtifacts {
func render_blocks(blocks: [Block], profiles: Profiles, privkey: String?, show_images: Bool) -> NoteArtifacts {
var invoices: [Invoice] = []
var img_urls: [URL] = []
var link_urls: [URL] = []
@@ -283,7 +283,7 @@ func render_blocks(blocks: [Block], profiles: Profiles, privkey: String?) -> Not
return str
case .url(let url):
// Handle Image URLs
if is_image_url(url) {
if show_images && is_image_url(url) {
// Append Image
img_urls.append(url)
return str

View File

@@ -39,7 +39,7 @@ struct ParticipantsView: View {
ForEach(originalReferences.pRefs) { participant in
let pubkey = participant.id
HStack {
ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles)
ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles, contacts: damus_state.contacts)
VStack(alignment: .leading) {
let profile = damus_state.profiles.lookup(id: pubkey)

View File

@@ -127,14 +127,17 @@ struct ProfilePicView: View {
}
}
func get_profile_url(picture: String?, pubkey: String, profiles: Profiles) -> URL {
func get_profile_url(picture: String?, pubkey: String, profiles: Profiles, contacts: Contacts) -> URL {
var pic: String
let remote_image_policy: RemoteImagePolicy = RemoteImagePolicy(rawValue: UserDefaults.standard.string(forKey: "remote_image_policy")!) ?? .everyone
let remote_image_policy: RemoteImagePolicy = RemoteImagePolicy(rawValue: UserDefaults.standard.string(forKey: "remote_image_policy") ?? "") ?? .friendsOfFriends
if remote_image_policy == .restricted || (remote_image_policy == .friendsOnly && !contacts.is_friend(pubkey)) {
pic = robohash(pubkey)
} else {
if pubkey == contacts.our_pubkey ||
remote_image_policy == .everyone ||
remote_image_policy == .friendsOnly && contacts.is_friend(pubkey) ||
remote_image_policy == .friendsOfFriends && contacts.is_in_friendosphere(pubkey) {
pic = picture ?? profiles.lookup(id: pubkey)?.picture ?? robohash(pubkey)
} else {
pic = robohash(pubkey)
}
if let url = URL(string: pic) {
@@ -161,7 +164,7 @@ struct ProfilePicView_Previews: PreviewProvider {
size: 100,
highlight: .none,
profiles: make_preview_profiles(pubkey),
contacts: Contacts())
contacts: Contacts(our_pubkey: pubkey))
}
}

View File

@@ -13,7 +13,7 @@ struct ProfilePictureSelector: View {
var body: some View {
let highlight: Highlight = .custom(Color.white, 2.0)
ZStack {
ProfilePicView(pubkey: pubkey, size: 80.0, highlight: highlight, profiles: Profiles(), contacts: Contacts())
ProfilePicView(pubkey: pubkey, size: 80.0, highlight: highlight, profiles: Profiles(), contacts: Contacts(our_pubkey: pubkey))
}
}
}

View File

@@ -254,12 +254,12 @@ struct ProfileView: View {
let pfp_size: CGFloat = 90.0
HStack(alignment: .center) {
ProfilePicView(pubkey: profile.pubkey, size: pfp_size, highlight: .custom(imageBorderColor(), 4.0), profiles: damus_state.profiles)
ProfilePicView(pubkey: profile.pubkey, size: pfp_size, highlight: .custom(imageBorderColor(), 4.0), profiles: damus_state.profiles, contacts: damus_state.contacts)
.onTapGesture {
is_zoomed.toggle()
}
.fullScreenCover(isPresented: $is_zoomed) {
ProfileZoomView(pubkey: profile.pubkey, profiles: damus_state.profiles) }
ProfileZoomView(pubkey: profile.pubkey, profiles: damus_state.profiles, contacts: damus_state.contacts)}
.offset(y: -(pfp_size/2.0)) // Increase if set a frame
Spacer()

View File

@@ -11,6 +11,7 @@ struct ProfileZoomView: View {
@Environment(\.presentationMode) var presentationMode
let pubkey: String
let profiles: Profiles
let contacts: Contacts
@GestureState private var scaleState: CGFloat = 1
@GestureState private var offsetState = CGSize.zero
@@ -68,7 +69,7 @@ struct ProfileZoomView: View {
Spacer()
ProfilePicView(pubkey: pubkey, size: 200.0, highlight: .none, profiles: profiles)
ProfilePicView(pubkey: pubkey, size: 200.0, highlight: .none, profiles: profiles, contacts: contacts)
.padding(100)
.scaledToFit()
.scaleEffect(self.scale * scaleState)
@@ -92,6 +93,8 @@ struct ProfileZoomView_Previews: PreviewProvider {
static var previews: some View {
ProfileZoomView(
pubkey: pubkey,
profiles: make_preview_profiles(pubkey))
profiles: make_preview_profiles(pubkey),
contacts: Contacts(our_pubkey: pubkey)
)
}
}

View File

@@ -55,7 +55,7 @@ struct SideMenuView: View {
NavigationLink(destination: ProfileView(damus_state: damus_state, profile: profile_model, followers: followers)) {
if let picture = damus_state.profiles.lookup(id: damus_state.pubkey)?.picture {
ProfilePicView(pubkey: damus_state.pubkey, size: 60, highlight: .none, profiles: damus_state.profiles, picture: picture)
ProfilePicView(pubkey: damus_state.pubkey, size: 60, highlight: .none, profiles: damus_state.profiles, contacts: damus_state.contacts, picture: picture)
} else {
Image(systemName: "person.fill")
}