Fix broken DM rendering

Currently NostrDB does not seem to handle encryption/decryption of DMs.
Since NostrDB now controls the block parsing process and fetches note
contents directly from the database, we have to add a specific condition
that injects decrypted content directly to the ndb content parser.

This is done in conjunction with some minor refactoring to `NdbBlocks`
and associated structs, as in C those are separated between the content
string and the offsets for each block, but in Swift this is more
ergonomically represented as a standalone/self-containing object.

No changelog entry is added because the previously broken version was
never released to the public, and therefore this fix produces no
user-facing changes compared to the last released version.

Changelog-None
Closes: https://github.com/damus-io/damus/issues/3106
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
Daniel D’Aquino
2025-06-27 19:27:42 -07:00
parent 9c47d2e0bd
commit caa7802bce
11 changed files with 350 additions and 129 deletions

View File

@@ -780,12 +780,11 @@ func validate_event(ev: NostrEvent) -> ValidationResult {
}
func first_eref_mention(ndb: Ndb, ev: NostrEvent, keypair: Keypair) -> Mention<NoteId>? {
guard let blocks_txn = ev.blocks(ndb: ndb) else {
guard let blockGroup = try? NdbBlockGroup.from(event: ev, using: ndb, and: keypair) else {
return nil
}
let ndb_blocks = blocks_txn.unsafeUnownedValue
let blocks = ndb_blocks.iter(note: ev).filter { block in
let blocks = blockGroup.blocks.filter { block in
guard case .mention(let mention) = block else {
return false
}
@@ -815,12 +814,11 @@ func first_eref_mention(ndb: Ndb, ev: NostrEvent, keypair: Keypair) -> Mention<N
return nil
}
func separate_invoices(ndb: Ndb, ev: NostrEvent) -> [Invoice]? {
guard let blocks_txn = ev.blocks(ndb: ndb) else {
func separate_invoices(ndb: Ndb, ev: NostrEvent, keypair: Keypair) -> [Invoice]? {
guard let blockGroup = try? NdbBlockGroup.from(event: ev, using: ndb, and: keypair) else {
return nil
}
let ndb_blocks = blocks_txn.unsafeUnownedValue
let invoiceBlocks: [Invoice] = ndb_blocks.iter(note: ev).reduce(into: []) { invoices, block in
let invoiceBlocks: [Invoice] = blockGroup.blocks.reduce(into: []) { invoices, block in
guard case .invoice(let invoice) = block,
let invoice = invoice.as_invoice()
else {