diff --git a/plume-models/src/follows.rs b/plume-models/src/follows.rs index 387858f4..91805f25 100644 --- a/plume-models/src/follows.rs +++ b/plume-models/src/follows.rs @@ -2,9 +2,8 @@ use crate::{ ap_url, db_conn::DbConn, instance::Instance, notifications::*, schema::follows, users::User, Connection, Error, Result, CONFIG, }; -use activitypub::activity::Follow as FollowAct; use activitystreams::{ - activity::{Accept, ActorAndObjectRef, Follow as FollowAct07, Undo}, + activity::{Accept, ActorAndObjectRef, Follow as FollowAct, Undo}, base::AnyBase, iri_string::types::IriString, prelude::*, @@ -56,27 +55,12 @@ impl Follow { .map_err(Error::from) } - pub fn to_activity(&self, conn: &Connection) -> Result { - let user = User::get(conn, self.follower_id)?; - let target = User::get(conn, self.following_id)?; - - let mut act = FollowAct::default(); - act.follow_props.set_actor_link::(user.into_id())?; - act.follow_props - .set_object_link::(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) - } - - pub fn to_activity07(&self, conn: &Connection) -> Result { + pub fn to_activity07(&self, conn: &Connection) -> Result { let user = User::get(conn, self.follower_id)?; let target = User::get(conn, self.following_id)?; let target_id = target.ap_url.parse::()?; - let mut act = FollowAct07::new(user.ap_url.parse::()?, target_id.clone()); + let mut act = FollowAct::new(user.ap_url.parse::()?, target_id.clone()); act.set_id(self.ap_url.parse::()?); act.set_many_tos(vec![target_id]); act.set_many_ccs(vec![PUBLIC_VISIBILITY.parse::()?]); @@ -104,7 +88,7 @@ impl Follow { conn: &Connection, from: &B, target: &A, - follow: FollowAct07, + follow: FollowAct, from_id: i32, target_id: i32, ) -> Result { @@ -135,7 +119,7 @@ impl Follow { &self, from: &B, target: &A, - follow: FollowAct07, + follow: FollowAct, ) -> Result { let mut accept = Accept::new( target.clone().into_id().parse::()?, @@ -170,7 +154,7 @@ impl Follow { } } -impl AsObject for User { +impl AsObject for User { type Error = Error; type Output = Follow; @@ -178,7 +162,7 @@ impl AsObject for User { // Mastodon (at least) requires the full Follow object when accepting it, // so we rebuilt it here let mut follow = - FollowAct07::new(id.parse::()?, actor.ap_url.parse::()?); + FollowAct::new(id.parse::()?, actor.ap_url.parse::()?); follow.set_id(id.parse::()?); Follow::accept_follow07(conn, &actor, &self, follow, actor.id, self.id) } @@ -186,13 +170,13 @@ impl AsObject for User { impl FromId for Follow { type Error = Error; - type Object = FollowAct07; + type Object = FollowAct; fn from_db07(conn: &DbConn, id: &str) -> Result { Follow::find_by_ap_url(conn, id) } - fn from_activity07(conn: &DbConn, follow: FollowAct07) -> Result { + fn from_activity07(conn: &DbConn, follow: FollowAct) -> Result { let actor = User::from_id( conn, follow @@ -312,28 +296,6 @@ mod tests { }) } - #[test] - fn to_activity() { - let conn = db(); - conn.test_transaction::<_, Error, _>(|| { - let (follow, _following, _follower, _users) = prepare_activity(&conn); - let act = follow.to_activity(&conn)?; - - let expected = json!({ - "actor": "https://plu.me/@/other/", - "cc": ["https://www.w3.org/ns/activitystreams#Public"], - "id": format!("https://plu.me/follows/{}", follow.id), - "object": "https://plu.me/@/user/", - "to": ["https://plu.me/@/user/"], - "type": "Follow" - }); - - assert_json_eq!(to_value(act)?, expected); - - Ok(()) - }); - } - #[test] fn to_activity07() { let conn = db(); diff --git a/src/routes/user.rs b/src/routes/user.rs index 2ed62d68..c8327ea7 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -18,9 +18,7 @@ use crate::routes::{ }; use crate::template_utils::{IntoContext, Ructe}; use crate::utils::requires_login; -use plume_common::activity_pub::{ - broadcast, broadcast07, ActivityStream, ApRequest, CustomPerson, Id, -}; +use plume_common::activity_pub::{broadcast07, ActivityStream, ApRequest, CustomPerson, Id}; use plume_common::utils::md_to_html; use plume_models::{ blogs::Blog, @@ -127,11 +125,11 @@ pub fn follow( )?; f.notify(&conn)?; - let act = f.to_activity(&conn)?; + let act = f.to_activity07(&conn)?; let msg = i18n!(rockets.intl.catalog, "You are now following {}."; target.name()); rockets .worker - .execute(move || broadcast(&user, act, vec![target], CONFIG.proxy().cloned())); + .execute(move || broadcast07(&user, act, vec![target], CONFIG.proxy().cloned())); msg }; Ok(Flash::success(