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,
|
2020-03-30 17:10:04 +00:00
|
|
|
error::MyError,
|
|
|
|
};
|
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,
|
|
|
|
prelude::*,
|
|
|
|
security,
|
2020-06-20 04:11:02 +00:00
|
|
|
url::Url,
|
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;
|
|
|
|
|
2020-04-21 00:56:50 +00:00
|
|
|
pub use self::{announce::Announce, follow::Follow, forward::Forward, reject::Reject, undo::Undo};
|
2020-03-30 17:10:04 +00:00
|
|
|
|
2020-06-20 04:11:02 +00:00
|
|
|
async fn get_inboxes(state: &State, actor: &Actor, object_id: &Url) -> Result<Vec<Url>, MyError> {
|
|
|
|
let domain = object_id.host().ok_or(MyError::Domain)?.to_string();
|
2020-03-30 17:10:04 +00:00
|
|
|
|
2021-02-10 04:05:06 +00:00
|
|
|
state.inboxes_without(&actor.inbox, &domain).await
|
2020-03-30 17:10:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 21:24:56 +00:00
|
|
|
fn prepare_activity<T, U, V, Kind>(
|
2020-03-30 17:10:04 +00:00
|
|
|
mut t: T,
|
2020-06-20 04:11:02 +00:00
|
|
|
id: impl TryInto<Url, Error = U>,
|
|
|
|
to: impl TryInto<Url, Error = V>,
|
2020-03-30 17:10:04 +00:00
|
|
|
) -> Result<T, MyError>
|
|
|
|
where
|
2020-05-21 21:24:56 +00:00
|
|
|
T: ObjectExt<Kind> + BaseExt<Kind>,
|
2020-03-30 17:10:04 +00:00
|
|
|
MyError: From<U> + From<V>,
|
|
|
|
{
|
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"
|
2020-06-20 04:11:02 +00:00
|
|
|
fn generate_undo_follow(config: &Config, actor_id: &Url, my_id: &Url) -> Result<AsUndo, MyError> {
|
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())
|
|
|
|
}
|