From b2528c21ffbd3174d61fef4b982803b0e292e771 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 24 Apr 2022 07:04:30 +0900 Subject: [PATCH] Implement AsObject07 for Post --- plume-models/src/likes.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plume-models/src/likes.rs b/plume-models/src/likes.rs index 4eaf4778..3738d4d1 100644 --- a/plume-models/src/likes.rs +++ b/plume-models/src/likes.rs @@ -12,7 +12,7 @@ use activitystreams::{ use chrono::NaiveDateTime; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use plume_common::activity_pub::{ - inbox::{AsActor, AsObject, FromId}, + inbox::{AsActor, AsObject, AsObject07, FromId}, sign::Signer, Id, IntoId, PUBLIC_VISIBILITY, }; @@ -138,6 +138,26 @@ impl AsObject for Post { } } +impl AsObject07 for Post { + type Error = Error; + type Output = Like; + + fn activity07(self, conn: &DbConn, actor: User, id: &str) -> Result { + 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 for Like { type Error = Error; type Object = activity::Like;