From b5867b90ac46f7056807f35faf984615a1ac1753 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 28 Mar 2024 05:24:38 +0100 Subject: [PATCH] feat: accept also bare note to publish --- src/activitypub/user/outbox.rs | 36 ++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/activitypub/user/outbox.rs b/src/activitypub/user/outbox.rs index f1dd9971..07967189 100644 --- a/src/activitypub/user/outbox.rs +++ b/src/activitypub/user/outbox.rs @@ -78,8 +78,40 @@ pub async fn post( None => Err(StatusCode::BAD_REQUEST.into()), Some(BaseType::Link(_)) => Err(StatusCode::UNPROCESSABLE_ENTITY.into()), - // Some(BaseType::Object(ObjectType::Note)) => { - // }, + Some(BaseType::Object(ObjectType::Note)) => { + let oid = ctx.oid(uuid::Uuid::new_v4().to_string()); + let aid = ctx.aid(uuid::Uuid::new_v4().to_string()); + let activity_targets = activity.addressed(); + let object_model = model::object::Model::new( + &activity + .set_id(Some(&oid)) + .set_attributed_to(Node::link(uid.clone())) + .set_published(Some(chrono::Utc::now())) + )?; + let activity_model = model::activity::Model { + id: aid.clone(), + activity_type: ActivityType::Create, + actor: uid.clone(), + object: Some(oid.clone()), + target: None, + cc: object_model.cc.clone(), + bcc: object_model.bcc.clone(), + to: object_model.to.clone(), + bto: object_model.bto.clone(), + published: object_model.published, + }; + + model::object::Entity::insert(object_model.into_active_model()) + .exec(ctx.db()).await?; + model::activity::Entity::insert(activity_model.into_active_model()) + .exec(ctx.db()).await?; + + let addressed = ctx.expand_addressing(&uid, activity_targets).await?; + ctx.address_to(&aid, Some(&oid), &addressed).await?; + ctx.deliver_to(&aid, &uid, &addressed).await?; + + Ok(CreationResult(aid)) + }, Some(BaseType::Object(ObjectType::Activity(ActivityType::Create))) => { let Some(object) = activity.object().get().map(|x| x.underlying_json_object()) else {