Move Undo(Like) builder function to builders::undo_like_note module
This commit is contained in:
parent
7103de2519
commit
1c4e75b0d8
4 changed files with 100 additions and 54 deletions
|
@ -130,28 +130,6 @@ pub fn create_activity(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_activity_undo_like(
|
||||
instance_url: &str,
|
||||
actor_profile: &DbActorProfile,
|
||||
reaction_id: &Uuid,
|
||||
recipient_id: &str,
|
||||
) -> Activity {
|
||||
let object_id = get_object_url(
|
||||
instance_url,
|
||||
reaction_id,
|
||||
);
|
||||
let activity_id = format!("{}/undo", object_id);
|
||||
create_activity(
|
||||
instance_url,
|
||||
&actor_profile.username,
|
||||
UNDO,
|
||||
activity_id,
|
||||
object_id,
|
||||
vec![AP_PUBLIC.to_string(), recipient_id.to_string()],
|
||||
vec![],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn create_activity_announce(
|
||||
instance_url: &str,
|
||||
actor_profile: &DbActorProfile,
|
||||
|
@ -207,28 +185,6 @@ mod tests {
|
|||
|
||||
const INSTANCE_URL: &str = "https://example.com";
|
||||
|
||||
#[test]
|
||||
fn test_create_activity_undo_like() {
|
||||
let author = DbActorProfile::default();
|
||||
let note_author_id = "https://example.com/users/test";
|
||||
let reaction_id = new_uuid();
|
||||
let activity = create_activity_undo_like(
|
||||
INSTANCE_URL,
|
||||
&author,
|
||||
&reaction_id,
|
||||
note_author_id,
|
||||
);
|
||||
assert_eq!(
|
||||
activity.id,
|
||||
format!("{}/objects/{}/undo", INSTANCE_URL, reaction_id),
|
||||
);
|
||||
assert_eq!(
|
||||
activity.object,
|
||||
format!("{}/objects/{}", INSTANCE_URL, reaction_id),
|
||||
);
|
||||
assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC, note_author_id]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_activity_announce() {
|
||||
let post_author_id = "https://test.net/user/test";
|
||||
|
|
|
@ -5,4 +5,5 @@ pub mod delete_person;
|
|||
pub mod follow;
|
||||
pub mod like_note;
|
||||
pub mod undo_follow;
|
||||
pub mod undo_like_note;
|
||||
pub mod update_person;
|
||||
|
|
92
src/activitypub/builders/undo_like_note.rs
Normal file
92
src/activitypub/builders/undo_like_note.rs
Normal file
|
@ -0,0 +1,92 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::{
|
||||
activity::{create_activity, Activity},
|
||||
constants::AP_PUBLIC,
|
||||
deliverer::OutgoingActivity,
|
||||
views::get_object_url,
|
||||
vocabulary::UNDO,
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::errors::DatabaseError;
|
||||
use crate::mastodon_api::statuses::helpers::{get_like_recipients, Audience};
|
||||
use crate::models::posts::types::Post;
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
use crate::models::users::types::User;
|
||||
|
||||
fn build_undo_like(
|
||||
instance_url: &str,
|
||||
actor_profile: &DbActorProfile,
|
||||
reaction_id: &Uuid,
|
||||
recipient_id: &str,
|
||||
) -> Activity {
|
||||
let object_id = get_object_url(
|
||||
instance_url,
|
||||
reaction_id,
|
||||
);
|
||||
let activity_id = format!("{}/undo", object_id);
|
||||
create_activity(
|
||||
instance_url,
|
||||
&actor_profile.username,
|
||||
UNDO,
|
||||
activity_id,
|
||||
object_id,
|
||||
vec![AP_PUBLIC.to_string(), recipient_id.to_string()],
|
||||
vec![],
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn prepare_undo_like_note(
|
||||
db_client: &impl GenericClient,
|
||||
instance: Instance,
|
||||
user: &User,
|
||||
post: &Post,
|
||||
reaction_id: &Uuid,
|
||||
) -> Result<OutgoingActivity, DatabaseError> {
|
||||
let Audience { recipients, primary_recipient } =
|
||||
get_like_recipients(db_client, &instance.url(), post).await?;
|
||||
let activity = build_undo_like(
|
||||
&instance.url(),
|
||||
&user.profile,
|
||||
reaction_id,
|
||||
&primary_recipient,
|
||||
);
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
sender: user.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
use crate::utils::id::new_uuid;
|
||||
use super::*;
|
||||
|
||||
const INSTANCE_URL: &str = "https://example.com";
|
||||
|
||||
#[test]
|
||||
fn test_build_undo_like() {
|
||||
let author = DbActorProfile::default();
|
||||
let note_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,
|
||||
);
|
||||
assert_eq!(
|
||||
activity.id,
|
||||
format!("{}/objects/{}/undo", INSTANCE_URL, reaction_id),
|
||||
);
|
||||
assert_eq!(
|
||||
activity.object,
|
||||
format!("{}/objects/{}", INSTANCE_URL, reaction_id),
|
||||
);
|
||||
assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC, note_author_id]));
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ use actix_web_httpauth::extractors::bearer::BearerAuth;
|
|||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::activity::{
|
||||
create_activity_undo_like,
|
||||
create_activity_announce,
|
||||
create_activity_undo_announce,
|
||||
};
|
||||
|
@ -14,6 +13,7 @@ use crate::activitypub::builders::{
|
|||
create_note::prepare_create_note,
|
||||
delete_note::prepare_delete_note,
|
||||
like_note::prepare_like_note,
|
||||
undo_like_note::prepare_undo_like_note,
|
||||
};
|
||||
use crate::activitypub::deliverer::deliver_activity;
|
||||
use crate::config::Config;
|
||||
|
@ -45,7 +45,6 @@ use super::helpers::{
|
|||
build_status,
|
||||
build_status_list,
|
||||
get_announce_recipients,
|
||||
get_like_recipients,
|
||||
Audience,
|
||||
};
|
||||
use super::types::{Status, StatusData, TransactionData};
|
||||
|
@ -270,15 +269,13 @@ async fn unfavourite(
|
|||
|
||||
if let Some(reaction_id) = maybe_reaction_deleted {
|
||||
// Federate
|
||||
let Audience { recipients, primary_recipient } =
|
||||
get_like_recipients(db_client, &config.instance_url(), &post).await?;
|
||||
let activity = create_activity_undo_like(
|
||||
&config.instance_url(),
|
||||
¤t_user.profile,
|
||||
prepare_undo_like_note(
|
||||
db_client,
|
||||
config.instance(),
|
||||
¤t_user,
|
||||
&post,
|
||||
&reaction_id,
|
||||
&primary_recipient,
|
||||
);
|
||||
deliver_activity(&config, ¤t_user, activity, recipients);
|
||||
).await?.spawn_deliver();
|
||||
};
|
||||
|
||||
let status = build_status(
|
||||
|
|
Loading…
Reference in a new issue