relay/src/jobs/apub/reject.rs

38 lines
1.1 KiB
Rust
Raw Normal View History

2020-03-30 17:10:04 +00:00
use crate::{
config::UrlKind,
data::Actor,
jobs::{apub::generate_undo_follow, Deliver, JobState},
};
2020-05-21 21:24:56 +00:00
use activitystreams_new::primitives::XsdAnyUri;
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)]
pub struct Reject(pub Actor);
impl Reject {
async fn perform(self, state: JobState) -> Result<(), anyhow::Error> {
2020-04-26 01:49:29 +00:00
if state.actors.unfollower(&self.0).await?.is_some() {
2020-03-30 17:10:04 +00:00
state.db.remove_listener(self.0.inbox.clone()).await?;
}
let my_id: XsdAnyUri = state.config.generate_url(UrlKind::Actor).parse()?;
let undo = generate_undo_follow(&state.config, &self.0.id, &my_id)?;
state.job_server.queue(Deliver::new(self.0.inbox, undo)?)?;
Ok(())
}
}
impl ActixJob for Reject {
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::Reject";
2020-04-21 00:56:50 +00:00
2020-03-30 17:10:04 +00:00
fn run(self, state: Self::State) -> Self::Future {
Box::pin(self.perform(state))
}
}