forked from alemi/upub
fix: also insert like relation when posting likes
This commit is contained in:
parent
c6703a0a1e
commit
a7a6a23560
1 changed files with 10 additions and 0 deletions
|
@ -197,11 +197,21 @@ pub async fn post(
|
||||||
},
|
},
|
||||||
Some(BaseType::Object(ObjectType::Activity(ActivityType::Like))) => {
|
Some(BaseType::Object(ObjectType::Activity(ActivityType::Like))) => {
|
||||||
let aid = uuid::Uuid::new_v4().to_string();
|
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)?;
|
let mut activity_model = model::activity::Model::new(&activity)?;
|
||||||
activity_model.id = aid.clone();
|
activity_model.id = aid.clone();
|
||||||
activity_model.published = chrono::Utc::now();
|
activity_model.published = chrono::Utc::now();
|
||||||
activity_model.actor = uid.clone();
|
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())
|
model::activity::Entity::insert(activity_model.into_active_model())
|
||||||
.exec(ctx.db()).await?;
|
.exec(ctx.db()).await?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue