mirror of https://github.com/LemmyNet/lemmy.git
Add `published` field to outgoing activities (ref #4529)
parent
2fd81067c7
commit
1d5b474c05
|
@ -2633,6 +2633,7 @@ version = "0.19.3"
|
|||
dependencies = [
|
||||
"activitypub_federation",
|
||||
"actix-web",
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"encoding",
|
||||
"enum-map",
|
||||
|
@ -2645,6 +2646,7 @@ dependencies = [
|
|||
"lemmy_db_views_moderator",
|
||||
"lemmy_utils",
|
||||
"mime",
|
||||
"moka",
|
||||
"once_cell",
|
||||
"pretty_assertions",
|
||||
"regex",
|
||||
|
|
|
@ -30,6 +30,7 @@ use activitypub_federation::{
|
|||
traits::{ActivityHandler, Actor},
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use chrono::{DateTime, Local, Utc};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
send_activity::{ActivityChannel, SendActivityData},
|
||||
|
@ -204,8 +205,9 @@ where
|
|||
{
|
||||
info!("Saving outgoing activity to queue {}", activity.id());
|
||||
|
||||
let activity = WithPublished::new(activity);
|
||||
let form = SentActivityForm {
|
||||
ap_id: activity.id().clone().into(),
|
||||
ap_id: activity.inner.id().clone().into(),
|
||||
data: serde_json::to_value(activity)?,
|
||||
sensitive,
|
||||
send_inboxes: send_targets
|
||||
|
@ -223,6 +225,24 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Wrapper struct that adds `published` field with timestamp to outgoing activities. Important that
|
||||
/// the timestamp includes milliseconds and timezone.
|
||||
#[derive(Serialize)]
|
||||
struct WithPublished<T> {
|
||||
published: DateTime<Utc>,
|
||||
#[serde(flatten)]
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> WithPublished<T> {
|
||||
pub fn new(inner: T) -> WithPublished<T> {
|
||||
Self {
|
||||
published: Local::now().into(),
|
||||
inner,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_outgoing_activities(context: Data<LemmyContext>) {
|
||||
while let Some(data) = ActivityChannel::retrieve_activity().await {
|
||||
if let Err(e) = match_outgoing_activities(data, &context.reset_request_count()).await {
|
||||
|
|
Loading…
Reference in New Issue