damus

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

TextEvent.swift (2568B)


      1 //
      2 //  TextEvent.swift
      3 //  damus
      4 //
      5 //  Created by William Casarin on 2023-02-03.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct EventViewOptions: OptionSet {
     11     let rawValue: UInt32
     12     
     13     static let no_action_bar = EventViewOptions(rawValue: 1 << 0)
     14     static let no_replying_to = EventViewOptions(rawValue: 1 << 1)
     15     static let wide = EventViewOptions(rawValue: 1 << 3)
     16     static let truncate_content = EventViewOptions(rawValue: 1 << 4)
     17     static let no_translate = EventViewOptions(rawValue: 1 << 5)
     18     static let small_pfp = EventViewOptions(rawValue: 1 << 6)
     19     static let nested = EventViewOptions(rawValue: 1 << 7)
     20     static let top_zap = EventViewOptions(rawValue: 1 << 8)
     21     static let no_mentions = EventViewOptions(rawValue: 1 << 9)
     22     static let no_media = EventViewOptions(rawValue: 1 << 10)
     23     static let truncate_content_very_short = EventViewOptions(rawValue: 1 << 11)
     24 
     25     static let embedded: EventViewOptions = [.no_action_bar, .small_pfp, .wide, .truncate_content, .nested]
     26     static let embedded_text_only: EventViewOptions = [.no_action_bar, .small_pfp, .wide, .truncate_content, .nested, .no_media, .truncate_content_very_short]
     27 }
     28 
     29 struct TextEvent: View {
     30     let damus: DamusState
     31     let event: NostrEvent
     32     let pubkey: Pubkey
     33     let options: EventViewOptions
     34     let evdata: EventData
     35     
     36     init(damus: DamusState, event: NostrEvent, pubkey: Pubkey, options: EventViewOptions) {
     37         self.damus = damus
     38         self.event = event
     39         self.pubkey = pubkey
     40         self.options = options
     41         self.evdata = damus.events.get_cache_data(event.id)
     42     }
     43     
     44     var body: some View {
     45         EventShell(state: damus, event: event, pubkey: pubkey, options: options) {
     46             EvBody(options: options)
     47         }
     48     }
     49 
     50     func EvBody(options: EventViewOptions) -> some View {
     51         let blur_imgs = should_blur_images(settings: damus.settings, contacts: damus.contacts, ev: event, our_pubkey: damus.pubkey)
     52         return NoteContentView(
     53             damus_state: damus,
     54             event: event,
     55             blur_images: blur_imgs,
     56             size: .normal,
     57             options: options
     58         )
     59     }
     60 
     61 }
     62 
     63 struct TextEvent_Previews: PreviewProvider {
     64     static var previews: some View {
     65         VStack(spacing: 20) {
     66             TextEvent(damus: test_damus_state, event: test_note, pubkey: test_pubkey, options: [])
     67                 .frame(height: 400)
     68             
     69             TextEvent(damus: test_damus_state, event: test_note, pubkey: test_pubkey, options: [.wide])
     70                 .frame(height: 400)
     71         }
     72     }
     73 }
     74