relay/src/jobs/apub/forward.rs

51 lines
1.3 KiB
Rust
Raw Normal View History

2020-03-30 17:10:04 +00:00
use crate::{
2020-05-21 21:24:56 +00:00
apub::AcceptedActivities,
2021-02-10 04:05:06 +00:00
db::Actor,
2021-09-18 17:55:39 +00:00
error::{Error, ErrorKind},
2020-03-30 17:10:04 +00:00
jobs::{apub::get_inboxes, DeliverMany, JobState},
};
2020-09-07 21:51:02 +00:00
use activitystreams::prelude::*;
2020-04-21 00:56:50 +00:00
use background_jobs::ActixJob;
2020-03-30 17:10:04 +00:00
use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2021-02-10 04:17:20 +00:00
pub(crate) struct Forward {
2020-05-21 21:24:56 +00:00
input: AcceptedActivities,
2020-03-30 17:10:04 +00:00
actor: Actor,
}
impl Forward {
2020-05-21 21:24:56 +00:00
pub fn new(input: AcceptedActivities, actor: Actor) -> Self {
2020-03-30 17:10:04 +00:00
Forward { input, actor }
}
2021-09-18 17:55:39 +00:00
#[tracing::instrument(name = "Forward")]
async fn perform(self, state: JobState) -> Result<(), Error> {
2020-05-21 21:24:56 +00:00
let object_id = self
.input
2022-01-17 22:54:45 +00:00
.object_unchecked()
2020-05-21 21:24:56 +00:00
.as_single_id()
2021-09-18 17:55:39 +00:00
.ok_or(ErrorKind::MissingId)?;
2020-03-30 17:10:04 +00:00
let inboxes = get_inboxes(&state.state, &self.actor, object_id).await?;
state
.job_server
2022-01-17 22:54:45 +00:00
.queue(DeliverMany::new(inboxes, self.input)?)
.await?;
2020-03-30 17:10:04 +00:00
Ok(())
}
}
impl ActixJob for Forward {
type State = JobState;
type Future = Pin<Box<dyn Future<Output = Result<(), anyhow::Error>>>>;
2020-04-21 01:03:46 +00:00
const NAME: &'static str = "relay::jobs::apub::Forward";
2020-04-21 00:56:50 +00:00
2020-03-30 17:10:04 +00:00
fn run(self, state: Self::State) -> Self::Future {
2021-09-18 17:55:39 +00:00
Box::pin(async move { self.perform(state).await.map_err(Into::into) })
2020-03-30 17:10:04 +00:00
}
}