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-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
|
|
|
};
|
2023-03-21 15:03:05 +00:00
|
|
|
use activitypub_federation::{config::Data, traits::Actor};
|
2022-11-28 14:29:33 +00:00
|
|
|
use lemmy_api_common::context::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 announce;
|
2023-02-18 14:50:28 +00:00
|
|
|
pub mod collection_add;
|
|
|
|
pub mod collection_remove;
|
|
|
|
pub mod lock_page;
|
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,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2022-11-23 23:40:47 +00:00
|
|
|
) -> Result<(), LemmyError> {
|
2023-03-21 15:03:05 +00:00
|
|
|
// send to any users which are mentioned or affected directly
|
|
|
|
let mut inboxes = extra_inboxes;
|
|
|
|
|
|
|
|
// send to user followers
|
|
|
|
if !is_mod_action {
|
|
|
|
inboxes.append(
|
|
|
|
&mut PersonFollower::list_followers(context.pool(), actor.id)
|
|
|
|
.await?
|
|
|
|
.into_iter()
|
|
|
|
.map(|p| ApubPerson(p).shared_inbox_or_inbox())
|
|
|
|
.collect(),
|
|
|
|
);
|
|
|
|
}
|
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
|
2023-03-21 15:03:05 +00:00
|
|
|
inboxes.push(community.shared_inbox_or_inbox());
|
2021-10-06 20:20:05 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
send_lemmy_activity(context, activity.clone(), actor, inboxes, false).await?;
|
2021-10-06 20:20:05 +00:00
|
|
|
Ok(())
|
|
|
|
}
|