DMView.swift (2444B)
1 // 2 // DMView.swift 3 // damus 4 // 5 // Created by William Casarin on 2022-07-01. 6 // 7 8 import SwiftUI 9 10 struct DMView: View { 11 let event: NostrEvent 12 let damus_state: DamusState 13 14 var is_ours: Bool { 15 event.pubkey == damus_state.pubkey 16 } 17 18 var Mention: some View { 19 Group { 20 if let mention = first_eref_mention(ev: event, keypair: damus_state.keypair) { 21 BuilderEventView(damus: damus_state, event_id: mention.ref) 22 } else { 23 EmptyView() 24 } 25 } 26 } 27 28 var dm_options: EventViewOptions { 29 /* 30 if self.damus_state.settings.translate_dms { 31 return [] 32 } 33 */ 34 35 return [.no_translate] 36 } 37 38 var DM: some View { 39 HStack { 40 if is_ours { 41 Spacer(minLength: UIScreen.main.bounds.width * 0.2) 42 } 43 44 let should_blur_img = should_blur_images(settings: damus_state.settings, contacts: damus_state.contacts, ev: event, our_pubkey: damus_state.pubkey) 45 46 VStack(alignment: .trailing) { 47 NoteContentView(damus_state: damus_state, event: event, blur_images: should_blur_img, size: .normal, options: dm_options) 48 .fixedSize(horizontal: false, vertical: true) 49 .padding([.top, .leading, .trailing], 10) 50 .padding([.bottom], 10) 51 .background(VisualEffectView(effect: UIBlurEffect(style: .prominent)) 52 .background(is_ours ? Color.accentColor.opacity(0.9) : Color.secondary.opacity(0.15)) 53 ) 54 .cornerRadius(8.0) 55 .tint(is_ours ? Color.white : Color.accentColor) 56 57 Text(format_relative_time(event.created_at)) 58 .font(.footnote) 59 .foregroundColor(.gray) 60 .opacity(0.8) 61 } 62 63 if !is_ours { 64 Spacer(minLength: UIScreen.main.bounds.width * 0.2) 65 } 66 } 67 } 68 69 var body: some View { 70 VStack { 71 Mention 72 DM 73 } 74 75 } 76 } 77 78 struct DMView_Previews: PreviewProvider { 79 static var previews: some View { 80 let ev = NostrEvent(content: "Hey there *buddy*, want to grab some drinks later? 🍻", keypair: test_keypair, kind: 1, tags: [])! 81 DMView(event: ev, damus_state: test_damus_state) 82 } 83 }