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,
|
2022-06-02 14:33:41 +00:00
|
|
|
local_instance,
|
2022-11-23 23:40:47 +00:00
|
|
|
objects::{community::ApubCommunity, person::ApubPerson},
|
2021-10-29 10:32:42 +00:00
|
|
|
protocol::activities::community::announce::AnnounceActivity,
|
2021-10-06 20:20:05 +00:00
|
|
|
};
|
2022-06-08 15:45:39 +00:00
|
|
|
use activitypub_federation::{core::object_id::ObjectId, traits::Actor};
|
2022-11-26 02:04:46 +00:00
|
|
|
use lemmy_api_common::LemmyContext;
|
2022-11-23 23:40:47 +00:00
|
|
|
use lemmy_db_schema::source::person::PersonFollower;
|
2022-06-02 14:33:41 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2021-11-02 13:02:39 +00:00
|
|
|
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;
|
|
|
|
|
2022-11-23 23:40:47 +00:00
|
|
|
/// This function sends all activities which are happening in a community to the right inboxes.
|
|
|
|
/// For example Create/Page, Add/Mod etc, but not private messages.
|
|
|
|
///
|
|
|
|
/// Activities are sent to the community itself if it lives on another instance. If the community
|
|
|
|
/// is local, the activity is directly wrapped into Announce and sent to community followers.
|
|
|
|
/// Activities are also sent to those who follow the actor (with exception of moderation activities).
|
|
|
|
///
|
|
|
|
/// * `activity` - The activity which is being sent
|
|
|
|
/// * `actor` - The user who is sending the activity
|
|
|
|
/// * `community` - Community inside which the activity is sent
|
|
|
|
/// * `inboxes` - Any additional inboxes the activity should be sent to (for example,
|
|
|
|
/// to the user who is being promoted to moderator)
|
|
|
|
/// * `is_mod_activity` - True for things like Add/Mod, these are not sent to user followers
|
|
|
|
pub(crate) async fn send_activity_in_community(
|
2021-10-06 20:20:05 +00:00
|
|
|
activity: AnnouncableActivities,
|
2022-11-23 23:40:47 +00:00
|
|
|
actor: &ApubPerson,
|
2021-10-18 21:36:44 +00:00
|
|
|
community: &ApubCommunity,
|
2022-11-23 23:40:47 +00:00
|
|
|
extra_inboxes: Vec<Url>,
|
|
|
|
is_mod_action: bool,
|
2021-10-06 20:20:05 +00:00
|
|
|
context: &LemmyContext,
|
2022-11-23 23:40:47 +00:00
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
// send to extra_inboxes
|
|
|
|
send_lemmy_activity(context, activity.clone(), actor, extra_inboxes, false).await?;
|
2021-11-15 21:37:19 +00:00
|
|
|
|
2021-10-06 20:20:05 +00:00
|
|
|
if community.local {
|
2022-11-23 23:40:47 +00:00
|
|
|
// send directly to community followers
|
|
|
|
AnnounceActivity::send(activity.clone().try_into()?, community, context).await?;
|
|
|
|
} else {
|
|
|
|
// send to the community, which will then forward to followers
|
|
|
|
let inbox = vec![community.shared_inbox_or_inbox()];
|
|
|
|
send_lemmy_activity(context, activity.clone(), actor, inbox, false).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
// send to those who follow `actor`
|
|
|
|
if !is_mod_action {
|
|
|
|
let inboxes = PersonFollower::list_followers(context.pool(), actor.id)
|
|
|
|
.await?
|
|
|
|
.into_iter()
|
|
|
|
.map(|p| ApubPerson(p).shared_inbox_or_inbox())
|
|
|
|
.collect();
|
|
|
|
send_lemmy_activity(context, activity, actor, inboxes, false).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)]
|
2022-12-01 20:52:49 +00:00
|
|
|
pub(crate) async fn get_community_from_moderators_url(
|
2021-10-28 11:46:48 +00:00
|
|
|
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)
|
2022-11-09 10:05:00 +00:00
|
|
|
.dereference(context, local_instance(context).await, request_counter)
|
2021-10-28 11:46:48 +00:00
|
|
|
.await
|
|
|
|
}
|