From a7a6a23560a40ad2349d0b607eeeba9d63d7805f Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 26 Mar 2024 02:13:03 +0100 Subject: [PATCH] fix: also insert like relation when posting likes --- src/activitypub/user/outbox.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/activitypub/user/outbox.rs b/src/activitypub/user/outbox.rs index 75987e86..c48116e4 100644 --- a/src/activitypub/user/outbox.rs +++ b/src/activitypub/user/outbox.rs @@ -197,11 +197,21 @@ pub async fn post( }, Some(BaseType::Object(ObjectType::Activity(ActivityType::Like))) => { let aid = uuid::Uuid::new_v4().to_string(); + let Some(oid) = activity.object().id().map(|x| x.to_string()) else { + return Err(StatusCode::BAD_REQUEST.into()); + }; let mut activity_model = model::activity::Model::new(&activity)?; activity_model.id = aid.clone(); activity_model.published = chrono::Utc::now(); activity_model.actor = uid.clone(); + let like_model = model::like::ActiveModel { + actor: Set(uid.clone()), + likes: Set(oid.clone()), + date: Set(chrono::Utc::now()), + ..Default::default() + }; + model::like::Entity::insert(like_model).exec(ctx.db()).await?; model::activity::Entity::insert(activity_model.into_active_model()) .exec(ctx.db()).await?;