@@ -93,8 +93,10 @@ class DraftArtifacts: Equatable {
9393 /// - draft_id: The unique ID of this draft, used for keeping draft identities stable. UUIDs are recommended but not required.
9494 /// - damus_state: The user's Damus state, used for fetching profiles in NostrDB
9595 /// - Returns: The draft that can be loaded into `PostView`.
96- static func from( event: NostrEvent , draft_id: String , damus_state: DamusState ) -> DraftArtifacts {
97- let parsed_blocks = parse_note_content ( content: . init( note: event, keypair: damus_state. keypair) )
96+ static func from( event: NostrEvent , draft_id: String , damus_state: DamusState ) -> DraftArtifacts ? {
97+ guard let parsed_blocks = parse_note_content ( content: . init( note: event, keypair: damus_state. keypair) ) else {
98+ return nil
99+ }
98100 return Self . from ( parsed_blocks: parsed_blocks, references: Array ( event. references) , draft_id: draft_id, damus_state: damus_state)
99101 }
100102
@@ -112,7 +114,7 @@ class DraftArtifacts: Equatable {
112114 for block in parsed_blocks. blocks {
113115 switch block {
114116 case . mention( let mention) :
115- if case . pubkey ( let pubkey) = mention. ref {
117+ if let pubkey = mention. ref. nip19 . pubkey ( ) {
116118 // A profile reference, format things properly.
117119 let profile = damus_state. ndb. lookup_profile ( pubkey) ? . unsafeUnownedValue? . profile
118120 let profile_name = parse_display_name ( profile: profile, pubkey: pubkey) . username
@@ -128,12 +130,10 @@ class DraftArtifacts: Equatable {
128130 ]
129131 )
130132 rich_text_content. append ( attributed_string)
131- }
132- else if case . note( _) = mention. ref {
133+ } else if case . note( _) = mention. ref. nip19 {
133134 // These note references occur when we quote a note, and since that is tracked via `PostAction` in `PostView`, ignore it here to avoid attaching the same event twice in a note
134135 continue
135- }
136- else {
136+ } else {
137137 // Other references
138138 rich_text_content. append ( . init( string: block. asString) )
139139 }
@@ -195,7 +195,10 @@ class Drafts: ObservableObject {
195195 ) else { return }
196196
197197 // Find out where to place these drafts
198- let blocks = parse_note_content ( content: . note( nip37_draft. unwrapped_note) )
198+ guard let blocks = parse_note_content ( content: . note( nip37_draft. unwrapped_note) ) else {
199+ return
200+ }
201+
199202 switch known_kind {
200203 case . text:
201204 if let replied_to_note_id = nip37_draft. unwrapped_note. direct_replies ( ) {
@@ -204,7 +207,7 @@ class Drafts: ObservableObject {
204207 else {
205208 for block in blocks. blocks {
206209 if case . mention( let mention) = block {
207- if case . note( let note_id) = mention. ref {
210+ if case . note( let note_id) = mention. ref. nip19 {
208211 self . quotes [ note_id] = draft_artifacts
209212 return
210213 }
0 commit comments