2021-10-29 10:32:42 +00:00
|
|
|
use itertools::Itertools;
|
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
use lemmy_apub_lib::traits::ActorType;
|
|
|
|
use lemmy_utils::LemmyError;
|
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
|
2021-10-06 20:20:05 +00:00
|
|
|
use crate::{
|
2021-10-29 10:32:42 +00:00
|
|
|
activities::send_lemmy_activity,
|
|
|
|
activity_lists::AnnouncableActivities,
|
2021-10-06 20:20:05 +00:00
|
|
|
check_is_apub_id_valid,
|
2021-10-28 11:46:48 +00:00
|
|
|
fetcher::object_id::ObjectId,
|
2021-10-06 20:20:05 +00:00
|
|
|
insert_activity,
|
2021-10-18 21:36:44 +00:00
|
|
|
objects::community::ApubCommunity,
|
2021-10-29 10:32:42 +00:00
|
|
|
protocol::activities::community::announce::AnnounceActivity,
|
2021-10-06 20:20:05 +00:00
|
|
|
};
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
|
|
|
|
pub mod add_mod;
|
|
|
|
pub mod announce;
|
|
|
|
pub mod block_user;
|
2021-08-19 21:24:33 +00:00
|
|
|
pub mod remove_mod;
|
2021-10-29 10:32:42 +00:00
|
|
|
pub mod report;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
pub mod undo_block_user;
|
|
|
|
pub mod update;
|
|
|
|
|
2021-07-27 22:18:50 +00:00
|
|
|
async fn list_community_follower_inboxes(
|
2021-10-18 21:36:44 +00:00
|
|
|
community: &ApubCommunity,
|
2021-07-27 22:18:50 +00:00
|
|
|
additional_inboxes: Vec<Url>,
|
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<Vec<Url>, LemmyError> {
|
|
|
|
Ok(
|
|
|
|
vec![
|
2021-09-22 15:57:09 +00:00
|
|
|
community
|
|
|
|
.get_follower_inboxes(context.pool(), &context.settings())
|
|
|
|
.await?,
|
2021-07-27 22:18:50 +00:00
|
|
|
additional_inboxes,
|
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.flatten()
|
|
|
|
.unique()
|
2021-09-22 15:57:09 +00:00
|
|
|
.filter(|inbox| inbox.host_str() != Some(&context.settings().hostname))
|
|
|
|
.filter(|inbox| check_is_apub_id_valid(inbox, false, &context.settings()).is_ok())
|
2021-07-27 22:18:50 +00:00
|
|
|
.map(|inbox| inbox.to_owned())
|
|
|
|
.collect(),
|
|
|
|
)
|
|
|
|
}
|
2021-10-06 20:20:05 +00:00
|
|
|
|
|
|
|
pub(crate) async fn send_to_community<T: ActorType>(
|
|
|
|
activity: AnnouncableActivities,
|
|
|
|
activity_id: &Url,
|
|
|
|
actor: &T,
|
2021-10-18 21:36:44 +00:00
|
|
|
community: &ApubCommunity,
|
2021-10-06 20:20:05 +00:00
|
|
|
additional_inboxes: Vec<Url>,
|
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
// if this is a local community, we need to do an announce from the community instead
|
|
|
|
if community.local {
|
|
|
|
insert_activity(activity_id, activity.clone(), true, false, context.pool()).await?;
|
|
|
|
AnnounceActivity::send(activity, community, additional_inboxes, context).await?;
|
|
|
|
} else {
|
|
|
|
let mut inboxes = additional_inboxes;
|
|
|
|
inboxes.push(community.shared_inbox_or_inbox_url());
|
|
|
|
send_lemmy_activity(context, &activity, activity_id, actor, inboxes, false).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-10-28 11:46:48 +00:00
|
|
|
|
|
|
|
async fn get_community_from_moderators_url(
|
|
|
|
moderators: &Url,
|
|
|
|
context: &LemmyContext,
|
|
|
|
request_counter: &mut i32,
|
|
|
|
) -> Result<ApubCommunity, LemmyError> {
|
|
|
|
let community_id = Url::parse(&moderators.to_string().replace("/moderators", ""))?;
|
|
|
|
ObjectId::new(community_id)
|
|
|
|
.dereference(context, request_counter)
|
|
|
|
.await
|
|
|
|
}
|