@@ -93,8 +93,10 @@ class DraftArtifacts: Equatable {
93
93
/// - draft_id: The unique ID of this draft, used for keeping draft identities stable. UUIDs are recommended but not required.
94
94
/// - damus_state: The user's Damus state, used for fetching profiles in NostrDB
95
95
/// - 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
+ }
98
100
return Self . from ( parsed_blocks: parsed_blocks, references: Array ( event. references) , draft_id: draft_id, damus_state: damus_state)
99
101
}
100
102
@@ -112,7 +114,7 @@ class DraftArtifacts: Equatable {
112
114
for block in parsed_blocks. blocks {
113
115
switch block {
114
116
case . mention( let mention) :
115
- if case . pubkey ( let pubkey) = mention. ref {
117
+ if let pubkey = mention. ref. nip19 . pubkey ( ) {
116
118
// A profile reference, format things properly.
117
119
let profile = damus_state. ndb. lookup_profile ( pubkey) ? . unsafeUnownedValue? . profile
118
120
let profile_name = parse_display_name ( profile: profile, pubkey: pubkey) . username
@@ -128,12 +130,10 @@ class DraftArtifacts: Equatable {
128
130
]
129
131
)
130
132
rich_text_content. append ( attributed_string)
131
- }
132
- else if case . note( _) = mention. ref {
133
+ } else if case . note( _) = mention. ref. nip19 {
133
134
// 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
134
135
continue
135
- }
136
- else {
136
+ } else {
137
137
// Other references
138
138
rich_text_content. append ( . init( string: block. asString) )
139
139
}
@@ -195,7 +195,10 @@ class Drafts: ObservableObject {
195
195
) else { return }
196
196
197
197
// 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
+
199
202
switch known_kind {
200
203
case . text:
201
204
if let replied_to_note_id = nip37_draft. unwrapped_note. direct_replies ( ) {
@@ -204,7 +207,7 @@ class Drafts: ObservableObject {
204
207
else {
205
208
for block in blocks. blocks {
206
209
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 {
208
211
self . quotes [ note_id] = draft_artifacts
209
212
return
210
213
}
0 commit comments