commit a80ddc08ec678753c2f84b58ee9f5acbf0a915a6
parent 6daa4f7e13c5669139b202464918c0330c83b4a8
Author: ericholguin <eric.holguinsanchez@gmail.com>
Date: Tue, 21 Nov 2023 17:31:16 -0700
settings: add media previews setting
Closes: https://github.com/damus-io/damus/pull/1757
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 63 insertions(+), 14 deletions(-)
diff --git a/damus/Models/UserSettingsStore.swift b/damus/Models/UserSettingsStore.swift
@@ -110,6 +110,9 @@ class UserSettingsStore: ObservableObject {
@Setting(key: "always_show_images", default_value: false)
var always_show_images: Bool
+ @Setting(key: "media_previews", default_value: true)
+ var media_previews: Bool
+
@Setting(key: "hide_nsfw_tagged_content", default_value: false)
var hide_nsfw_tagged_content: Bool
diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift
@@ -27,6 +27,7 @@ struct NoteContentView: View {
let damus_state: DamusState
let event: NostrEvent
@State var show_images: Bool
+ @State var load_media: Bool = false
let size: EventViewKind
let preview_height: CGFloat?
let options: EventViewOptions
@@ -132,18 +133,21 @@ struct NoteContentView: View {
translateView
}
}
-
- if show_images && artifacts.media.count > 0 {
- ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media)
- } else if !show_images && artifacts.media.count > 0 {
- ZStack {
+
+ if artifacts.media.count > 0 {
+ if !damus_state.settings.media_previews && !load_media {
+ loadMediaButton(artifacts: artifacts)
+ } else if show_images || (show_images && !damus_state.settings.media_previews && load_media) {
ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media)
- Blur()
- .onTapGesture {
- show_images = true
- }
+ } else if !show_images || (!show_images && !damus_state.settings.media_previews && load_media) {
+ ZStack {
+ ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media)
+ Blur()
+ .onTapGesture {
+ show_images = true
+ }
+ }
}
- //.cornerRadius(10)
}
if artifacts.invoices.count > 0 {
@@ -155,15 +159,54 @@ struct NoteContentView: View {
}
}
- if with_padding {
- previewView(links: artifacts.links).padding(.horizontal)
- } else {
- previewView(links: artifacts.links)
+ if damus_state.settings.media_previews {
+ if with_padding {
+ previewView(links: artifacts.links).padding(.horizontal)
+ } else {
+ previewView(links: artifacts.links)
+ }
}
}
}
+ func loadMediaButton(artifacts: NoteArtifactsSeparated) -> some View {
+ Button(action: {
+ load_media = true
+ }, label: {
+ VStack(alignment: .leading) {
+ HStack {
+ Image("images")
+ Text("Load media", comment: "Button to show media in note.")
+ .fontWeight(.bold)
+ .font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size))
+ }
+ .padding(EdgeInsets(top: 5, leading: 10, bottom: 0, trailing: 10))
+
+ ForEach(artifacts.media.indices, id: \.self) { index in
+ Divider()
+ .frame(height: 1)
+ switch artifacts.media[index] {
+ case .image(let url), .video(let url):
+ Text("\(url)")
+ .font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size))
+ .foregroundStyle(DamusColors.neutral6)
+ .multilineTextAlignment(.leading)
+ .padding(EdgeInsets(top: 0, leading: 10, bottom: 5, trailing: 10))
+ }
+ }
+ }
+ .background(DamusColors.neutral1)
+ .frame(minWidth: 300, maxWidth: .infinity, alignment: .center)
+ .cornerRadius(8)
+ .overlay(
+ RoundedRectangle(cornerRadius: 8)
+ .stroke(DamusColors.neutral3, lineWidth: 1)
+ )
+ })
+ .padding(.horizontal)
+ }
+
func load(force_artifacts: Bool = false) {
// always reload artifacts on load
let plan = get_preload_plan(evcache: damus_state.events, ev: event, our_keypair: damus_state.keypair, settings: damus_state.settings)
diff --git a/damus/Views/Settings/AppearanceSettingsView.swift b/damus/Views/Settings/AppearanceSettingsView.swift
@@ -81,6 +81,9 @@ struct AppearanceSettingsView: View {
Toggle(NSLocalizedString("Always show images", comment: "Setting to always show and never blur images"), isOn: $settings.always_show_images)
.toggleStyle(.switch)
+ Toggle(NSLocalizedString("Media previews", comment: "Setting to show media"), isOn: $settings.media_previews)
+ .toggleStyle(.switch)
+
Picker(NSLocalizedString("Image uploader", comment: "Prompt selection of user's image uploader"),
selection: $settings.default_media_uploader) {
ForEach(MediaUploader.allCases, id: \.self) { uploader in