mirror of
https://github.com/LemmyNet/activitypub-federation-rust.git
synced 2024-06-09 00:39:29 +00:00
remove send_activity function
This commit is contained in:
parent
006943aab1
commit
9d2ada1426
|
@ -4,7 +4,7 @@ To send an activity we need to initialize our previously defined struct, and pic
|
|||
|
||||
```
|
||||
# use activitypub_federation::config::FederationConfig;
|
||||
# use activitypub_federation::activity_sending::send_activity;
|
||||
# use activitypub_federation::activity_sending::SendActivityTask;
|
||||
# use activitypub_federation::http_signatures::generate_actor_keypair;
|
||||
# use activitypub_federation::traits::Actor;
|
||||
# use activitypub_federation::fetch::object_id::ObjectId;
|
||||
|
@ -25,7 +25,11 @@ let activity = Follow {
|
|||
id: "https://lemmy.ml/activities/321".try_into()?
|
||||
};
|
||||
let inboxes = vec![recipient.shared_inbox_or_inbox()];
|
||||
send_activity(&activity, &sender, inboxes, &data).await?;
|
||||
|
||||
let sends = SendActivityTask::prepare(&activity, &sender, inboxes, &data).await?;
|
||||
for send in sends {
|
||||
send.sign_and_send(&data).await?;
|
||||
}
|
||||
# Ok::<(), anyhow::Error>(())
|
||||
# }).unwrap()
|
||||
```
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
DbPost,
|
||||
};
|
||||
use activitypub_federation::{
|
||||
activity_sending::send_activity,
|
||||
activity_sending::SendActivityTask,
|
||||
config::Data,
|
||||
fetch::object_id::ObjectId,
|
||||
kinds::activity::CreateType,
|
||||
|
@ -39,7 +39,12 @@ impl CreatePost {
|
|||
id: generate_object_id(data.domain())?,
|
||||
};
|
||||
let create_with_context = WithContext::new_default(create);
|
||||
send_activity(&create_with_context, &data.local_user(), vec![inbox], data).await?;
|
||||
let sends =
|
||||
SendActivityTask::prepare(&create_with_context, &data.local_user(), vec![inbox], data)
|
||||
.await?;
|
||||
for send in sends {
|
||||
send.sign_and_send(data).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
utils::generate_object_id,
|
||||
};
|
||||
use activitypub_federation::{
|
||||
activity_sending::send_activity,
|
||||
activity_sending::SendActivityTask,
|
||||
config::Data,
|
||||
fetch::{object_id::ObjectId, webfinger::webfinger_resolve_actor},
|
||||
http_signatures::generate_actor_keypair,
|
||||
|
@ -113,7 +113,10 @@ impl DbUser {
|
|||
<Activity as ActivityHandler>::Error: From<anyhow::Error> + From<serde_json::Error>,
|
||||
{
|
||||
let activity = WithContext::new_default(activity);
|
||||
send_activity(&activity, self, recipients, data).await?;
|
||||
let sends = SendActivityTask::prepare(&activity, self, recipients, data).await?;
|
||||
for send in sends {
|
||||
send.sign_and_send(data).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,27 +29,6 @@ use std::{
|
|||
use tracing::debug;
|
||||
use url::Url;
|
||||
|
||||
/// sends an activity to many inboxes
|
||||
/// as opposed to older version, there is no queueing, retrying or parallelization.
|
||||
/// for higher performance and reliability, you'll want to use the methods in [SendActivityTask] directly
|
||||
pub async fn send_activity<Activity, Datatype, ActorType>(
|
||||
activity: &Activity,
|
||||
actor: &ActorType,
|
||||
inboxes: Vec<Url>,
|
||||
data: &Data<Datatype>,
|
||||
) -> Result<(), <Activity as ActivityHandler>::Error>
|
||||
where
|
||||
Activity: ActivityHandler + Serialize,
|
||||
<Activity as ActivityHandler>::Error: From<anyhow::Error> + From<serde_json::Error>,
|
||||
Datatype: Clone,
|
||||
ActorType: Actor,
|
||||
{
|
||||
let sends = SendActivityTask::prepare(activity, actor, inboxes, data).await?;
|
||||
for send in sends {
|
||||
send.sign_and_send(data).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
/// all info needed to send one activity to one inbox
|
||||
pub struct SendActivityTask<'a> {
|
||||
|
@ -103,8 +82,8 @@ impl SendActivityTask<'_> {
|
|||
return None;
|
||||
};
|
||||
Some(SendActivityTask {
|
||||
actor_id: actor_id,
|
||||
activity_id: activity_id,
|
||||
actor_id,
|
||||
activity_id,
|
||||
inbox,
|
||||
activity: activity_serialized.clone(),
|
||||
private_key: private_key.clone(),
|
||||
|
@ -137,7 +116,7 @@ impl SendActivityTask<'_> {
|
|||
.headers(generate_request_headers(&task.inbox));
|
||||
let request = sign_request(
|
||||
request_builder,
|
||||
&task.actor_id,
|
||||
task.actor_id,
|
||||
task.activity.clone(),
|
||||
task.private_key.clone(),
|
||||
task.http_signature_compat,
|
||||
|
|
Loading…
Reference in a new issue