Commit Graph

4377 Commits

Author SHA1 Message Date
Daniel D’Aquino
1caad24364 Add note provenance filter support to SubscriptionManager
Closes: https://github.com/damus-io/damus/issues/3222
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:10 -07:00
Daniel D’Aquino
ecbfb3714b Fix incompatibilities with new nostrdb version
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:03 -07:00
William Casarin
d565eb20f7 nostrdb: query: enforce author matches in author_kind queries
before we weren't checking this, meaning we were getting
results from other keys. oops.

Reported-by: Jeff Gardner
Fixes: #84
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
a040a0244b nostrdb: search: fix memleak in profile search
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
387af198d6 nostrdb: win: fix heap corruption with flatbuf 2025-09-24 14:06:03 -07:00
William Casarin
66e10db6b2 nostrdb: mem: re-enable profile freeing
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
42a0f2c08d nostrdb: Revert "mem: search cursor close"
this is causing heap corruption on the windows
build

This reverts commit a8d6925a5b33ddbdd4306423527b5d8314f7dd36.
2025-09-24 14:06:03 -07:00
William Casarin
aa8ce31941 nostrdb: mem: close cursors in print helpers 2025-09-24 14:06:03 -07:00
William Casarin
8014d772ba nostrdb: mem: builder clear before free 2025-09-24 14:06:03 -07:00
William Casarin
4d8313c788 nostrdb: mem: relay iter cleanup 2025-09-24 14:06:03 -07:00
William Casarin
342067640f nostrdb: mem: reaction stats cleanup 2025-09-24 14:06:03 -07:00
William Casarin
84839d1c43 nostrdb: mem: search cursor close 2025-09-24 14:06:03 -07:00
William Casarin
b5079c42d5 nostrdb: memory: fix a bunch of memory leaks
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
0847c53a39 nostrdb: add ndb_builder_push_tag_id
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
fa2d240ddf nostrdb: nostrdb: calculate id in ndb_note_verify
Rogue relays could in theory attack nostrdb by replaying ids and
signatures from other notes. This fixes this weakness by calculating the
id again in ndb_note_verify.

There is no known relays exploiting this, but lets get ahead of it
before we switch to the outbox model in damus iOS/notedeck

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
3a37a6c18e nostrdb: change <=10 author search queries to ==1
These queries are broken anyways. Rely on scans until we fix this

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
5c75e87ed5 nostrdb: eq: fix fallthrough bug
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
64c16e7cc8 nostrdb: filter: add initial custom filtering logic
This adds some helpers for adding custom filtering logic
to nostr filters. These are just a callback and a closure.
There can only be one custom callback filter per filter.

Fixes: https://github.com/damus-io/nostrdb/issues/33
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
0b8090cb28 nostrdb: query: implement profile search query plans
The basic idea of this is to allow you to use the standard
nip50 query interface to search for profiles using our profile
index.

query: {"search":"jb55", "kinds":[0]}

will result in a profile_search query plan that searches kind0 profiles
for the corresponding `name` or `display_name`.

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
9cff8608f6 nostrdb: fix build on macos 2025-09-24 14:06:03 -07:00
William Casarin
c728210be8 nostrdb: query: implement author_kind query plan
This should help author kind query performance
2025-09-24 14:06:03 -07:00
William Casarin
0f66e87faf nostrdb: Relay queries
Add support for relay-based filtering in nostr queries.

Filters can now include a "relays" field. Optimal performance when
you include a kind as well:

{"relays":["wss://pyramid.fiatjaf.com/"], "kinds":[1]}

This corresponds to a `ndb` query like so:

$ ndb query -r wss://pyramid.fiatjaf.com/ -k 1 -l 1
using filter '{"relays":["wss://pyramid.fiatjaf.com/"],"kinds":[1],"limit":1}'
1 results in 0.094929 ms
{"id":"277dd4ed26d0b44576..}

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
af2298dcb7 nostrdb: relay: fix potential relay index corruption
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
a0b85129d4 nostrdb: relay: fix race condition bug
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
e42b14cc6f nostrdb: debug: add a print for debugging rust integration
Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
f0521ba406 nostrdb: relay-index: fix a few bugs
There were a few race conditions and lmdb bugs in the
relay index implementation. Fix those!

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
c29027ff5b nostrdb: note: always write relay index
This fixes a race condition where if multiple of the same note
is processed at the same time, we still manage to write the
note relays

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
c6674199de nostrdb: win: fix build on windows 2025-09-24 14:06:03 -07:00
William Casarin
5961bf7958 nostrdb: ndb: add print-relay-kind-index-keys
for debugging

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
a877a19c25 nostrdb: relay: add note relay iteration
This is a simple cursor that walks the NDB_DB_NOTE_RELAYS db

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
684701931d nostrdb: Initial relay index implementation
Add relay indexing for existing notes

This patch introduces a relay index for new notes and notes that have
already been stored, allowing the database to track additional relay
sources for a given note.

Changes:

- Added `NDB_WRITER_NOTE_RELAY` to handle relay indexing separately from
  new note ingestion.

- Implemented `ndb_write_note_relay()` and
  `ndb_write_note_relay_kind_index()` to store relay URLs.

- Modified `ndb_ingester_process_event()` to check for existing notes
  and append relay info if necessary.

- Introduced `ndb_note_has_relay()` to prevent duplicate relay entries.

- Updated LMDB schema with `NDB_DB_NOTE_RELAYS` (note_id -> relay) and
  `NDB_DB_NOTE_RELAY_KIND` (relay + kind + created_at -> note).

- Refactored `ndb_process_event()` to use `ndb_ingest_meta` for tracking
  relay sources.

- Ensured proper memory management for relay strings in writer thread.

With this change, nostrdb can better track where notes are seen across
different relays, improving query capabilities for relay-based data
retrieval.

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
William Casarin
fcd8131063 nostrdb: config: custom writer scratch size
making more things configurable if you have memory constraints

Signed-off-by: William Casarin <jb55@jb55.com>
2025-09-24 14:06:03 -07:00
Daniel D’Aquino
3290e1f9d2 Improve NostrNetworkManager interfaces
This commit improves NostrNetworkManager interfaces to be easier to use,
and with more options on how to read data from the Nostr network

This reduces the amount of duplicate logic in handling streams, and also
prevents possible common mistakes when using the standard subscribe method.

This fixes an issue with the mute list manager (which prompted for this
interface improvement, as the root cause is similar to other similar
issues).

Closes: https://github.com/damus-io/damus/issues/3221
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
2bea2faf3f Add load more content button to the top bar
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
9bcee298d4 Fix forever-loading hashtag view
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
7eb759a8a0 Fix issue with wallet loading
Changelog-Changed: Increased transaction list limit to 50 transactions
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
2550d613b2 Fix test compilation issues
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
9fb7ed741e Fix race condition on app swap that would cause ndb to remain closed
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
d766029f2b Improve loading UX in the home timeline
Changelog-Changed: Improved loading UX in the home timeline
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
4478672c10 Fix occasional stale timeline issue
Changelog-Changed: Added UX hint to make it easier to load new notes
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
c43a37d2d3 Fix forever-loading quote repost view
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
ab22206093 Fix broken Follow Pack timeline
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
de70d19135 Fix NIP-05 timeline crash
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
0f26d50e08 Prevent publishing changes to Observable outside the main thread
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
9709e69dda Fix forever loading Universe view
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
809c8c80ac Fix missing relay list from profile
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
c4c3656f90 Multi-session subscriptions and RelayPool reopening
This commit implements nostr network subscriptions that survive between
sessions, as well as improved handling of RelayPool opening/closing with
respect to the app lifecycle.

This prevents stale data after users swap out and back into Damus.

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
46c3667ec3 Update setting on main actor to avoid crashes
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
739a3a0b8c Add more test cases to SubscriptionManager tests
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00
Daniel D’Aquino
ab6ea7a9c1 Fix issue where repost and like counts would not appear
Previously, HomeModel could listen to all subscriptions throughout the
app, and it would handle reaction and repost counting.

Once moved to the local relay model, HomeModel no longer had access to
all subscriptions, causing those counts to disappear.

The issue was fixed by doing the counting from ThreadModel itself, which
better isolates concerns throughout the app.

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-09-24 14:06:02 -07:00