Add "to" attribute to Activity object

This commit is contained in:
silverpill 2021-11-18 21:28:50 +00:00
parent d104b32d5e
commit 9216d2414b
2 changed files with 12 additions and 0 deletions

View file

@ -87,6 +87,7 @@ pub struct Activity {
pub actor: String, pub actor: String,
pub object: Value, pub object: Value,
pub to: Value,
} }
fn create_activity( fn create_activity(
@ -95,6 +96,7 @@ fn create_activity(
activity_type: &str, activity_type: &str,
activity_uuid: Option<Uuid>, activity_uuid: Option<Uuid>,
object: impl Serialize, object: impl Serialize,
recipient_id: &str,
) -> Activity { ) -> Activity {
let actor_id = get_actor_url( let actor_id = get_actor_url(
instance_url, instance_url,
@ -110,6 +112,7 @@ fn create_activity(
activity_type: activity_type.to_string(), activity_type: activity_type.to_string(),
actor: actor_id, actor: actor_id,
object: serde_json::to_value(object).unwrap(), object: serde_json::to_value(object).unwrap(),
to: json!([recipient_id]),
} }
} }
@ -195,6 +198,7 @@ pub fn create_activity_note(
CREATE, CREATE,
None, None,
object, object,
AP_PUBLIC,
); );
activity activity
} }
@ -216,6 +220,7 @@ pub fn create_activity_like(
LIKE, LIKE,
None, None,
object, object,
AP_PUBLIC,
); );
activity activity
} }
@ -238,6 +243,7 @@ pub fn create_activity_follow(
FOLLOW, FOLLOW,
Some(*follow_request_id), Some(*follow_request_id),
object, object,
target_actor_id,
); );
activity activity
} }
@ -246,6 +252,7 @@ pub fn create_activity_accept_follow(
instance_url: &str, instance_url: &str,
actor_profile: &DbActorProfile, actor_profile: &DbActorProfile,
follow_activity_id: &str, follow_activity_id: &str,
source_actor_id: &str,
) -> Activity { ) -> Activity {
// TODO: use received activity as object // TODO: use received activity as object
let object = Object { let object = Object {
@ -260,6 +267,7 @@ pub fn create_activity_accept_follow(
ACCEPT, ACCEPT,
None, None,
object, object,
source_actor_id,
); );
activity activity
} }
@ -293,6 +301,7 @@ pub fn create_activity_undo_follow(
UNDO, UNDO,
None, None,
object, object,
target_actor_id,
); );
activity activity
} }
@ -308,6 +317,7 @@ pub fn create_activity_update_person(
UPDATE, UPDATE,
None, None,
actor, actor,
AP_PUBLIC,
); );
Ok(activity) Ok(activity)
} }
@ -445,5 +455,6 @@ mod tests {
assert_eq!(activity.object["actor"], Value::Null); assert_eq!(activity.object["actor"], Value::Null);
assert_eq!(activity.object["object"], Value::Null); assert_eq!(activity.object["object"], Value::Null);
assert_eq!(activity.object["content"], Value::Null); assert_eq!(activity.object["content"], Value::Null);
assert_eq!(activity.to, json!([target_actor_id]));
} }
} }

View file

@ -328,6 +328,7 @@ pub async fn receive_activity(
&config.instance_url(), &config.instance_url(),
&target_profile, &target_profile,
&activity.id, &activity.id,
&source_actor.id,
); );
// Save relationship // Save relationship
follow(db_client, &source_profile.id, &target_profile.id).await?; follow(db_client, &source_profile.id, &target_profile.id).await?;