asonix
ab8aa2cbe1
- Add image purge to profile update - Add outbound processing in apub ingest - Add follower + follow request cleanup in profile delete - Add inboxes + id to Outbound trait
72 lines
2 KiB
Rust
72 lines
2 KiB
Rust
use super::{Block as Blocked, UndoBlock};
|
|
use crate::{Context, Error, Outbound, Required};
|
|
use activitystreams::{
|
|
activity::{Block, Undo},
|
|
base::AnyBase,
|
|
context,
|
|
prelude::*,
|
|
security,
|
|
};
|
|
use url::Url;
|
|
use uuid::Uuid;
|
|
|
|
impl Outbound for Blocked {
|
|
fn id(&self) -> Option<Uuid> {
|
|
Some(self.block_id)
|
|
}
|
|
|
|
fn inboxes(&self, ctx: &Context) -> Result<Vec<Url>, Error> {
|
|
let block = ctx.store.view.blocks.by_id(self.block_id)?.req()?;
|
|
let inbox = ctx.apub.endpoints_for_profile(block.left)?.req()?.inbox;
|
|
|
|
Ok(vec![inbox])
|
|
}
|
|
|
|
fn to_apub(&self, ctx: &Context) -> Result<AnyBase, Error> {
|
|
let block = ctx.store.view.blocks.by_id(self.block_id)?.req()?;
|
|
let actor_id = ctx.apub.apub_for_profile(block.right)?.req()?;
|
|
let object_id = ctx.apub.apub_for_profile(block.left)?.req()?;
|
|
let published = block.published;
|
|
|
|
let mut block = Block::new(actor_id, object_id);
|
|
block
|
|
.set_id(ctx.apub.info.gen_id().req()?)
|
|
.set_published(published.into())
|
|
.add_context(context())
|
|
.add_context(security());
|
|
let block = block.into_any_base()?;
|
|
ctx.apub.store_object(&block)?;
|
|
|
|
Ok(block)
|
|
}
|
|
}
|
|
|
|
impl Outbound for UndoBlock {
|
|
fn id(&self) -> Option<Uuid> {
|
|
None
|
|
}
|
|
|
|
fn inboxes(&self, ctx: &Context) -> Result<Vec<Url>, Error> {
|
|
let inbox = ctx
|
|
.apub
|
|
.endpoints_for_profile(self.blocked_id)?
|
|
.req()?
|
|
.inbox;
|
|
Ok(vec![inbox])
|
|
}
|
|
|
|
fn to_apub(&self, ctx: &Context) -> Result<AnyBase, Error> {
|
|
let person_id = ctx.apub.apub_for_profile(self.profile_id)?.req()?;
|
|
let block = ctx.apub.object(&self.block_apub_id)?.req()?;
|
|
|
|
let mut undo = Undo::new(person_id, block);
|
|
undo.set_id(ctx.apub.info.gen_id().req()?)
|
|
.add_context(context())
|
|
.add_context(security());
|
|
let undo = undo.into_any_base()?;
|
|
ctx.apub.store_object(&undo)?;
|
|
|
|
Ok(undo)
|
|
}
|
|
}
|