diff --git a/src/services/bluesky/entities/post.rs b/src/services/bluesky/entities/post.rs index 60e18f6..af8af78 100644 --- a/src/services/bluesky/entities/post.rs +++ b/src/services/bluesky/entities/post.rs @@ -6,8 +6,9 @@ use crate::services::bluesky::internals::cbor::CborValue; #[derive(Debug)] pub struct PostRecord { - pub langs: Option>, pub text: String, + pub langs: Option>, + pub reply: Option, } impl TryFrom for PostRecord { @@ -25,6 +26,59 @@ impl TryFrom for PostRecord { .remove("langs") .map(|value| value.try_into()) .transpose()?, + reply: map.remove("reply") + .map(|value| value.try_into()) + .transpose()?, + }) + } +} + +#[derive(Debug)] +pub struct ReplyRef { + pub parent: Ref, + pub root: Ref, +} + +impl TryFrom for ReplyRef { + type Error = Error; + + fn try_from(root: CborValue) -> Result { + let mut map: HashMap<_, _> = root.try_into()?; + + Ok(ReplyRef { + parent: map + .remove("parent") + .ok_or_else(|| anyhow!("Missing field: parent"))? + .try_into()?, + root: map + .remove("root") + .ok_or_else(|| anyhow!("Missing field: root"))? + .try_into()?, + }) + } +} + +#[derive(Debug)] +pub struct Ref { + pub cid: String, + pub uri: String, +} + +impl TryFrom for Ref { + type Error = Error; + + fn try_from(root: CborValue) -> Result { + let mut map: HashMap<_, _> = root.try_into()?; + + Ok(Ref { + cid: map + .remove("cid") + .ok_or_else(|| anyhow!("Missing field: cid"))? + .try_into()?, + uri: map + .remove("uri") + .ok_or_else(|| anyhow!("Missing field: uri"))? + .try_into()?, }) } }