Make Reshare follow activitystreams 0.7
This commit is contained in:
parent
fad7c7279b
commit
fff1b8396b
@ -2,13 +2,18 @@ use crate::{
|
|||||||
ap_url, db_conn::DbConn, instance::Instance, notifications::*, schema::follows, users::User,
|
ap_url, db_conn::DbConn, instance::Instance, notifications::*, schema::follows, users::User,
|
||||||
Connection, Error, Result, CONFIG,
|
Connection, Error, Result, CONFIG,
|
||||||
};
|
};
|
||||||
use activitypub::activity::{Accept, Follow as FollowAct, Undo};
|
use activitystreams::{
|
||||||
|
activity::{Accept, ActivityExt, ActorAndObjectRefExt, AsActivity, Follow as FollowAct, Undo},
|
||||||
|
base::AnyBase,
|
||||||
|
primitives::OneOrMany,
|
||||||
|
uri as as_uri,
|
||||||
|
};
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
||||||
use plume_common::activity_pub::{
|
use plume_common::activity_pub::{
|
||||||
broadcast,
|
broadcast,
|
||||||
inbox::{AsActor, AsObject, FromId},
|
inbox::{AsActor, AsObject, FromId},
|
||||||
sign::Signer,
|
sign::Signer,
|
||||||
Id, IntoId, PUBLIC_VISIBILITY,
|
Id, IntoId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Identifiable, Associations, AsChangeset)]
|
#[derive(Clone, Queryable, Identifiable, Associations, AsChangeset)]
|
||||||
@ -54,14 +59,19 @@ impl Follow {
|
|||||||
let user = User::get(conn, self.follower_id)?;
|
let user = User::get(conn, self.follower_id)?;
|
||||||
let target = User::get(conn, self.following_id)?;
|
let target = User::get(conn, self.following_id)?;
|
||||||
|
|
||||||
let mut act = FollowAct::default();
|
let act = FollowAct::new(
|
||||||
act.follow_props.set_actor_link::<Id>(user.into_id())?;
|
as_uri!(user.ap_url), // FIXME: Use to_activity()
|
||||||
act.follow_props
|
as_uri!(target.ap_url), // FIXME: Use to_activity()
|
||||||
.set_object_link::<Id>(target.clone().into_id())?;
|
);
|
||||||
act.object_props.set_id_string(self.ap_url.clone())?;
|
|
||||||
act.object_props.set_to_link_vec(vec![target.into_id()])?;
|
// let mut act = FollowAct::default();
|
||||||
act.object_props
|
// act.follow_props.set_actor_link::<Id>(user.into_id())?;
|
||||||
.set_cc_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
// act.follow_props
|
||||||
|
// .set_object_link::<Id>(target.clone().into_id())?;
|
||||||
|
// act.object_props.set_id_string(self.ap_url.clone())?;
|
||||||
|
// act.object_props.set_to_link_vec(vec![target.into_id()])?;
|
||||||
|
// act.object_props
|
||||||
|
// .set_cc_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +104,11 @@ impl Follow {
|
|||||||
NewFollow {
|
NewFollow {
|
||||||
follower_id: from_id,
|
follower_id: from_id,
|
||||||
following_id: target_id,
|
following_id: target_id,
|
||||||
ap_url: follow.object_props.id_string()?,
|
ap_url: follow
|
||||||
|
.object()
|
||||||
|
.as_single_id()
|
||||||
|
.expect("exists and only")
|
||||||
|
.to_string(),
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
res.notify(conn)?;
|
res.notify(conn)?;
|
||||||
@ -102,7 +116,7 @@ impl Follow {
|
|||||||
let accept = res.build_accept(from, target, follow)?;
|
let accept = res.build_accept(from, target, follow)?;
|
||||||
broadcast(
|
broadcast(
|
||||||
&*target,
|
&*target,
|
||||||
accept,
|
*accept.activity_ref(),
|
||||||
vec![from.clone()],
|
vec![from.clone()],
|
||||||
CONFIG.proxy().cloned(),
|
CONFIG.proxy().cloned(),
|
||||||
);
|
);
|
||||||
@ -115,39 +129,53 @@ impl Follow {
|
|||||||
target: &A,
|
target: &A,
|
||||||
follow: FollowAct,
|
follow: FollowAct,
|
||||||
) -> Result<Accept> {
|
) -> Result<Accept> {
|
||||||
let mut accept = Accept::default();
|
let accept = Accept::new(
|
||||||
let accept_id = ap_url(&format!(
|
as_uri!(target.into_id()), // FIXME: Use to_activity()
|
||||||
"{}/follows/{}/accept",
|
as_uri!(from.into_id()), // FIXME: Use to_activity()
|
||||||
CONFIG.base_url.as_str(),
|
);
|
||||||
self.id
|
|
||||||
));
|
// let mut accept = Accept::default();
|
||||||
accept.object_props.set_id_string(accept_id)?;
|
// let accept_id = ap_url(&format!(
|
||||||
accept
|
// "{}/follows/{}/accept",
|
||||||
.object_props
|
// CONFIG.base_url.as_str(),
|
||||||
.set_to_link_vec(vec![from.clone().into_id()])?;
|
// self.id
|
||||||
accept
|
// ));
|
||||||
.object_props
|
// accept.object_props.set_id_string(accept_id)?;
|
||||||
.set_cc_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
// accept
|
||||||
accept
|
// .object_props
|
||||||
.accept_props
|
// .set_to_link_vec(vec![from.clone().into_id()])?;
|
||||||
.set_actor_link::<Id>(target.clone().into_id())?;
|
// accept
|
||||||
accept.accept_props.set_object_object(follow)?;
|
// .object_props
|
||||||
|
// .set_cc_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
||||||
|
// accept
|
||||||
|
// .accept_props
|
||||||
|
// .set_actor_link::<Id>(target.clone().into_id())?;
|
||||||
|
// accept.accept_props.set_object_object(follow)?;
|
||||||
|
|
||||||
Ok(accept)
|
Ok(accept)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> {
|
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> {
|
||||||
let mut undo = Undo::default();
|
let follow = self.to_activity(conn)?;
|
||||||
undo.undo_props
|
let undo = Undo::new::<url::Url, OneOrMany<AnyBase>>(
|
||||||
.set_actor_link(User::get(conn, self.follower_id)?.into_id())?;
|
*follow
|
||||||
undo.object_props
|
.actor()
|
||||||
.set_id_string(format!("{}/undo", self.ap_url))?;
|
.expect("authorized domain")
|
||||||
undo.undo_props
|
.as_single_id()
|
||||||
.set_object_link::<Id>(self.clone().into_id())?;
|
.expect("exists and only"),
|
||||||
undo.object_props
|
*follow.result().expect("exists"),
|
||||||
.set_to_link_vec(vec![User::get(conn, self.following_id)?.into_id()])?;
|
);
|
||||||
undo.object_props
|
// let mut undo = Undo::default();
|
||||||
.set_cc_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
// undo.undo_props
|
||||||
|
// .set_actor_link(User::get(conn, self.follower_id)?.into_id())?;
|
||||||
|
// undo.object_props
|
||||||
|
// .set_id_string(format!("{}/undo", self.ap_url))?;
|
||||||
|
// undo.undo_props
|
||||||
|
// .set_object_link::<Id>(self.clone().into_id())?;
|
||||||
|
// undo.object_props
|
||||||
|
// .set_to_link_vec(vec![User::get(conn, self.following_id)?.into_id()])?;
|
||||||
|
// undo.object_props
|
||||||
|
// .set_cc_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
||||||
Ok(undo)
|
Ok(undo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,11 +187,12 @@ impl AsObject<User, FollowAct, &DbConn> for User {
|
|||||||
fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Follow> {
|
fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Follow> {
|
||||||
// Mastodon (at least) requires the full Follow object when accepting it,
|
// Mastodon (at least) requires the full Follow object when accepting it,
|
||||||
// so we rebuilt it here
|
// so we rebuilt it here
|
||||||
let mut follow = FollowAct::default();
|
let follow = FollowAct::new(as_uri!(actor.ap_url), as_uri!(id));
|
||||||
follow.object_props.set_id_string(id.to_string())?;
|
// let mut follow = FollowAct::default();
|
||||||
follow
|
// follow.object_props.set_id_string(id.to_string())?;
|
||||||
.follow_props
|
// follow
|
||||||
.set_actor_link::<Id>(actor.clone().into_id())?;
|
// .follow_props
|
||||||
|
// .set_actor_link::<Id>(actor.clone().into_id())?;
|
||||||
Follow::accept_follow(conn, &actor, &self, follow, actor.id, self.id)
|
Follow::accept_follow(conn, &actor, &self, follow, actor.id, self.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +208,12 @@ impl FromId<DbConn> for Follow {
|
|||||||
fn from_activity(conn: &DbConn, follow: FollowAct) -> Result<Self> {
|
fn from_activity(conn: &DbConn, follow: FollowAct) -> Result<Self> {
|
||||||
let actor = User::from_id(
|
let actor = User::from_id(
|
||||||
conn,
|
conn,
|
||||||
&follow.follow_props.actor_link::<Id>()?,
|
&follow
|
||||||
|
.actor()
|
||||||
|
.expect("authorized domain")
|
||||||
|
.as_single_id()
|
||||||
|
.expect("exists and only")
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
@ -187,7 +221,11 @@ impl FromId<DbConn> for Follow {
|
|||||||
|
|
||||||
let target = User::from_id(
|
let target = User::from_id(
|
||||||
conn,
|
conn,
|
||||||
&follow.follow_props.object_link::<Id>()?,
|
&follow
|
||||||
|
.object()
|
||||||
|
.as_single_id()
|
||||||
|
.expect("exists and only")
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user