2020-03-30 17:10:04 +00:00
|
|
|
use crate::{
|
|
|
|
config::{Config, UrlKind},
|
2021-02-10 04:05:06 +00:00
|
|
|
data::State,
|
|
|
|
db::Actor,
|
2021-09-18 17:55:39 +00:00
|
|
|
error::{Error, ErrorKind},
|
2020-03-30 17:10:04 +00:00
|
|
|
};
|
2020-09-07 21:51:02 +00:00
|
|
|
use activitystreams::{
|
2020-05-21 21:24:56 +00:00
|
|
|
activity::{Follow as AsFollow, Undo as AsUndo},
|
|
|
|
context,
|
2022-01-17 22:54:45 +00:00
|
|
|
iri_string::types::IriString,
|
2020-05-21 21:24:56 +00:00
|
|
|
prelude::*,
|
|
|
|
security,
|
2020-03-30 17:10:04 +00:00
|
|
|
};
|
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2020-03-30 15:45:44 +00:00
|
|
|
mod announce;
|
2020-03-30 17:10:04 +00:00
|
|
|
mod follow;
|
|
|
|
mod forward;
|
|
|
|
mod reject;
|
|
|
|
mod undo;
|
|
|
|
|
2021-02-10 04:17:20 +00:00
|
|
|
pub(crate) use self::{
|
|
|
|
announce::Announce, follow::Follow, forward::Forward, reject::Reject, undo::Undo,
|
|
|
|
};
|
2020-03-30 17:10:04 +00:00
|
|
|
|
2022-01-17 22:54:45 +00:00
|
|
|
async fn get_inboxes(
|
|
|
|
state: &State,
|
|
|
|
actor: &Actor,
|
|
|
|
object_id: &IriString,
|
|
|
|
) -> Result<Vec<IriString>, Error> {
|
|
|
|
let authority = object_id
|
|
|
|
.authority_str()
|
|
|
|
.ok_or(ErrorKind::Domain)?
|
|
|
|
.to_string();
|
2020-03-30 17:10:04 +00:00
|
|
|
|
2022-01-17 22:54:45 +00:00
|
|
|
state.inboxes_without(&actor.inbox, &authority).await
|
2020-03-30 17:10:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 00:21:55 +00:00
|
|
|
fn prepare_activity<T, U, V>(
|
2020-03-30 17:10:04 +00:00
|
|
|
mut t: T,
|
2022-01-17 22:54:45 +00:00
|
|
|
id: impl TryInto<IriString, Error = U>,
|
|
|
|
to: impl TryInto<IriString, Error = V>,
|
2021-09-18 17:55:39 +00:00
|
|
|
) -> Result<T, Error>
|
2020-03-30 17:10:04 +00:00
|
|
|
where
|
2022-12-07 00:21:55 +00:00
|
|
|
T: ObjectExt + BaseExt,
|
2021-09-18 17:55:39 +00:00
|
|
|
Error: From<U> + From<V>,
|
2020-03-30 17:10:04 +00:00
|
|
|
{
|
2020-05-21 21:24:56 +00:00
|
|
|
t.set_id(id.try_into()?)
|
|
|
|
.set_many_tos(vec![to.try_into()?])
|
|
|
|
.set_many_contexts(vec![context(), security()]);
|
2020-03-30 17:10:04 +00:00
|
|
|
Ok(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a type that says "I want to stop following you"
|
2022-01-17 22:54:45 +00:00
|
|
|
fn generate_undo_follow(
|
|
|
|
config: &Config,
|
|
|
|
actor_id: &IriString,
|
|
|
|
my_id: &IriString,
|
|
|
|
) -> Result<AsUndo, Error> {
|
2020-05-21 21:24:56 +00:00
|
|
|
let mut follow = AsFollow::new(my_id.clone(), actor_id.clone());
|
2020-03-30 17:10:04 +00:00
|
|
|
|
2020-06-03 17:37:36 +00:00
|
|
|
follow.set_id(config.generate_url(UrlKind::Activity));
|
2020-03-30 17:10:04 +00:00
|
|
|
|
2020-05-21 21:24:56 +00:00
|
|
|
let undo = AsUndo::new(my_id.clone(), follow.into_any_base()?);
|
2020-03-30 17:10:04 +00:00
|
|
|
|
|
|
|
prepare_activity(undo, config.generate_url(UrlKind::Actor), actor_id.clone())
|
|
|
|
}
|