2021-01-05 06:09:59 +00:00
|
|
|
use crate::{
|
|
|
|
apub::actions::{UndoAcceptFollow, UndoFollow},
|
2021-01-06 08:21:17 +00:00
|
|
|
Action, Context, Error, Outbound, Required,
|
2021-01-05 06:09:59 +00:00
|
|
|
};
|
2021-01-04 17:34:31 +00:00
|
|
|
|
2021-01-05 06:09:59 +00:00
|
|
|
impl Action for UndoFollow {
|
2021-01-06 19:49:23 +00:00
|
|
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
2021-01-05 06:09:59 +00:00
|
|
|
let opt = context.store.view.follows.remove(self.follow_id)?;
|
|
|
|
let accept_apub_id = context.apub.apub_for_follow(self.follow_id)?.req()?;
|
|
|
|
context.apub.delete_object(&accept_apub_id)?;
|
|
|
|
context.apub.delete_object(&self.follow_apub_id)?;
|
|
|
|
|
|
|
|
if let Some(undo_follow) = opt {
|
|
|
|
if context.is_local(undo_follow.0.right)? {
|
|
|
|
return Ok(Some(Box::new(crate::apub::results::UndoFollow {
|
|
|
|
follow_apub_id: self.follow_apub_id.clone(),
|
|
|
|
profile_id: undo_follow.0.right,
|
2021-01-06 08:21:17 +00:00
|
|
|
followed_id: undo_follow.0.left,
|
2021-01-05 06:09:59 +00:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Action for UndoAcceptFollow {
|
2021-01-06 19:49:23 +00:00
|
|
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
2021-01-05 06:09:59 +00:00
|
|
|
let opt = context.store.view.follows.remove(self.follow_id)?;
|
|
|
|
let accept_apub_id = context.apub.apub_for_follow(self.follow_id)?.req()?;
|
|
|
|
context.apub.delete_object(&accept_apub_id)?;
|
|
|
|
context.apub.delete_object(&self.follow_apub_id)?;
|
|
|
|
|
|
|
|
if let Some(undo_follow) = opt {
|
|
|
|
if context.is_local(undo_follow.0.right)? {
|
|
|
|
return Ok(Some(Box::new(crate::apub::results::UndoAcceptFollow {
|
|
|
|
accept_apub_id,
|
2021-01-06 08:21:17 +00:00
|
|
|
profile_id: undo_follow.0.left,
|
|
|
|
requester_id: undo_follow.0.right,
|
2021-01-05 06:09:59 +00:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(None)
|
2021-01-04 17:34:31 +00:00
|
|
|
}
|
|
|
|
}
|