diff --git a/damus/ContentView.swift b/damus/ContentView.swift index e770a157d..dc897f09f 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -987,6 +987,12 @@ func handle_post_notification(keypair: FullKeypair, postbox: PostBox, events: Ev postbox.send(ev) } } + for qref in new_ev.referenced_quote_ids.prefix(3) { + // also broadcast at most 3 referenced quoted events + if let ev = events.lookup(qref.note_id) { + postbox.send(ev) + } + } return true case .cancel: print("post cancelled") diff --git a/damus/Nostr/Id.swift b/damus/Nostr/Id.swift index f97bf7a6c..101fadddd 100644 --- a/damus/Nostr/Id.swift +++ b/damus/Nostr/Id.swift @@ -34,14 +34,37 @@ protocol TagConvertible { static func from_tag(tag: TagSequence) -> Self? } -struct QuoteId: IdType, TagKey { +struct QuoteId: IdType, TagKey, TagConvertible { let id: Data init(_ data: Data) { self.id = data } + + /// Refer to this QuoteId as a NoteId + var note_id: NoteId { + NoteId(self.id) + } var keychar: AsciiCharacter { "q" } + + var tag: [String] { + ["q", self.hex()] + } + + static func from_tag(tag: TagSequence) -> QuoteId? { + var i = tag.makeIterator() + + guard tag.count >= 2, + let t0 = i.next(), + let key = t0.single_char, + key == "q", + let t1 = i.next(), + let quote_id = t1.id().map(QuoteId.init) + else { return nil } + + return quote_id + } } diff --git a/nostrdb/NdbNote.swift b/nostrdb/NdbNote.swift index b46deca39..4d39ca70a 100644 --- a/nostrdb/NdbNote.swift +++ b/nostrdb/NdbNote.swift @@ -292,6 +292,10 @@ extension NdbNote { public var referenced_ids: References { References(tags: self.tags) } + + public var referenced_quote_ids: References { + References(tags: self.tags) + } public var referenced_noterefs: References { References(tags: self.tags)