lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

ingest.rs (977B)


      1 #[derive(Debug, Clone, Default, Eq, PartialEq)]
      2 pub enum RadrootsNostrNdbIngestSource {
      3     #[default]
      4     Client,
      5     Relay {
      6         relay_url: Option<String>,
      7     },
      8 }
      9 
     10 impl RadrootsNostrNdbIngestSource {
     11     pub fn client() -> Self {
     12         Self::Client
     13     }
     14 
     15     pub fn relay(relay_url: impl Into<String>) -> Self {
     16         Self::Relay {
     17             relay_url: Some(relay_url.into()),
     18         }
     19     }
     20 
     21     pub fn relay_unknown() -> Self {
     22         Self::Relay { relay_url: None }
     23     }
     24 
     25     pub(crate) fn to_ndb_metadata(&self) -> nostrdb::IngestMetadata {
     26         match self {
     27             Self::Client => nostrdb::IngestMetadata::new().client(true),
     28             Self::Relay { relay_url } => {
     29                 let meta = nostrdb::IngestMetadata::new().client(false);
     30                 if let Some(relay_url) = relay_url {
     31                     meta.relay(relay_url.as_str())
     32                 } else {
     33                     meta
     34                 }
     35             }
     36         }
     37     }
     38 }