Add "published" property to outgoing Announce(Note) activities
This commit is contained in:
parent
fd632b4816
commit
a804d0e8bb
2 changed files with 29 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tokio_postgres::GenericClient;
|
use tokio_postgres::GenericClient;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
actors::types::Actor,
|
||||||
|
@ -26,6 +26,7 @@ pub struct Announce {
|
||||||
actor: String,
|
actor: String,
|
||||||
id: String,
|
id: String,
|
||||||
object: String,
|
object: String,
|
||||||
|
published: DateTime<Utc>,
|
||||||
|
|
||||||
to: Vec<String>,
|
to: Vec<String>,
|
||||||
cc: Vec<String>,
|
cc: Vec<String>,
|
||||||
|
@ -34,12 +35,12 @@ pub struct Announce {
|
||||||
fn build_announce_note(
|
fn build_announce_note(
|
||||||
instance_url: &str,
|
instance_url: &str,
|
||||||
sender_username: &str,
|
sender_username: &str,
|
||||||
post: &Post,
|
repost: &Post,
|
||||||
repost_id: &Uuid,
|
|
||||||
) -> Announce {
|
) -> Announce {
|
||||||
let actor_id = local_actor_id(instance_url, sender_username);
|
let actor_id = local_actor_id(instance_url, sender_username);
|
||||||
|
let post = repost.repost_of.as_ref().unwrap();
|
||||||
let object_id = post.get_object_id(instance_url);
|
let object_id = post.get_object_id(instance_url);
|
||||||
let activity_id = local_object_id(instance_url, repost_id);
|
let activity_id = local_object_id(instance_url, &repost.id);
|
||||||
let recipient_id = post.author.actor_id(instance_url);
|
let recipient_id = post.author.actor_id(instance_url);
|
||||||
let followers = local_actor_followers(instance_url, sender_username);
|
let followers = local_actor_followers(instance_url, sender_username);
|
||||||
Announce {
|
Announce {
|
||||||
|
@ -48,6 +49,7 @@ fn build_announce_note(
|
||||||
actor: actor_id,
|
actor: actor_id,
|
||||||
id: activity_id,
|
id: activity_id,
|
||||||
object: object_id,
|
object: object_id,
|
||||||
|
published: repost.created_at,
|
||||||
to: vec![AP_PUBLIC.to_string(), recipient_id],
|
to: vec![AP_PUBLIC.to_string(), recipient_id],
|
||||||
cc: vec![followers],
|
cc: vec![followers],
|
||||||
}
|
}
|
||||||
|
@ -77,10 +79,9 @@ pub async fn prepare_announce_note(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
instance: Instance,
|
instance: Instance,
|
||||||
user: &User,
|
user: &User,
|
||||||
post: &Post,
|
repost: &Post,
|
||||||
repost_id: &Uuid,
|
|
||||||
) -> Result<OutgoingActivity<Announce>, DatabaseError> {
|
) -> Result<OutgoingActivity<Announce>, DatabaseError> {
|
||||||
assert_ne!(&post.id, repost_id);
|
let post = repost.repost_of.as_ref().unwrap();
|
||||||
let (recipients, _) = get_announce_note_recipients(
|
let (recipients, _) = get_announce_note_recipients(
|
||||||
db_client,
|
db_client,
|
||||||
&instance.url(),
|
&instance.url(),
|
||||||
|
@ -90,8 +91,7 @@ pub async fn prepare_announce_note(
|
||||||
let activity = build_announce_note(
|
let activity = build_announce_note(
|
||||||
&instance.url(),
|
&instance.url(),
|
||||||
&user.profile.username,
|
&user.profile.username,
|
||||||
post,
|
repost,
|
||||||
repost_id,
|
|
||||||
);
|
);
|
||||||
Ok(OutgoingActivity {
|
Ok(OutgoingActivity {
|
||||||
instance,
|
instance,
|
||||||
|
@ -105,7 +105,6 @@ pub async fn prepare_announce_note(
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::activitypub::actors::types::Actor;
|
use crate::activitypub::actors::types::Actor;
|
||||||
use crate::models::profiles::types::DbActorProfile;
|
use crate::models::profiles::types::DbActorProfile;
|
||||||
use crate::utils::id::new_uuid;
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const INSTANCE_URL: &str = "https://example.com";
|
const INSTANCE_URL: &str = "https://example.com";
|
||||||
|
@ -127,17 +126,28 @@ mod tests {
|
||||||
object_id: Some(post_id.to_string()),
|
object_id: Some(post_id.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let announcer = DbActorProfile::default();
|
let repost_author = DbActorProfile {
|
||||||
let repost_id = new_uuid();
|
username: "announcer".to_string(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let repost = Post {
|
||||||
|
author: repost_author.clone(),
|
||||||
|
repost_of_id: Some(post.id),
|
||||||
|
repost_of: Some(Box::new(post)),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
let activity = build_announce_note(
|
let activity = build_announce_note(
|
||||||
INSTANCE_URL,
|
INSTANCE_URL,
|
||||||
&announcer.username,
|
&repost_author.username,
|
||||||
&post,
|
&repost,
|
||||||
&repost_id,
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
activity.id,
|
activity.id,
|
||||||
format!("{}/objects/{}", INSTANCE_URL, repost_id),
|
format!("{}/objects/{}", INSTANCE_URL, repost.id),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
activity.actor,
|
||||||
|
format!("{}/users/announcer", INSTANCE_URL),
|
||||||
);
|
);
|
||||||
assert_eq!(activity.object, post_id);
|
assert_eq!(activity.object, post_id);
|
||||||
assert_eq!(activity.to, vec![AP_PUBLIC, post_author_id]);
|
assert_eq!(activity.to, vec![AP_PUBLIC, post_author_id]);
|
||||||
|
|
|
@ -299,16 +299,16 @@ async fn reblog(
|
||||||
repost_of_id: Some(status_id.into_inner()),
|
repost_of_id: Some(status_id.into_inner()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let repost = create_post(db_client, ¤t_user.id, repost_data).await?;
|
let mut repost = create_post(db_client, ¤t_user.id, repost_data).await?;
|
||||||
post.repost_count += 1;
|
post.repost_count += 1;
|
||||||
|
repost.repost_of = Some(Box::new(post));
|
||||||
|
|
||||||
// Federate
|
// Federate
|
||||||
prepare_announce_note(
|
prepare_announce_note(
|
||||||
db_client,
|
db_client,
|
||||||
config.instance(),
|
config.instance(),
|
||||||
¤t_user,
|
¤t_user,
|
||||||
&post,
|
&repost,
|
||||||
&repost.id,
|
|
||||||
).await?.spawn_deliver();
|
).await?.spawn_deliver();
|
||||||
|
|
||||||
let status = build_status(
|
let status = build_status(
|
||||||
|
|
Loading…
Reference in a new issue