forked from alemi/upub
fix: context <-> conversation
damn you mastodon!
This commit is contained in:
parent
8ad5738579
commit
c2f3224e0e
1 changed files with 24 additions and 2 deletions
|
@ -101,7 +101,6 @@ impl Object for serde_json::Value {
|
|||
getter! { attributed_to::attributedTo -> node impl Actor }
|
||||
getter! { audience -> node impl Actor }
|
||||
getter! { content -> &str }
|
||||
getter! { context -> node impl Object }
|
||||
getter! { name -> &str }
|
||||
getter! { end_time::endTime -> chrono::DateTime<chrono::Utc> }
|
||||
getter! { generator -> node impl Actor }
|
||||
|
@ -123,6 +122,17 @@ impl Object for serde_json::Value {
|
|||
getter! { media_type -> &str }
|
||||
getter! { duration -> &str }
|
||||
getter! { url -> node impl super::Link }
|
||||
|
||||
// TODO Mastodon doesn't use a "context" field on the object but makes up a new one!!
|
||||
fn context(&self) -> Node<impl Object> {
|
||||
match self.get("context") {
|
||||
Some(x) => Node::from(x.clone()),
|
||||
None => match self.get("conversation") {
|
||||
Some(x) => Node::from(x.clone()),
|
||||
None => Node::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectMut for serde_json::Value {
|
||||
|
@ -131,7 +141,6 @@ impl ObjectMut for serde_json::Value {
|
|||
setter! { attributed_to::attributedTo -> node impl Actor }
|
||||
setter! { audience -> node impl Actor }
|
||||
setter! { content -> &str }
|
||||
setter! { context -> node impl Object }
|
||||
setter! { name -> &str }
|
||||
setter! { end_time::endTime -> chrono::DateTime<chrono::Utc> }
|
||||
setter! { generator -> node impl Actor }
|
||||
|
@ -154,4 +163,17 @@ impl ObjectMut for serde_json::Value {
|
|||
setter! { duration -> &str }
|
||||
setter! { url -> node impl super::Link }
|
||||
|
||||
// TODO Mastodon doesn't use a "context" field on the object but makes up a new one!!
|
||||
fn set_context(mut self, ctx: Node<impl Object>) -> Self {
|
||||
if let Some(conversation) = ctx.id() {
|
||||
crate::activitystream::macros::set_maybe_value(
|
||||
&mut self, "conversation", Some(serde_json::Value::String(conversation.to_string())),
|
||||
);
|
||||
}
|
||||
crate::activitystream::macros::set_maybe_node(
|
||||
&mut self, "context", ctx
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue