From 3018200e95561cf0404b37f9c9386a18e6eb8edd Mon Sep 17 00:00:00 2001 From: William Casarin Date: Wed, 23 Oct 2024 13:13:38 -0700 Subject: [PATCH] nostrdb: add ndb_subscription_filters Expose a way to get the set of filters for a subscription. On the rust side, we should likely ndb_filter_clone each filter asap, because the result of this function will only be valid up until the subscription ends. Signed-off-by: William Casarin --- nostrdb/src/nostrdb.c | 14 ++++++++++++++ nostrdb/src/nostrdb.h | 1 + 2 files changed, 15 insertions(+) diff --git a/nostrdb/src/nostrdb.c b/nostrdb/src/nostrdb.c index 740db11a..380c43f8 100644 --- a/nostrdb/src/nostrdb.c +++ b/nostrdb/src/nostrdb.c @@ -6467,6 +6467,20 @@ int ndb_unsubscribe(struct ndb *ndb, uint64_t subid) return 1; } +struct ndb_filter *ndb_subscription_filters(struct ndb *ndb, uint64_t subid, int *filters) +{ + struct ndb_subscription *sub; + + sub = ndb_find_subscription(ndb, subid, NULL); + if (sub) { + *filters = sub->group.num_filters; + return sub->group.filters; + } + + *filters = 0; + return NULL; +} + int ndb_num_subscriptions(struct ndb *ndb) { return ndb->monitor.num_subscriptions; diff --git a/nostrdb/src/nostrdb.h b/nostrdb/src/nostrdb.h index 7f1fba42..35705121 100644 --- a/nostrdb/src/nostrdb.h +++ b/nostrdb/src/nostrdb.h @@ -521,6 +521,7 @@ int ndb_wait_for_notes(struct ndb *, uint64_t subid, uint64_t *note_ids, int not int ndb_poll_for_notes(struct ndb *, uint64_t subid, uint64_t *note_ids, int note_id_capacity); int ndb_unsubscribe(struct ndb *, uint64_t subid); int ndb_num_subscriptions(struct ndb *); +struct ndb_filter *ndb_subscription_filters(struct ndb *, uint64_t subid, int *filters); // FULLTEXT SEARCH int ndb_text_search(struct ndb_txn *txn, const char *query, struct ndb_text_search_results *, struct ndb_text_search_config *);