damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 62625c6ff365467a79b59599b3125dead805beb9
parent c8d88058d46089e11d32140a35ffb7e425589734
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  5 Feb 2024 16:48:36 -0800

nostrdb: ndb: add ndb_poll_for_notes

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>

Diffstat:
Mnostrdb/src/nostrdb.c | 14++++++++++++++
Mnostrdb/src/nostrdb.h | 4++--
2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/nostrdb/src/nostrdb.c b/nostrdb/src/nostrdb.c @@ -5614,6 +5614,20 @@ struct ndb_subscription *ndb_find_subscription(struct ndb *ndb, uint64_t subid) return sub; } +int ndb_poll_for_notes(struct ndb *ndb, uint64_t subid, uint64_t *note_ids, + int note_id_capacity) +{ + struct ndb_subscription *sub; + + if (subid == 0) + return 0; + + if (!(sub = ndb_find_subscription(ndb, subid))) + return 0; + + return prot_queue_try_pop_all(&sub->inbox, note_ids, note_id_capacity); +} + int ndb_wait_for_notes(struct ndb *ndb, uint64_t subid, uint64_t *note_ids, int note_id_capacity) { diff --git a/nostrdb/src/nostrdb.h b/nostrdb/src/nostrdb.h @@ -486,8 +486,8 @@ void ndb_filter_destroy(struct ndb_filter *); // SUBSCRIPTIONS uint64_t ndb_subscribe(struct ndb *, struct ndb_filter *, int num_filters); -int ndb_wait_for_notes(struct ndb *, uint64_t subid, uint64_t *note_ids, - int note_id_capacity); +int ndb_wait_for_notes(struct ndb *, uint64_t subid, uint64_t *note_ids, int note_id_capacity); +int ndb_poll_for_notes(struct ndb *, uint64_t subid, uint64_t *note_ids, int note_id_capacity); int ndb_unsubscribe(int subid); // FULLTEXT SEARCH