From 44799e94fda195875cd4f45dc9981cb0ebb37466 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 24 Apr 2022 05:50:45 +0900 Subject: [PATCH] Implement Follow::accept_follow07() --- plume-models/src/follows.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/plume-models/src/follows.rs b/plume-models/src/follows.rs index d8a163ba..df47b708 100644 --- a/plume-models/src/follows.rs +++ b/plume-models/src/follows.rs @@ -11,7 +11,7 @@ use activitystreams::{ }; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; use plume_common::activity_pub::{ - broadcast, + broadcast, broadcast07, inbox::{AsActor, AsObject, FromId}, sign::Signer, Id, IntoId, PUBLIC_VISIBILITY, @@ -128,6 +128,39 @@ impl Follow { Ok(res) } + /// from -> The one sending the follow request + /// target -> The target of the request, responding with Accept + pub fn accept_follow07 + IntoId, T>( + conn: &Connection, + from: &B, + target: &A, + follow: FollowAct07, + from_id: i32, + target_id: i32, + ) -> Result { + let res = Follow::insert( + conn, + NewFollow { + follower_id: from_id, + following_id: target_id, + ap_url: follow + .id_unchecked() + .ok_or(Error::MissingApProperty)? + .to_string(), + }, + )?; + res.notify(conn)?; + + let accept = res.build_accept07(from, target, follow)?; + broadcast07( + &*target, + accept, + vec![from.clone()], + CONFIG.proxy().cloned(), + ); + Ok(res) + } + pub fn build_accept + IntoId, T>( &self, from: &B,