fix: add context extensions depending on type
if actor, add both counters and fe, if object add just fe:likedByMe, to avoid sending useless text every time
This commit is contained in:
parent
0b07979244
commit
4095b0eece
1 changed files with 18 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
// it's not a route
|
// it's not a route
|
||||||
// maybe under src/server/jsonld.rs ??
|
// maybe under src/server/jsonld.rs ??
|
||||||
|
|
||||||
|
use apb::Object;
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
|
|
||||||
pub trait LD {
|
pub trait LD {
|
||||||
|
@ -14,9 +15,26 @@ pub trait LD {
|
||||||
|
|
||||||
impl LD for serde_json::Value {
|
impl LD for serde_json::Value {
|
||||||
fn ld_context(mut self) -> Self {
|
fn ld_context(mut self) -> Self {
|
||||||
|
let o_type = self.object_type();
|
||||||
if let Some(obj) = self.as_object_mut() {
|
if let Some(obj) = self.as_object_mut() {
|
||||||
let mut ctx = serde_json::Map::new();
|
let mut ctx = serde_json::Map::new();
|
||||||
ctx.insert("sensitive".to_string(), serde_json::Value::String("as:sensitive".into()));
|
ctx.insert("sensitive".to_string(), serde_json::Value::String("as:sensitive".into()));
|
||||||
|
match o_type {
|
||||||
|
Some(apb::ObjectType::Actor(_)) => {
|
||||||
|
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()));
|
||||||
|
},
|
||||||
|
None => {},
|
||||||
|
}
|
||||||
obj.insert(
|
obj.insert(
|
||||||
"@context".to_string(),
|
"@context".to_string(),
|
||||||
serde_json::Value::Array(vec![
|
serde_json::Value::Array(vec![
|
||||||
|
|
Loading…
Reference in a new issue