hyaenidae/profiles/src/apub/actions/follow.rs
asonix 29bdf064e9 Profiles: Update profile delete to profile suspend
Clear profile data on suspend
Clear comment body on delete
Update Unfollow and Unblock operations to only delete apub IDs if present
2021-01-14 20:41:53 -06:00

63 lines
2.3 KiB
Rust

use crate::{
apub::actions::{UndoAcceptFollow, UndoFollow},
Action, Context, Error, Outbound, Required,
};
use url::Url;
// Get Follow from Undo Follow or Accept Follow or Reject Follow
fn follow_apub_id(parent_apub_id: &Url, ctx: &Context) -> Result<Url, Error> {
use activitystreams::{activity::ActorAndObject, prelude::*};
let parent_any_base = ctx.apub.object(parent_apub_id)?.req()?;
let parent: ActorAndObject<String> = parent_any_base.extend()?.req()?;
let follow_id = parent.object().as_single_id().req()?;
Ok(follow_id.to_owned())
}
impl Action for UndoFollow {
fn perform(&self, ctx: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
let opt = ctx.store.view.follows.remove(self.follow_id)?;
if let Some(accept_apub_id) = ctx.apub.apub_for_follow(self.follow_id)? {
let follow_apub_id = follow_apub_id(&accept_apub_id, ctx)?;
ctx.apub.delete_object(&accept_apub_id)?;
ctx.apub.delete_object(&follow_apub_id)?;
if let Some(undo_follow) = opt {
if ctx.is_local(undo_follow.0.right)? {
return Ok(Some(Box::new(crate::apub::results::UndoFollow {
follow_apub_id,
profile_id: undo_follow.0.right,
followed_id: undo_follow.0.left,
})));
}
}
}
Ok(None)
}
}
impl Action for UndoAcceptFollow {
fn perform(&self, ctx: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
let opt = ctx.store.view.follows.remove(self.follow_id)?;
if let Some(accept_apub_id) = ctx.apub.apub_for_follow(self.follow_id)? {
let follow_apub_id = follow_apub_id(&accept_apub_id, ctx)?;
ctx.apub.delete_object(&accept_apub_id)?;
ctx.apub.delete_object(&follow_apub_id)?;
if let Some(undo_follow) = opt {
if ctx.is_local(undo_follow.0.right)? {
return Ok(Some(Box::new(crate::apub::results::UndoAcceptFollow {
accept_apub_id,
profile_id: undo_follow.0.left,
requester_id: undo_follow.0.right,
})));
}
}
}
Ok(None)
}
}