dominus

One damus client to rule them all
git clone git://jb55.com/dominus
Log | Files | Refs | README

filter.rs (2084B)


      1 use crate::{EventId, Pubkey};
      2 use serde::{Deserialize, Serialize};
      3 
      4 #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
      5 pub struct Filter {
      6     #[serde(skip_serializing_if = "Option::is_none")]
      7     ids: Option<Vec<EventId>>,
      8     #[serde(skip_serializing_if = "Option::is_none")]
      9     authors: Option<Vec<Pubkey>>,
     10     #[serde(skip_serializing_if = "Option::is_none")]
     11     kinds: Option<Vec<u64>>,
     12     #[serde(rename = "#e")]
     13     #[serde(skip_serializing_if = "Option::is_none")]
     14     events: Option<Vec<EventId>>,
     15     #[serde(rename = "#p")]
     16     #[serde(skip_serializing_if = "Option::is_none")]
     17     pubkeys: Option<Vec<Pubkey>>,
     18     #[serde(skip_serializing_if = "Option::is_none")]
     19     since: Option<u64>, // unix timestamp seconds
     20     #[serde(skip_serializing_if = "Option::is_none")]
     21     until: Option<u64>, // unix timestamp seconds
     22     #[serde(skip_serializing_if = "Option::is_none")]
     23     limit: Option<u16>,
     24 }
     25 
     26 impl Filter {
     27     pub fn new() -> Filter {
     28         Filter {
     29             ids: None,
     30             authors: None,
     31             kinds: None,
     32             events: None,
     33             pubkeys: None,
     34             since: None,
     35             until: None,
     36             limit: None,
     37         }
     38     }
     39 
     40     pub fn ids(mut self, ids: Vec<EventId>) -> Self {
     41         self.ids = Some(ids);
     42         self
     43     }
     44 
     45     pub fn authors(mut self, authors: Vec<Pubkey>) -> Self {
     46         self.authors = Some(authors);
     47         self
     48     }
     49 
     50     pub fn kinds(mut self, kinds: Vec<u64>) -> Self {
     51         self.kinds = Some(kinds);
     52         self
     53     }
     54 
     55     pub fn events(mut self, events: Vec<EventId>) -> Self {
     56         self.events = Some(events);
     57         self
     58     }
     59 
     60     pub fn pubkeys(mut self, pubkeys: Vec<Pubkey>) -> Self {
     61         self.pubkeys = Some(pubkeys);
     62         self
     63     }
     64 
     65     pub fn since(mut self, since: u64) -> Self {
     66         self.since = Some(since);
     67         self
     68     }
     69 
     70     pub fn until(mut self, until: u64) -> Self {
     71         self.until = Some(until);
     72         self
     73     }
     74 
     75     pub fn limit(mut self, limit: u16) -> Self {
     76         self.limit = Some(limit);
     77         self
     78     }
     79 }