Skip to content

Commit

Permalink
nostr: not skip serialization of empty lists in Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Feb 22, 2024
1 parent 3403110 commit 6921a5a
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 90 deletions.
23 changes: 15 additions & 8 deletions crates/nostr-database/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ impl FilterIndex {
impl From<Filter> for FilterIndex {
fn from(value: Filter) -> Self {
Self {
ids: value.ids,
ids: value.ids.unwrap_or_default(),
authors: value
.authors
.unwrap_or_default()
.into_iter()
.map(PublicKeyPrefix::from)
.collect(),
kinds: value.kinds,
kinds: value.kinds.unwrap_or_default(),
since: value.since,
until: value.until,
generic_tags: value.generic_tags,
Expand Down Expand Up @@ -332,12 +333,18 @@ enum QueryPattern {

impl From<Filter> for QueryPattern {
fn from(filter: Filter) -> Self {
let kinds_len = filter.kinds.len();
let first_kind = filter.kinds.iter().next().copied();
let authors_len = filter.authors.len();
let first_author = filter.authors.iter().next().copied();
let ids_len = filter.ids.len();
let generic_tags_len = filter.generic_tags.len();
let (kinds_len, first_kind): (usize, Option<Kind>) = filter
.kinds
.as_ref()
.map(|set| (set.len(), set.iter().next().copied()))
.unwrap_or_default();
let (authors_len, first_author): (usize, Option<PublicKey>) = filter
.authors
.as_ref()
.map(|set| (set.len(), set.iter().next().copied()))
.unwrap_or_default();
let ids_len: usize = filter.ids.as_ref().map(|set| set.len()).unwrap_or_default();
let generic_tags_len: usize = filter.generic_tags.len();
let identifier = filter
.generic_tags
.get(&SingleLetterTag::lowercase(Alphabet::D))
Expand Down
Loading

0 comments on commit 6921a5a

Please sign in to comment.