Use Follow type to create embedded activity when building Undo(Follow)

This commit is contained in:
silverpill 2022-12-05 22:45:52 +00:00
parent 7c3d669e9b
commit 777dd74373
2 changed files with 16 additions and 17 deletions

View file

@ -13,18 +13,18 @@ use crate::models::profiles::types::DbActorProfile;
use crate::models::users::types::User; use crate::models::users::types::User;
#[derive(Serialize)] #[derive(Serialize)]
struct Follow { pub(super) struct Follow {
#[serde(rename = "@context")] #[serde(rename = "@context")]
context: String, pub context: String,
#[serde(rename = "type")] #[serde(rename = "type")]
activity_type: String, pub activity_type: String,
id: String, pub id: String,
actor: String, pub actor: String,
object: String, pub object: String,
to: Vec<String>, pub to: Vec<String>,
} }
fn build_follow( fn build_follow(

View file

@ -1,9 +1,7 @@
use serde::Serialize; use serde::Serialize;
use serde_json::json;
use uuid::Uuid; use uuid::Uuid;
use crate::activitypub::{ use crate::activitypub::{
activity::Object,
actors::types::Actor, actors::types::Actor,
constants::AP_CONTEXT, constants::AP_CONTEXT,
deliverer::OutgoingActivity, deliverer::OutgoingActivity,
@ -13,6 +11,7 @@ use crate::activitypub::{
use crate::config::Instance; use crate::config::Instance;
use crate::models::profiles::types::DbActorProfile; use crate::models::profiles::types::DbActorProfile;
use crate::models::users::types::User; use crate::models::users::types::User;
use super::follow::Follow;
#[derive(Serialize)] #[derive(Serialize)]
struct UndoFollow { struct UndoFollow {
@ -24,7 +23,7 @@ struct UndoFollow {
id: String, id: String,
actor: String, actor: String,
object: Object, object: Follow,
to: Vec<String>, to: Vec<String>,
} }
@ -43,13 +42,13 @@ fn build_undo_follow(
instance_url, instance_url,
&actor_profile.username, &actor_profile.username,
); );
let object = Object { let object = Follow {
context: Some(json!(AP_CONTEXT)), context: AP_CONTEXT.to_string(),
activity_type: FOLLOW.to_string(),
id: follow_activity_id, id: follow_activity_id,
object_type: FOLLOW.to_string(), actor: follow_actor_id,
actor: Some(follow_actor_id), object: target_actor_id.to_string(),
object: Some(target_actor_id.to_owned()), to: vec![target_actor_id.to_string()],
..Default::default()
}; };
let activity_id = format!("{}/undo", object.id); let activity_id = format!("{}/undo", object.id);
let actor_id = local_actor_id(instance_url, &actor_profile.username); let actor_id = local_actor_id(instance_url, &actor_profile.username);
@ -115,7 +114,7 @@ mod tests {
activity.object.id, activity.object.id,
format!("{}/objects/{}", INSTANCE_URL, follow_request_id), format!("{}/objects/{}", INSTANCE_URL, follow_request_id),
); );
assert_eq!(activity.object.object.unwrap(), target_actor_id); assert_eq!(activity.object.object, target_actor_id);
assert_eq!(activity.to, vec![target_actor_id]); assert_eq!(activity.to, vec![target_actor_id]);
} }
} }