add remote loading image setting

This commit is contained in:
radixrat
2023-02-02 13:53:57 -08:00
parent 331d7e9792
commit 40be9885c5
7 changed files with 56 additions and 12 deletions

View File

@@ -252,7 +252,7 @@ struct ContentView: View {
Button {
isSideBarOpened.toggle()
} label: {
ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles)
ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, contacts: damus_state!.contacts)
}
}

View File

@@ -75,7 +75,7 @@ struct ChatView: View {
HStack {
VStack {
if is_active || just_started {
ProfilePicView(pubkey: event.pubkey, size: 32, highlight: is_active ? .main : .none, profiles: damus_state.profiles)
ProfilePicView(pubkey: event.pubkey, size: 32, highlight: is_active ? .main : .none, profiles: damus_state.profiles, contacts:damus_state.contacts)
}
Spacer()
@@ -97,7 +97,7 @@ struct ChatView: View {
if let ref_id = thread.replies.lookup(event.id) {
if !is_reply_to_prev() {
/*
ReplyQuoteView(keypair: damus_state.keypair, quoter: event, event_id: ref_id, profiles: damus_state.profiles, previews: damus_state.previews)
ReplyQuoteView(keypair: damus_state.keypair, quoter: event, event_id: ref_id, profiles: damus_state.profiles, previews: damus_state.previews, contacts: damus_state.contacts)
.frame(maxHeight: expand_reply ? nil : 100)
.environmentObject(thread)
.onTapGesture {

View File

@@ -19,8 +19,8 @@ struct ConfigView: View {
@State var privkey_copied: Bool = false
@State var pubkey_copied: Bool = false
@State var delete_text: String = ""
@ObservedObject var settings: UserSettingsStore
@AppStorage("remote_image_policy") var remote_image_policy: String = "everyone"
let generator = UIImpactFeedbackGenerator(style: .light)
@@ -129,7 +129,30 @@ struct ConfigView: View {
KingfisherManager.shared.cache.cleanExpiredDiskCache()
}
}
Section("Profile Image Loading Policy") {
Menu {
Button {
UserDefaults.standard.set("everyone", forKey:"remote_image_policy")
} label: {
Text("Everyone")
}
Button {
UserDefaults.standard.set("friends", forKey:"remote_image_policy")
} label: {
Text("Friends Only")
}
Button {
UserDefaults.standard.set("restricted", forKey:"remote_image_policy")
} label: {
Text("Restricted")
}
} label: {
Text("\(convertImageLoadPolicyTxt(policy:remote_image_policy))")
.frame(maxWidth: .infinity, alignment: .leading)
}
}
if state.is_privkey_user {
Section(NSLocalizedString("Delete", comment: "Section title for deleting the user")) {
Button(NSLocalizedString("Delete Account", comment: "Button to delete the user's account."), role: .destructive) {
@@ -176,6 +199,17 @@ struct ConfigView: View {
}
}
func convertImageLoadPolicyTxt(policy: String) -> String {
switch policy {
case "restricted":
return "Restricted"
case "friends":
return "Friends Only"
default:
return "Everyone"
}
}
struct ConfigView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {

View File

@@ -42,7 +42,7 @@ struct DMChatView: View {
let profile_page = ProfileView(damus_state: damus_state, profile: pmodel, followers: fmodel)
return NavigationLink(destination: profile_page) {
HStack {
ProfilePicView(pubkey: pubkey, size: 24, highlight: .none, profiles: damus_state.profiles)
ProfilePicView(pubkey: pubkey, size: 24, highlight: .none, profiles: damus_state.profiles, contacts:damus_state.contacts)
ProfileName(pubkey: pubkey, profile: profile, damus: damus_state, show_friend_confirmed: true)
}

View File

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

View File

@@ -98,19 +98,21 @@ struct ProfilePicView: View {
let size: CGFloat
let highlight: Highlight
let profiles: Profiles
let contacts: Contacts
@State var picture: String?
init (pubkey: String, size: CGFloat, highlight: Highlight, profiles: Profiles, picture: String? = nil) {
init (pubkey: String, size: CGFloat, highlight: Highlight, profiles: Profiles, contacts: Contacts, picture: String? = nil) {
self.pubkey = pubkey
self.profiles = profiles
self.contacts = contacts
self.size = size
self.highlight = highlight
self._picture = State(initialValue: picture)
}
var body: some View {
InnerProfilePicView(url: get_profile_url(picture: picture, pubkey: pubkey, profiles: profiles), fallbackUrl: URL(string: robohash(pubkey)), pubkey: pubkey, size: size, highlight: highlight)
InnerProfilePicView(url: get_profile_url(picture: picture, pubkey: pubkey, profiles: profiles, contacts: contacts), fallbackUrl: URL(string: robohash(pubkey)), pubkey: pubkey, size: size, highlight: highlight)
.onReceive(handle_notify(.profile_updated)) { notif in
let updated = notif.object as! ProfileUpdate
@@ -126,7 +128,14 @@ struct ProfilePicView: View {
}
func get_profile_url(picture: String?, pubkey: String, profiles: Profiles) -> URL {
let pic = picture ?? profiles.lookup(id: pubkey)?.picture ?? robohash(pubkey)
var pic: String
let remote_image_policy = UserDefaults.standard.string(forKey: "remote_image_policy")
if remote_image_policy == "restricted" || (remote_image_policy == "friends" && !contacts.is_friend(pubkey)) {
pic = robohash(pubkey)
} else {
pic = picture ?? profiles.lookup(id: pubkey)?.picture ?? robohash(pubkey)
}
if let url = URL(string: pic) {
return url
}
@@ -150,7 +159,8 @@ struct ProfilePicView_Previews: PreviewProvider {
pubkey: pubkey,
size: 100,
highlight: .none,
profiles: make_preview_profiles(pubkey))
profiles: make_preview_profiles(pubkey),
contacts: Contacts())
}
}

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())
ProfilePicView(pubkey: pubkey, size: 80.0, highlight: highlight, profiles: Profiles(), contacts: Contacts())
}
}
}