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-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
|
|
|
};
|
2021-11-05 00:24:10 +00:00
|
|
|
use lemmy_apub_lib::{object_id::ObjectId, traits::ActorType};
|
2021-11-02 13:02:39 +00:00
|
|
|
use lemmy_utils::LemmyError;
|
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
use url::Url;
|
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;
|
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 update;
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-11-15 21:37:19 +00:00
|
|
|
pub(crate) async fn send_activity_in_community<T: ActorType>(
|
2021-10-06 20:20:05 +00:00
|
|
|
activity: AnnouncableActivities,
|
|
|
|
activity_id: &Url,
|
|
|
|
actor: &T,
|
2021-10-18 21:36:44 +00:00
|
|
|
community: &ApubCommunity,
|
2021-11-15 21:37:19 +00:00
|
|
|
mut inboxes: Vec<Url>,
|
2021-10-06 20:20:05 +00:00
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<(), LemmyError> {
|
2021-11-15 21:37:19 +00:00
|
|
|
inboxes.push(community.shared_inbox_or_inbox_url());
|
|
|
|
send_lemmy_activity(context, &activity, activity_id, actor, inboxes, false).await?;
|
|
|
|
|
2021-10-06 20:20:05 +00:00
|
|
|
if community.local {
|
2021-11-15 21:37:19 +00:00
|
|
|
AnnounceActivity::send(activity, community, context).await?;
|
2021-10-06 20:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-10-28 11:46:48 +00:00
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
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)
|
2021-12-06 22:54:34 +00:00
|
|
|
.dereference(context, context.client(), request_counter)
|
2021-10-28 11:46:48 +00:00
|
|
|
.await
|
|
|
|
}
|