lib

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

repost.rs (1900B)


      1 #[cfg(not(feature = "std"))]
      2 use alloc::string::String;
      3 
      4 use crate::social::RadrootsSocialTarget;
      5 
      6 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
      7 #[derive(Clone, Debug)]
      8 pub struct RadrootsRepost {
      9     pub target: RadrootsSocialTarget,
     10     #[cfg_attr(
     11         feature = "serde",
     12         serde(default, skip_serializing_if = "Option::is_none")
     13     )]
     14     pub content: Option<String>,
     15 }
     16 
     17 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
     18 #[derive(Clone, Debug)]
     19 pub struct RadrootsGenericRepost {
     20     pub target: RadrootsSocialTarget,
     21     pub target_kind: u32,
     22     #[cfg_attr(
     23         feature = "serde",
     24         serde(default, skip_serializing_if = "Option::is_none")
     25     )]
     26     pub content: Option<String>,
     27 }
     28 
     29 #[cfg(test)]
     30 mod tests {
     31     use super::*;
     32 
     33     #[test]
     34     fn repost_models_represent_note_and_generic_targets() {
     35         let note_target = RadrootsSocialTarget::Event {
     36             id: "a".repeat(64),
     37             author: Some("b".repeat(64)),
     38             event_kind: Some(1),
     39             relays: None,
     40         };
     41         let article_target = RadrootsSocialTarget::Address {
     42             address: "30023:pubkey:article".to_string(),
     43             author: Some("b".repeat(64)),
     44             event_kind: Some(30023),
     45             relays: Some(vec!["wss://relay.example".to_string()]),
     46         };
     47 
     48         let repost = RadrootsRepost {
     49             target: note_target,
     50             content: None,
     51         };
     52         let generic = RadrootsGenericRepost {
     53             target: article_target,
     54             target_kind: 30023,
     55             content: Some("long-form share".to_string()),
     56         };
     57 
     58         assert!(matches!(repost.target, RadrootsSocialTarget::Event { .. }));
     59         assert_eq!(generic.target_kind, 30023);
     60         assert!(matches!(
     61             generic.target,
     62             RadrootsSocialTarget::Address { .. }
     63         ));
     64     }
     65 }