diff --git a/src/activitypub/builders/announce_note.rs b/src/activitypub/builders/announce.rs similarity index 93% rename from src/activitypub/builders/announce_note.rs rename to src/activitypub/builders/announce.rs index 736dcc3..c1d4bea 100644 --- a/src/activitypub/builders/announce_note.rs +++ b/src/activitypub/builders/announce.rs @@ -32,7 +32,7 @@ struct Announce { cc: Vec, } -fn build_announce_note( +fn build_announce( instance_url: &str, sender_username: &str, repost: &Post, @@ -55,7 +55,7 @@ fn build_announce_note( } } -pub async fn get_announce_note_recipients( +pub async fn get_announce_recipients( db_client: &impl GenericClient, instance_url: &str, current_user: &User, @@ -75,20 +75,20 @@ pub async fn get_announce_note_recipients( Ok((recipients, primary_recipient)) } -pub async fn prepare_announce_note( +pub async fn prepare_announce( db_client: &impl GenericClient, instance: &Instance, sender: &User, repost: &Post, ) -> Result { let post = repost.repost_of.as_ref().unwrap(); - let (recipients, _) = get_announce_note_recipients( + let (recipients, _) = get_announce_recipients( db_client, &instance.url(), sender, post, ).await?; - let activity = build_announce_note( + let activity = build_announce( &instance.url(), &sender.profile.username, repost, @@ -110,7 +110,7 @@ mod tests { const INSTANCE_URL: &str = "https://example.com"; #[test] - fn test_build_announce_note() { + fn test_build_announce() { let post_author_id = "https://test.net/user/test"; let post_author = DbActorProfile { actor_json: Some(Actor { @@ -136,7 +136,7 @@ mod tests { repost_of: Some(Box::new(post)), ..Default::default() }; - let activity = build_announce_note( + let activity = build_announce( INSTANCE_URL, &repost_author.username, &repost, diff --git a/src/activitypub/builders/like_note.rs b/src/activitypub/builders/like.rs similarity index 76% rename from src/activitypub/builders/like_note.rs rename to src/activitypub/builders/like.rs index 8a43129..9a7bcf2 100644 --- a/src/activitypub/builders/like_note.rs +++ b/src/activitypub/builders/like.rs @@ -31,7 +31,7 @@ struct Like { cc: Vec, } -pub fn get_like_note_audience( +pub fn get_like_audience( note_author_id: &str, note_visibility: &Visibility, ) -> (Vec, Vec) { @@ -43,30 +43,30 @@ pub fn get_like_note_audience( (primary_audience, secondary_audience) } -fn build_like_note( +fn build_like( instance_url: &str, actor_profile: &DbActorProfile, - note_id: &str, + object_id: &str, reaction_id: &Uuid, - note_author_id: &str, - note_visibility: &Visibility, + post_author_id: &str, + post_visibility: &Visibility, ) -> Like { let activity_id = local_object_id(instance_url, reaction_id); let actor_id = local_actor_id(instance_url, &actor_profile.username); let (primary_audience, secondary_audience) = - get_like_note_audience(note_author_id, note_visibility); + get_like_audience(post_author_id, post_visibility); Like { context: AP_CONTEXT.to_string(), activity_type: LIKE.to_string(), id: activity_id, actor: actor_id, - object: note_id.to_string(), + object: object_id.to_string(), to: primary_audience, cc: secondary_audience, } } -pub async fn get_like_note_recipients( +pub async fn get_like_recipients( _db_client: &impl GenericClient, _instance_url: &str, post: &Post, @@ -78,26 +78,26 @@ pub async fn get_like_note_recipients( Ok(recipients) } -pub async fn prepare_like_note( +pub async fn prepare_like( db_client: &impl GenericClient, instance: &Instance, sender: &User, post: &Post, reaction_id: &Uuid, ) -> Result { - let recipients = get_like_note_recipients( + let recipients = get_like_recipients( db_client, &instance.url(), post, ).await?; - let note_id = post.object_id(&instance.url()); - let note_author_id = post.author.actor_id(&instance.url()); - let activity = build_like_note( + let object_id = post.object_id(&instance.url()); + let post_author_id = post.author.actor_id(&instance.url()); + let activity = build_like( &instance.url(), &sender.profile, - ¬e_id, + &object_id, reaction_id, - ¬e_author_id, + &post_author_id, &post.visibility, ); Ok(OutgoingActivity::new( @@ -116,25 +116,25 @@ mod tests { const INSTANCE_URL: &str = "https://example.com"; #[test] - fn test_build_like_note() { + fn test_build_like() { let author = DbActorProfile::default(); - let note_id = "https://example.com/objects/123"; - let note_author_id = "https://example.com/users/test"; + let post_id = "https://example.com/objects/123"; + let post_author_id = "https://example.com/users/test"; let reaction_id = new_uuid(); - let activity = build_like_note( + let activity = build_like( INSTANCE_URL, &author, - note_id, + post_id, &reaction_id, - note_author_id, + post_author_id, &Visibility::Public, ); assert_eq!( activity.id, format!("{}/objects/{}", INSTANCE_URL, reaction_id), ); - assert_eq!(activity.object, note_id); - assert_eq!(activity.to, vec![note_author_id, AP_PUBLIC]); + assert_eq!(activity.object, post_id); + assert_eq!(activity.to, vec![post_author_id, AP_PUBLIC]); assert_eq!(activity.cc.is_empty(), true); } } diff --git a/src/activitypub/builders/mod.rs b/src/activitypub/builders/mod.rs index ee47e90..35ce0f2 100644 --- a/src/activitypub/builders/mod.rs +++ b/src/activitypub/builders/mod.rs @@ -1,14 +1,14 @@ pub mod accept_follow; pub mod add_person; -pub mod announce_note; +pub mod announce; pub mod create_note; pub mod delete_note; pub mod delete_person; pub mod follow; -pub mod like_note; +pub mod like; pub mod move_person; pub mod remove_person; -pub mod undo_announce_note; +pub mod undo_announce; pub mod undo_follow; -pub mod undo_like_note; +pub mod undo_like; pub mod update_person; diff --git a/src/activitypub/builders/undo_announce_note.rs b/src/activitypub/builders/undo_announce.rs similarity index 94% rename from src/activitypub/builders/undo_announce_note.rs rename to src/activitypub/builders/undo_announce.rs index e7f1584..ddf67a4 100644 --- a/src/activitypub/builders/undo_announce_note.rs +++ b/src/activitypub/builders/undo_announce.rs @@ -13,7 +13,7 @@ use crate::database::DatabaseError; use crate::models::posts::types::Post; use crate::models::profiles::types::DbActorProfile; use crate::models::users::types::User; -use super::announce_note::get_announce_note_recipients; +use super::announce::get_announce_recipients; #[derive(Serialize)] struct UndoAnnounce { @@ -58,7 +58,7 @@ fn build_undo_announce( } } -pub async fn prepare_undo_announce_note( +pub async fn prepare_undo_announce( db_client: &impl GenericClient, instance: &Instance, sender: &User, @@ -66,7 +66,7 @@ pub async fn prepare_undo_announce_note( repost_id: &Uuid, ) -> Result { assert_ne!(&post.id, repost_id); - let (recipients, primary_recipient) = get_announce_note_recipients( + let (recipients, primary_recipient) = get_announce_recipients( db_client, &instance.url(), sender, diff --git a/src/activitypub/builders/undo_like_note.rs b/src/activitypub/builders/undo_like.rs similarity index 82% rename from src/activitypub/builders/undo_like_note.rs rename to src/activitypub/builders/undo_like.rs index 9ae6b22..9a51196 100644 --- a/src/activitypub/builders/undo_like_note.rs +++ b/src/activitypub/builders/undo_like.rs @@ -13,9 +13,9 @@ use crate::database::DatabaseError; use crate::models::posts::types::{Post, Visibility}; use crate::models::profiles::types::DbActorProfile; use crate::models::users::types::User; -use super::like_note::{ - get_like_note_audience, - get_like_note_recipients, +use super::like::{ + get_like_audience, + get_like_recipients, }; #[derive(Serialize)] @@ -38,14 +38,14 @@ fn build_undo_like( instance_url: &str, actor_profile: &DbActorProfile, reaction_id: &Uuid, - note_author_id: &str, - note_visibility: &Visibility, + post_author_id: &str, + post_visibility: &Visibility, ) -> UndoLike { let object_id = local_object_id(instance_url, reaction_id); let activity_id = format!("{}/undo", object_id); let actor_id = local_actor_id(instance_url, &actor_profile.username); let (primary_audience, secondary_audience) = - get_like_note_audience(note_author_id, note_visibility); + get_like_audience(post_author_id, post_visibility); UndoLike { context: AP_CONTEXT.to_string(), activity_type: UNDO.to_string(), @@ -57,24 +57,24 @@ fn build_undo_like( } } -pub async fn prepare_undo_like_note( +pub async fn prepare_undo_like( db_client: &impl GenericClient, instance: &Instance, sender: &User, post: &Post, reaction_id: &Uuid, ) -> Result { - let recipients = get_like_note_recipients( + let recipients = get_like_recipients( db_client, &instance.url(), post, ).await?; - let note_author_id = post.author.actor_id(&instance.url()); + let post_author_id = post.author.actor_id(&instance.url()); let activity = build_undo_like( &instance.url(), &sender.profile, reaction_id, - ¬e_author_id, + &post_author_id, &post.visibility, ); Ok(OutgoingActivity::new( @@ -96,13 +96,13 @@ mod tests { #[test] fn test_build_undo_like() { let author = DbActorProfile::default(); - let note_author_id = "https://example.com/users/test"; + let post_author_id = "https://example.com/users/test"; let reaction_id = new_uuid(); let activity = build_undo_like( INSTANCE_URL, &author, &reaction_id, - note_author_id, + post_author_id, &Visibility::Public, ); assert_eq!( @@ -113,6 +113,6 @@ mod tests { activity.object, format!("{}/objects/{}", INSTANCE_URL, reaction_id), ); - assert_eq!(activity.to, vec![note_author_id, AP_PUBLIC]); + assert_eq!(activity.to, vec![post_author_id, AP_PUBLIC]); } } diff --git a/src/mastodon_api/statuses/views.rs b/src/mastodon_api/statuses/views.rs index 6ebfef0..d587ac1 100644 --- a/src/mastodon_api/statuses/views.rs +++ b/src/mastodon_api/statuses/views.rs @@ -6,12 +6,12 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use uuid::Uuid; use crate::activitypub::builders::{ - announce_note::prepare_announce_note, + announce::prepare_announce, create_note::prepare_create_note, delete_note::prepare_delete_note, - like_note::prepare_like_note, - undo_announce_note::prepare_undo_announce_note, - undo_like_note::prepare_undo_like_note, + like::prepare_like, + undo_announce::prepare_undo_announce, + undo_like::prepare_undo_like, }; use crate::config::Config; use crate::database::{get_database_client, DatabaseError, DbPool}; @@ -305,7 +305,7 @@ async fn favourite( if let Some(reaction) = maybe_reaction_created { // Federate - prepare_like_note( + prepare_like( db_client, &config.instance(), ¤t_user, @@ -346,7 +346,7 @@ async fn unfavourite( if let Some(reaction_id) = maybe_reaction_deleted { // Federate - prepare_undo_like_note( + prepare_undo_like( db_client, &config.instance(), ¤t_user, @@ -383,7 +383,7 @@ async fn reblog( repost.repost_of = Some(Box::new(post)); // Federate - prepare_announce_note( + prepare_announce( db_client, &config.instance(), ¤t_user, @@ -419,7 +419,7 @@ async fn unreblog( let post = get_post_by_id(db_client, &status_id).await?; // Federate - prepare_undo_announce_note( + prepare_undo_announce( db_client, &config.instance(), ¤t_user,