]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/mod.rs
Implement separate mod activities for feature, lock post (#2716)
[lemmy.git] / crates / apub / src / activities / mod.rs
index 3cf9771e13b912570b54a02a7842ee1600f95dd7..2896959fc60654e31898094b0564e67fc5e9b8de 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  generate_moderators_url,
   insert_activity,
   local_instance,
   objects::{community::ApubCommunity, person::ApubPerson},
@@ -13,13 +12,13 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::public;
 use anyhow::anyhow;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   newtypes::CommunityId,
   source::{community::Community, local_site::LocalSite},
 };
 use lemmy_db_views_actor::structs::{CommunityPersonBanView, CommunityView};
 use lemmy_utils::error::LemmyError;
-use lemmy_websocket::LemmyContext;
 use serde::Serialize;
 use std::ops::Deref;
 use tracing::info;
@@ -31,6 +30,7 @@ pub mod community;
 pub mod create_or_update;
 pub mod deletion;
 pub mod following;
+pub mod unfederated;
 pub mod voting;
 
 /// Checks that the specified Url actually identifies a Person (by fetching it), and that the person
@@ -111,21 +111,23 @@ pub(crate) async fn verify_mod_action(
   Err(LemmyError::from_message("Not a mod"))
 }
 
-/// For Add/Remove community moderator activities, check that the target field actually contains
-/// /c/community/moderators. Any different values are unsupported.
-fn verify_add_remove_moderator_target(
-  target: &Url,
-  community: &ApubCommunity,
-) -> Result<(), LemmyError> {
-  if target != &generate_moderators_url(&community.actor_id)?.into() {
-    return Err(LemmyError::from_message("Unkown target url"));
+pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> Result<(), LemmyError> {
+  if ![to, cc].iter().any(|set| set.contains(&public())) {
+    return Err(LemmyError::from_message("Object is not public"));
   }
   Ok(())
 }
 
-pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> Result<(), LemmyError> {
-  if ![to, cc].iter().any(|set| set.contains(&public())) {
-    return Err(LemmyError::from_message("Object is not public"));
+pub(crate) fn verify_community_matches<T>(
+  a: &ObjectId<ApubCommunity>,
+  b: T,
+) -> Result<(), LemmyError>
+where
+  T: Into<ObjectId<ApubCommunity>>,
+{
+  let b: ObjectId<ApubCommunity> = b.into();
+  if a != &b {
+    return Err(LemmyError::from_message("Invalid community"));
   }
   Ok(())
 }