From e2702a187b23c2cf47ab40086193a3a8a38b02bd Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 24 Apr 2022 06:35:50 +0900 Subject: [PATCH] Implement AsObject07 for Post --- plume-models/src/reshares.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/plume-models/src/reshares.rs b/plume-models/src/reshares.rs index f2e8ee80..d21da516 100644 --- a/plume-models/src/reshares.rs +++ b/plume-models/src/reshares.rs @@ -7,7 +7,7 @@ use activitystreams::{activity::Announce as Announce07, iri_string::types::IriSt 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, }; @@ -145,6 +145,27 @@ impl AsObject for Post { } } +impl AsObject07 for Post { + type Error = Error; + type Output = Reshare; + + fn activity07(self, conn: &DbConn, actor: User, id: &str) -> Result { + let conn = conn; + let reshare = Reshare::insert( + conn, + NewReshare { + post_id: self.id, + user_id: actor.id, + ap_url: id.to_string(), + }, + )?; + reshare.notify(conn)?; + + Timeline::add_to_all_timelines(conn, &self, Kind::Reshare(&actor))?; + Ok(reshare) + } +} + impl FromId for Reshare { type Error = Error; type Object = Announce;