Allow to like private posts
This commit is contained in:
parent
a8019a95cc
commit
09b06c4fdb
2 changed files with 11 additions and 4 deletions
|
@ -11,7 +11,7 @@ use crate::activitypub::{
|
|||
};
|
||||
use crate::config::Instance;
|
||||
use crate::errors::DatabaseError;
|
||||
use crate::models::posts::types::Post;
|
||||
use crate::models::posts::types::{Post, Visibility};
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
use crate::models::users::types::User;
|
||||
|
||||
|
@ -21,15 +21,20 @@ fn build_like_note(
|
|||
note_id: &str,
|
||||
reaction_id: &Uuid,
|
||||
recipient_id: &str,
|
||||
is_public: bool,
|
||||
) -> Activity {
|
||||
let activity_id = local_object_id(instance_url, reaction_id);
|
||||
let mut primary_audience = vec![recipient_id.to_string()];
|
||||
if is_public {
|
||||
primary_audience.push(AP_PUBLIC.to_string());
|
||||
};
|
||||
let activity = create_activity(
|
||||
instance_url,
|
||||
&actor_profile.username,
|
||||
LIKE,
|
||||
activity_id,
|
||||
note_id,
|
||||
vec![AP_PUBLIC.to_string(), recipient_id.to_string()],
|
||||
primary_audience,
|
||||
vec![],
|
||||
);
|
||||
activity
|
||||
|
@ -67,6 +72,7 @@ pub async fn prepare_like_note(
|
|||
¬e_id,
|
||||
reaction_id,
|
||||
&primary_recipient,
|
||||
matches!(post.visibility, Visibility::Public),
|
||||
);
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
|
@ -96,12 +102,13 @@ mod tests {
|
|||
note_id,
|
||||
&reaction_id,
|
||||
note_author_id,
|
||||
true,
|
||||
);
|
||||
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]));
|
||||
assert_eq!(activity.to.unwrap(), json!([note_author_id, AP_PUBLIC]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,7 +207,7 @@ async fn favourite(
|
|||
let db_client = &mut **get_database_client(&db_pool).await?;
|
||||
let current_user = get_current_user(db_client, auth.token()).await?;
|
||||
let mut post = get_post_by_id(db_client, &status_id).await?;
|
||||
if !post.is_public() || post.repost_of_id.is_some() {
|
||||
if post.repost_of_id.is_some() {
|
||||
return Err(HttpError::NotFoundError("post"));
|
||||
};
|
||||
let maybe_reaction_created = match create_reaction(
|
||||
|
|
Loading…
Reference in a new issue