2021-11-08 15:04:02 +00:00
|
|
|
use activitystreams::{base::AnyBase, primitives::OneOrMany};
|
2021-10-28 15:25:26 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-11-25 17:44:49 +00:00
|
|
|
|
2021-10-28 15:25:26 +00:00
|
|
|
lazy_static! {
|
2021-11-08 15:04:02 +00:00
|
|
|
static ref CONTEXT: OneOrMany<AnyBase> =
|
|
|
|
serde_json::from_str(include_str!("../assets/lemmy/context.json")).expect("parse context");
|
2021-10-28 15:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub(crate) struct WithContext<T> {
|
|
|
|
#[serde(rename = "@context")]
|
|
|
|
context: OneOrMany<AnyBase>,
|
|
|
|
#[serde(flatten)]
|
|
|
|
inner: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> WithContext<T> {
|
|
|
|
pub(crate) fn new(inner: T) -> WithContext<T> {
|
|
|
|
WithContext {
|
|
|
|
context: CONTEXT.clone(),
|
|
|
|
inner,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub(crate) fn inner(self) -> T {
|
|
|
|
self.inner
|
|
|
|
}
|
2020-11-25 17:44:49 +00:00
|
|
|
}
|