damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit de4e8e5748656fd1da43439aaed3bf0fc5566c9b
parent ad6a1962bbddc17762c4a73dbe25398c7d79f861
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 11 Jul 2023 12:56:30 -0700

Only show longform preview in notifications

Changelog-Fixed: Show longform previews in notifications instead of the entire post

Diffstat:
Mdamus/Views/Events/EventBody.swift | 23++++++++++++++---------
Mdamus/Views/Events/Longform/LongformPreview.swift | 45+++++++++++++++++++++++++++++++++++----------
2 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/damus/Views/Events/EventBody.swift b/damus/Views/Events/EventBody.swift @@ -21,18 +21,23 @@ 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 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 { - let longform = LongformEvent.parse(from: event) - - Text(longform.title ?? "Untitled") - .font(.title) - .padding(.horizontal) + 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 } - - NoteContentView(damus_state: damus_state, event: event, show_images: should_show_img, size: size, options: options) - .frame(maxWidth: .infinity, alignment: .leading) } } diff --git 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 { } } } +} - var body: some View { - EventShell(state: state, event: event.event, options: options.union(.no_mentions)) { +struct LongformPreview: View { + let state: DamusState + let event: LongformEvent + let options: EventViewOptions - if options.contains(.wide) { - Main.padding(.horizontal) - } else { - Main - } + 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) { + LongformPreviewBody(state: state, ev: event, options: options) } } }