2024-05-31 21:29:51 +02:00
|
|
|
use crate::Object;
|
2024-03-21 03:07:35 +01:00
|
|
|
|
2024-03-21 19:15:19 +01:00
|
|
|
pub trait LD {
|
|
|
|
fn ld_context(self) -> Self;
|
|
|
|
}
|
2024-03-21 03:07:35 +01:00
|
|
|
|
2024-03-21 19:15:19 +01:00
|
|
|
impl LD for serde_json::Value {
|
|
|
|
fn ld_context(mut self) -> Self {
|
2024-05-02 05:10:38 +02:00
|
|
|
let o_type = self.object_type();
|
2024-03-21 19:15:19 +01:00
|
|
|
if let Some(obj) = self.as_object_mut() {
|
2024-05-01 21:21:26 +02:00
|
|
|
let mut ctx = serde_json::Map::new();
|
|
|
|
ctx.insert("sensitive".to_string(), serde_json::Value::String("as:sensitive".into()));
|
2024-05-20 08:58:38 +02:00
|
|
|
ctx.insert("quoteUrl".to_string(), serde_json::Value::String("as:quoteUrl".into()));
|
2024-05-02 05:10:38 +02:00
|
|
|
match o_type {
|
2024-05-31 21:29:51 +02:00
|
|
|
Some(crate::ObjectType::Actor(_)) => {
|
2024-05-02 05:10:38 +02:00
|
|
|
ctx.insert("counters".to_string(), serde_json::Value::String("https://ns.alemi.dev/as/counters/#".into()));
|
|
|
|
ctx.insert("followingCount".to_string(), serde_json::Value::String("counters:followingCount".into()));
|
|
|
|
ctx.insert("followersCount".to_string(), serde_json::Value::String("counters:followersCount".into()));
|
|
|
|
ctx.insert("statusesCount".to_string(), serde_json::Value::String("counters:statusesCount".into()));
|
|
|
|
ctx.insert("fe".to_string(), serde_json::Value::String("https://ns.alemi.dev/as/fe/#".into()));
|
|
|
|
ctx.insert("followingMe".to_string(), serde_json::Value::String("fe:followingMe".into()));
|
|
|
|
ctx.insert("followedByMe".to_string(), serde_json::Value::String("fe:followedByMe".into()));
|
|
|
|
},
|
|
|
|
Some(_) => {
|
|
|
|
ctx.insert("fe".to_string(), serde_json::Value::String("https://ns.alemi.dev/as/fe/#".into()));
|
|
|
|
ctx.insert("likedByMe".to_string(), serde_json::Value::String("fe:likedByMe".into()));
|
2024-05-24 00:26:22 +02:00
|
|
|
ctx.insert("ostatus".to_string(), serde_json::Value::String("http://ostatus.org#".into()));
|
|
|
|
ctx.insert("conversation".to_string(), serde_json::Value::String("ostatus:conversation".into()));
|
2024-05-02 05:10:38 +02:00
|
|
|
},
|
|
|
|
None => {},
|
|
|
|
}
|
2024-03-21 19:15:19 +01:00
|
|
|
obj.insert(
|
|
|
|
"@context".to_string(),
|
|
|
|
serde_json::Value::Array(vec![
|
2024-05-01 21:21:26 +02:00
|
|
|
serde_json::Value::String("https://www.w3.org/ns/activitystreams".into()),
|
|
|
|
serde_json::Value::Object(ctx),
|
2024-03-21 19:15:19 +01:00
|
|
|
]),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
tracing::warn!("cannot add @context to json value different than object");
|
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|