Fix bug in create_activity_like()

This commit is contained in:
silverpill 2022-05-13 01:28:39 +00:00
parent ee8b6c497d
commit 9a20c7891f
2 changed files with 24 additions and 3 deletions

View file

@ -280,11 +280,10 @@ pub fn create_activity_note(
pub fn create_activity_like( pub fn create_activity_like(
instance_url: &str, instance_url: &str,
actor_profile: &DbActorProfile, actor_profile: &DbActorProfile,
post_id: &Uuid, object_id: &str,
reaction_id: &Uuid, reaction_id: &Uuid,
recipient_id: &str, recipient_id: &str,
) -> Activity { ) -> Activity {
let object_id = get_object_url(instance_url, post_id);
let activity_id = get_object_url(instance_url, reaction_id); let activity_id = get_object_url(instance_url, reaction_id);
let activity = create_activity( let activity = create_activity(
instance_url, instance_url,
@ -628,6 +627,27 @@ mod tests {
assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC])); assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC]));
} }
#[test]
fn test_create_activity_like() {
let author = DbActorProfile::default();
let note_id = "https://example.com/objects/123";
let note_author_id = "https://example.com/users/test";
let reaction_id = new_uuid();
let activity = create_activity_like(
INSTANCE_URL,
&author,
note_id,
&reaction_id,
note_author_id,
);
assert_eq!(
activity.id,
format!("{}/objects/{}", INSTANCE_URL, reaction_id),
);
assert_eq!(activity.object, json!(note_id));
assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC, note_author_id]));
}
#[test] #[test]
fn test_create_activity_follow() { fn test_create_activity_follow() {
let follower = DbActorProfile { let follower = DbActorProfile {

View file

@ -239,10 +239,11 @@ async fn favourite(
// Federate // Federate
let Audience { recipients, primary_recipient } = let Audience { recipients, primary_recipient } =
get_like_recipients(db_client, &config.instance_url(), &post).await?; get_like_recipients(db_client, &config.instance_url(), &post).await?;
let object_id = post.get_object_id(&config.instance_url());
let activity = create_activity_like( let activity = create_activity_like(
&config.instance_url(), &config.instance_url(),
&current_user.profile, &current_user.profile,
&post.id, &object_id,
&reaction.id, &reaction.id,
&primary_recipient, &primary_recipient,
); );