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

@@ -457,23 +457,25 @@ extension NdbNote {
return ThreadReply(tags: self.tags)?.reply.note_id
}
func blocks(ndb: Ndb) -> NdbTxn<NdbBlocks>? {
let blocks_txn = NdbTxn<NdbBlocks?>(ndb: ndb) { txn in
func block_offsets(ndb: Ndb) -> SafeNdbTxn<NdbBlockGroup.BlocksMetadata>? {
let blocks_txn: SafeNdbTxn<NdbBlockGroup.BlocksMetadata>? = .new(on: ndb) { txn -> NdbBlockGroup.BlocksMetadata? in
guard let key = ndb.lookup_note_key_with_txn(self.id, txn: txn) else {
return nil
}
return ndb.lookup_blocks_by_key_with_txn(key, txn: txn)
}
guard let blocks_txn else {
return nil
}
guard let blocks_txn else { return nil }
return blocks_txn.collect()
return blocks_txn
}
func is_content_encrypted() -> Bool {
return known_kind == .dm // Probably other kinds should be listed here
}
func get_content(_ keypair: Keypair) -> String {
if known_kind == .dm {
if is_content_encrypted() {
return decrypted(keypair: keypair) ?? "*failed to decrypt content*"
}
else if known_kind == .highlight {
@@ -484,7 +486,7 @@ extension NdbNote {
}
func maybe_get_content(_ keypair: Keypair) -> String? {
if known_kind == .dm {
if is_content_encrypted() {
return decrypted(keypair: keypair)
}