TextEvent.swift (2713B)
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 static let no_previews = EventViewOptions(rawValue: 1 << 12) 25 static let no_show_more = EventViewOptions(rawValue: 1 << 13) 26 27 static let embedded: EventViewOptions = [.no_action_bar, .small_pfp, .wide, .truncate_content, .nested] 28 static let embedded_text_only: EventViewOptions = [.no_action_bar, .small_pfp, .wide, .truncate_content, .nested, .no_media, .truncate_content_very_short, .no_previews] 29 } 30 31 struct TextEvent: View { 32 let damus: DamusState 33 let event: NostrEvent 34 let pubkey: Pubkey 35 let options: EventViewOptions 36 let evdata: EventData 37 38 init(damus: DamusState, event: NostrEvent, pubkey: Pubkey, options: EventViewOptions) { 39 self.damus = damus 40 self.event = event 41 self.pubkey = pubkey 42 self.options = options 43 self.evdata = damus.events.get_cache_data(event.id) 44 } 45 46 var body: some View { 47 EventShell(state: damus, event: event, pubkey: pubkey, options: options) { 48 EvBody(options: options) 49 } 50 } 51 52 func EvBody(options: EventViewOptions) -> some View { 53 let blur_imgs = should_blur_images(settings: damus.settings, contacts: damus.contacts, ev: event, our_pubkey: damus.pubkey) 54 return NoteContentView( 55 damus_state: damus, 56 event: event, 57 blur_images: blur_imgs, 58 size: .normal, 59 options: options 60 ) 61 } 62 63 } 64 65 struct TextEvent_Previews: PreviewProvider { 66 static var previews: some View { 67 VStack(spacing: 20) { 68 TextEvent(damus: test_damus_state, event: test_note, pubkey: test_pubkey, options: []) 69 .frame(height: 400) 70 71 TextEvent(damus: test_damus_state, event: test_note, pubkey: test_pubkey, options: [.wide]) 72 .frame(height: 400) 73 } 74 } 75 } 76