2024-03-21 03:07:35 +01:00
|
|
|
use axum::{extract::{Path, State}, http::StatusCode};
|
2024-03-20 08:56:35 +01:00
|
|
|
use sea_orm::EntityTrait;
|
2024-03-23 06:32:15 +01:00
|
|
|
use crate::{activitystream::{object::{activity::ActivityMut, ObjectMut}, BaseMut, Node}, model::{self, activity, object}, server::Context};
|
2024-03-20 05:44:50 +01:00
|
|
|
|
2024-03-21 19:15:19 +01:00
|
|
|
use super::{jsonld::LD, JsonLD};
|
2024-03-20 05:44:50 +01:00
|
|
|
|
2024-03-23 06:32:15 +01:00
|
|
|
pub fn ap_activity(activity: model::activity::Model) -> serde_json::Value {
|
|
|
|
serde_json::Value::new_object()
|
|
|
|
.set_id(Some(&activity.id))
|
|
|
|
.set_activity_type(Some(activity.activity_type))
|
|
|
|
.set_actor(Node::link(activity.actor))
|
|
|
|
.set_object(Node::maybe_link(activity.object))
|
|
|
|
.set_target(Node::maybe_link(activity.target))
|
|
|
|
.set_published(Some(activity.published))
|
|
|
|
.set_to(Node::links(activity.to.0.clone()))
|
|
|
|
.set_bto(Node::empty())
|
|
|
|
.set_cc(Node::links(activity.cc.0.clone()))
|
|
|
|
.set_bcc(Node::empty())
|
|
|
|
}
|
2024-03-21 03:07:35 +01:00
|
|
|
|
|
|
|
pub async fn view(State(ctx) : State<Context>, Path(id): Path<String>) -> Result<JsonLD<serde_json::Value>, StatusCode> {
|
2024-03-21 01:42:29 +01:00
|
|
|
match activity::Entity::find_by_id(ctx.aid(id))
|
|
|
|
.find_also_related(object::Entity)
|
|
|
|
.one(ctx.db())
|
|
|
|
.await
|
|
|
|
{
|
2024-03-21 19:15:19 +01:00
|
|
|
Ok(Some((activity, object))) => Ok(JsonLD(
|
2024-03-23 06:32:15 +01:00
|
|
|
ap_activity(activity)
|
|
|
|
.set_object(Node::maybe_object(object.map(super::object::ap_object)))
|
2024-03-21 19:15:19 +01:00
|
|
|
.ld_context()
|
|
|
|
)),
|
2024-03-20 05:44:50 +01:00
|
|
|
Ok(None) => Err(StatusCode::NOT_FOUND),
|
|
|
|
Err(e) => {
|
|
|
|
tracing::error!("error querying for activity: {e}");
|
|
|
|
Err(StatusCode::INTERNAL_SERVER_ERROR)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|