Implement AsObject07<User, Like07, &DbConn> for Post

This commit is contained in:
Kitaiti Makoto 2022-04-24 07:04:30 +09:00
parent fcc9e1d81b
commit b2528c21ff

View File

@ -12,7 +12,7 @@ use activitystreams::{
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use plume_common::activity_pub::{ use plume_common::activity_pub::{
inbox::{AsActor, AsObject, FromId}, inbox::{AsActor, AsObject, AsObject07, FromId},
sign::Signer, sign::Signer,
Id, IntoId, PUBLIC_VISIBILITY, Id, IntoId, PUBLIC_VISIBILITY,
}; };
@ -138,6 +138,26 @@ impl AsObject<User, activity::Like, &DbConn> for Post {
} }
} }
impl AsObject07<User, Like07, &DbConn> for Post {
type Error = Error;
type Output = Like;
fn activity07(self, conn: &DbConn, actor: User, id: &str) -> Result<Like> {
let res = Like::insert(
conn,
NewLike {
post_id: self.id,
user_id: actor.id,
ap_url: id.to_string(),
},
)?;
res.notify(conn)?;
Timeline::add_to_all_timelines(conn, &self, Kind::Like(&actor))?;
Ok(res)
}
}
impl FromId<DbConn> for Like { impl FromId<DbConn> for Like {
type Error = Error; type Error = Error;
type Object = activity::Like; type Object = activity::Like;