Use Follow::build_undo07() instead of build_undo()

This commit is contained in:
Kitaiti Makoto 2022-05-03 00:41:05 +09:00
parent e4180b3b38
commit f44bca30f4
2 changed files with 7 additions and 44 deletions

View File

@ -2,9 +2,9 @@ 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 activitypub::activity::{Accept, Follow as FollowAct};
use activitystreams::{ use activitystreams::{
activity::{Accept as Accept07, ActorAndObjectRef, Follow as FollowAct07, Undo as Undo07}, activity::{Accept as Accept07, ActorAndObjectRef, Follow as FollowAct07, Undo},
base::AnyBase, base::AnyBase,
iri_string::types::IriString, iri_string::types::IriString,
prelude::*, prelude::*,
@ -210,23 +210,8 @@ impl Follow {
Ok(accept) Ok(accept)
} }
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> { pub fn build_undo07(&self, conn: &Connection) -> Result<Undo> {
let mut undo = Undo::default(); let mut undo = Undo::new(
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)
}
pub fn build_undo07(&self, conn: &Connection) -> Result<Undo07> {
let mut undo = Undo07::new(
User::get(conn, self.follower_id)? User::get(conn, self.follower_id)?
.ap_url .ap_url
.parse::<IriString>()?, .parse::<IriString>()?,
@ -296,7 +281,7 @@ impl FromId<DbConn> for Follow {
} }
} }
impl AsObject<User, Undo07, &DbConn> for Follow { impl AsObject<User, Undo, &DbConn> for Follow {
type Error = Error; type Error = Error;
type Output = (); type Output = ();
@ -486,28 +471,6 @@ mod tests {
}); });
} }
#[test]
fn build_undo() {
let conn = db();
conn.test_transaction::<_, Error, _>(|| {
let (follow, _following, _follower, _users) = prepare_activity(&conn);
let act = follow.build_undo(&conn)?;
let expected = json!({
"actor": "https://plu.me/@/other/",
"cc": ["https://www.w3.org/ns/activitystreams#Public"],
"id": format!("https://plu.me/follows/{}/undo", follow.id),
"object": format!("https://plu.me/follows/{}", follow.id),
"to": ["https://plu.me/@/user/"],
"type": "Undo"
});
assert_json_eq!(to_value(act)?, expected);
Ok(())
});
}
#[test] #[test]
fn build_undo07() { fn build_undo07() {
let conn = db(); let conn = db();

View File

@ -105,7 +105,7 @@ pub fn follow(
) -> Result<Flash<Redirect>, ErrorPage> { ) -> Result<Flash<Redirect>, ErrorPage> {
let target = User::find_by_fqn(&conn, &name)?; let target = User::find_by_fqn(&conn, &name)?;
let message = if let Ok(follow) = follows::Follow::find(&conn, user.id, target.id) { let message = if let Ok(follow) = follows::Follow::find(&conn, user.id, target.id) {
let delete_act = follow.build_undo(&conn)?; let delete_act = follow.build_undo07(&conn)?;
local_inbox( local_inbox(
&conn, &conn,
serde_json::to_value(&delete_act).map_err(Error::from)?, serde_json::to_value(&delete_act).map_err(Error::from)?,
@ -114,7 +114,7 @@ pub fn follow(
let msg = i18n!(rockets.intl.catalog, "You are no longer following {}."; target.name()); let msg = i18n!(rockets.intl.catalog, "You are no longer following {}."; target.name());
rockets rockets
.worker .worker
.execute(move || broadcast(&user, delete_act, vec![target], CONFIG.proxy().cloned())); .execute(move || broadcast07(&user, delete_act, vec![target], CONFIG.proxy().cloned()));
msg msg
} else { } else {
let f = follows::Follow::insert( let f = follows::Follow::insert(