Implement Follow::accept_follow07()

This commit is contained in:
Kitaiti Makoto 2022-04-24 05:50:45 +09:00
parent f14c307786
commit 44799e94fd

View file

@ -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<A: Signer + IntoId + Clone, B: Clone + AsActor<T> + IntoId, T>(
conn: &Connection,
from: &B,
target: &A,
follow: FollowAct07,
from_id: i32,
target_id: i32,
) -> Result<Follow> {
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<A: Signer + IntoId + Clone, B: Clone + AsActor<T> + IntoId, T>(
&self,
from: &B,