mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-23 04:53:06 +00:00
Create separate SendActivityTask for each destination
This commit is contained in:
parent
60730e81d9
commit
26883208cd
1 changed files with 28 additions and 30 deletions
|
@ -203,15 +203,15 @@ where
|
||||||
insert_activity(actor.user_id(), activity.clone(), true, pool).await?;
|
insert_activity(actor.user_id(), activity.clone(), true, pool).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: it would make sense to create a separate task for each destination server
|
for t in to {
|
||||||
let message = SendActivityTask {
|
let message = SendActivityTask {
|
||||||
activity: serialised_activity,
|
activity: serialised_activity.to_owned(),
|
||||||
to,
|
to: t,
|
||||||
actor_id: actor.actor_id()?,
|
actor_id: actor.actor_id()?,
|
||||||
private_key: actor.private_key().context(location_info!())?,
|
private_key: actor.private_key().context(location_info!())?,
|
||||||
};
|
};
|
||||||
|
activity_sender.queue::<SendActivityTask>(message)?;
|
||||||
activity_sender.queue::<SendActivityTask>(message)?;
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ where
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
struct SendActivityTask {
|
struct SendActivityTask {
|
||||||
activity: String,
|
activity: String,
|
||||||
to: Vec<Url>,
|
to: Url,
|
||||||
actor_id: Url,
|
actor_id: Url,
|
||||||
private_key: String,
|
private_key: String,
|
||||||
}
|
}
|
||||||
|
@ -234,27 +234,25 @@ impl ActixJob for SendActivityTask {
|
||||||
|
|
||||||
fn run(self, state: Self::State) -> Self::Future {
|
fn run(self, state: Self::State) -> Self::Future {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
for to_url in &self.to {
|
let mut headers = BTreeMap::<String, String>::new();
|
||||||
let mut headers = BTreeMap::<String, String>::new();
|
headers.insert("Content-Type".into(), "application/json".into());
|
||||||
headers.insert("Content-Type".into(), "application/json".into());
|
let result = sign_and_send(
|
||||||
let result = sign_and_send(
|
&state.client,
|
||||||
&state.client,
|
headers,
|
||||||
headers,
|
&self.to,
|
||||||
to_url,
|
self.activity.clone(),
|
||||||
self.activity.clone(),
|
&self.actor_id,
|
||||||
&self.actor_id,
|
self.private_key.to_owned(),
|
||||||
self.private_key.to_owned(),
|
)
|
||||||
)
|
.await;
|
||||||
.await;
|
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
warn!("{}", e);
|
warn!("{}", e);
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"Failed to send activity {} to {}",
|
"Failed to send activity {} to {}",
|
||||||
&self.activity,
|
&self.activity,
|
||||||
to_url
|
self.to
|
||||||
));
|
));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue