Since Damus iOS is not an immediate-mode UI like android, we would
rather not poll for results. Instead we need a way to register a
callback function that is called when we get new subscription results.
This is also useful on the android side, allowing us to request a new
frame to draw when we have new results, instead of drawing every second.
Signed-off-by: William Casarin <jb55@jb55.com>
We didn't have a way to unsubscribe from subscriptions. Now we do!
Apps like notecrumbs may open up many local subscriptions based on
incoming requests. We may need to make the MAX_SUBSCRIPTIONS size much
larger, but this should be okish for now.
Changelog-Added: Add ndb_unsubscribe to unsubscribe from subscriptions
Signed-off-by: William Casarin <jb55@jb55.com>
Clone filters when moving them into subscriptions. This will allow us to
fix the double free issue on the rust side.
Signed-off-by: William Casarin <jb55@jb55.com>
Instead of storing exact pointers inside of our filter elements, just
store offsets. This will allow us to clone filters very easily without
having to mess around with fixing up the pointers afterwards.
Signed-off-by: William Casarin <jb55@jb55.com>
This is a pretty scary looking function that realloc our large variable
filter buffer into a compact one. This saves up a bunch of memory when
we are done building the filter.
Signed-off-by: William Casarin <jb55@jb55.com>
The polling variant of ndb_wait_for_notes. This makes more sense for
realtime apps like notedeck
Changelog-Added: Add ndb_poll_for_notes
Signed-off-by: William Casarin <jb55@jb55.com>
Instead of running queries off filters directly, we do some simple
heuristics and determine a reasonable query plan for the given filter.
To test this, also add a kind index query plan and add a test for it.
We still need tag, author, and created_at index scans. This is up next!
Signed-off-by: William Casarin <jb55@jb55.com>
Still a lot more work to do, but this is at least a proof of concept for
querying nostrdb using filters.
Signed-off-by: William Casarin <jb55@jb55.com>
This adds some initial code for the nostrdb relay subscription monitor.
When new notes are written to the database, they are checked against
active subscriptions. If any of the subscriptions are matched, the note
primary key is written to the inbox queue for that subscription.
We also add an ndb_wait_for_notes() method that simply waits for notes
to be written by the subscription monitor.
Changelog-Added: Added filter subscriptions
Signed-off-by: William Casarin <jb55@jb55.com>
so we don't need heap allocation. we will be calling this a lot in tight
render loops, we don't want to be allocating on each frame.
Signed-off-by: William Casarin <jb55@jb55.com>
In some situations we will need to have owned note blocks. For
example, when we try to fetch note blocks from the database and it's not
there yet. We will need to parse the content on the spot and return an
owned copy, since it will not be immediately available in the database.
Add a new flag field to note blocks that lets us know if it's owned by
malloc or nostrdb.
We the add a free function that checks this flag and frees the object if
its set. If it is not set then it doesn nothing because it likely came
from the database.
Signed-off-by: William Casarin <jb55@jb55.com>
We need to pull the data out as well! Let's add some initial decoders.
We still need tests to make sure it's working.
Signed-off-by: William Casarin <jb55@jb55.com>
This adds some initial code for nostrdb content parsing.
We still need to write tests for encoding and decoding, so this is
likely not working yet.
Signed-off-by: William Casarin <jb55@jb55.com>