From de4e8e5748656fd1da43439aaed3bf0fc5566c9b Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 11 Jul 2023 12:56:30 -0700 Subject: [PATCH] Only show longform preview in notifications Changelog-Fixed: Show longform previews in notifications instead of the entire post --- damus/Views/Events/EventBody.swift | 25 ++++++----- .../Events/Longform/LongformPreview.swift | 45 ++++++++++++++----- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/damus/Views/Events/EventBody.swift b/damus/Views/Events/EventBody.swift index 0a822556..37cdda15 100644 --- a/damus/Views/Events/EventBody.swift +++ b/damus/Views/Events/EventBody.swift @@ -21,19 +21,24 @@ struct EventBody: View { self.options = options self.should_show_img = should_show_img ?? should_show_images(settings: damus_state.settings, contacts: damus_state.contacts, ev: event, our_pubkey: damus_state.pubkey) } - - var body: some View { - if event.known_kind == .longform { - let longform = LongformEvent.parse(from: event) - - Text(longform.title ?? "Untitled") - .font(.title) - .padding(.horizontal) - } - + + var note_content: some View { NoteContentView(damus_state: damus_state, event: event, show_images: should_show_img, size: size, options: options) .frame(maxWidth: .infinity, alignment: .leading) } + + var body: some View { + if event.known_kind == .longform { + LongformPreviewBody(state: damus_state, ev: event, options: options) + + // truncated longform bodies are just the preview + if !options.contains(.truncate_content) { + note_content + } + } else { + note_content + } + } } struct EventBody_Previews: PreviewProvider { diff --git a/damus/Views/Events/Longform/LongformPreview.swift b/damus/Views/Events/Longform/LongformPreview.swift index 3f96df81..e3bc3758 100644 --- a/damus/Views/Events/Longform/LongformPreview.swift +++ b/damus/Views/Events/Longform/LongformPreview.swift @@ -7,12 +7,20 @@ import SwiftUI -struct LongformPreview: View { +struct LongformPreviewBody: View { let state: DamusState let event: LongformEvent let options: EventViewOptions @ObservedObject var artifacts: NoteArtifactsModel - + + init(state: DamusState, ev: LongformEvent, options: EventViewOptions) { + self.state = state + self.event = ev + self.options = options + + self._artifacts = ObservedObject(wrappedValue: state.events.get_cache_data(ev.event.id).artifacts_model) + } + init(state: DamusState, ev: NostrEvent, options: EventViewOptions) { self.state = state self.event = LongformEvent.parse(from: ev) @@ -20,11 +28,21 @@ struct LongformPreview: View { self._artifacts = ObservedObject(wrappedValue: state.events.get_cache_data(ev.id).artifacts_model) } - + func Words(_ words: Int) -> Text { Text(verbatim: words.description) + Text(verbatim: " ") + Text("Words") } + var body: some View { + Group { + if options.contains(.wide) { + Main.padding(.horizontal) + } else { + Main + } + } + } + var Main: some View { VStack(alignment: .leading, spacing: 10) { Text(event.title ?? "Untitled") @@ -40,15 +58,22 @@ struct LongformPreview: View { } } } +} + +struct LongformPreview: View { + let state: DamusState + let event: LongformEvent + let options: EventViewOptions + + init(state: DamusState, ev: NostrEvent, options: EventViewOptions) { + self.state = state + self.event = LongformEvent.parse(from: ev) + self.options = options.union(.no_mentions) + } var body: some View { - EventShell(state: state, event: event.event, options: options.union(.no_mentions)) { - - if options.contains(.wide) { - Main.padding(.horizontal) - } else { - Main - } + EventShell(state: state, event: event.event, options: options) { + LongformPreviewBody(state: state, ev: event, options: options) } } }