damus

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

EventBody.swift (2045B)


      1 //
      2 //  EventBody.swift
      3 //  damus
      4 //
      5 //  Created by William Casarin on 2023-01-23.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct EventBody: View {
     11     let damus_state: DamusState
     12     let event: NostrEvent
     13     let size: EventViewKind
     14     let should_blur_img: Bool
     15     let options: EventViewOptions
     16     
     17     init(damus_state: DamusState, event: NostrEvent, size: EventViewKind, should_blur_img: Bool? = nil, options: EventViewOptions) {
     18         self.damus_state = damus_state
     19         self.event = event
     20         self.size = size
     21         self.options = options
     22         self.should_blur_img = should_blur_img ?? should_blur_images(settings: damus_state.settings, contacts: damus_state.contacts, ev: event, our_pubkey: damus_state.pubkey)
     23     }
     24 
     25     var note_content: some View {
     26         NoteContentView(damus_state: damus_state, event: event, blur_images: should_blur_img, size: size, options: options)
     27             .frame(maxWidth: .infinity, alignment: .leading)
     28     }
     29 
     30     var body: some View {
     31         if event.known_kind == .longform {
     32             LongformPreviewBody(state: damus_state, ev: event, options: options, header: true)
     33 
     34             // truncated longform bodies are just the preview
     35             if !options.contains(.truncate_content) {
     36                 note_content
     37             }
     38         } else if event.known_kind == .highlight {
     39             HighlightBodyView(state: damus_state, ev: event, options: options)
     40                 .onTapGesture {
     41                     if let highlighted_note = event.highlighted_note_id().flatMap({ damus_state.events.lookup($0) }) {
     42                         let thread = ThreadModel(event: highlighted_note, damus_state: damus_state, highlight: event.content)
     43                         damus_state.nav.push(route: Route.Thread(thread: thread))
     44                     }
     45                 }
     46         } else {
     47             note_content
     48         }
     49     }
     50 }
     51 
     52 struct EventBody_Previews: PreviewProvider {
     53     static var previews: some View {
     54         EventBody(damus_state: test_damus_state, event: test_note, size: .normal, options: [])
     55     }
     56 }