};
use lemmy_apub::{
objects::post::ApubPost,
- protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
+ protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
};
use lemmy_db_schema::{
source::{
ModLockPost::create(context.pool(), &form).await?;
// apub updates
- CreateOrUpdatePost::send(
+ CreateOrUpdatePage::send(
updated_post,
&local_user_view.person.clone().into(),
CreateOrUpdateType::Update,
};
use lemmy_apub::{
objects::post::ApubPost,
- protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
+ protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
};
use lemmy_db_schema::{
source::{
// Apub updates
// TODO stickied should pry work like locked for ease of use
- CreateOrUpdatePost::send(
+ CreateOrUpdatePage::send(
updated_post,
&local_user_view.person.clone().into(),
CreateOrUpdateType::Update,
use lemmy_apub::{
generate_local_apub_endpoint,
objects::comment::ApubComment,
- protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType},
+ protocol::activities::{create_or_update::note::CreateOrUpdateNote, CreateOrUpdateType},
EndpointType,
};
use lemmy_db_schema::{
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
let apub_comment: ApubComment = updated_comment.into();
- CreateOrUpdateComment::send(
+ CreateOrUpdateNote::send(
apub_comment.clone(),
&local_user_view.person.clone().into(),
CreateOrUpdateType::Create,
},
};
use lemmy_apub::protocol::activities::{
- create_or_update::comment::CreateOrUpdateComment,
+ create_or_update::note::CreateOrUpdateNote,
CreateOrUpdateType,
};
use lemmy_db_schema::{
.await?;
// Send the apub update
- CreateOrUpdateComment::send(
+ CreateOrUpdateNote::send(
updated_comment.into(),
&local_user_view.person.into(),
CreateOrUpdateType::Update,
use lemmy_apub::{
generate_local_apub_endpoint,
objects::post::ApubPost,
- protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
+ protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
EndpointType,
};
use lemmy_db_schema::{
}
let apub_post: ApubPost = updated_post.into();
- CreateOrUpdatePost::send(
+ CreateOrUpdatePage::send(
apub_post.clone(),
&local_user_view.person.clone().into(),
CreateOrUpdateType::Create,
},
};
use lemmy_apub::protocol::activities::{
- create_or_update::post::CreateOrUpdatePost,
+ create_or_update::page::CreateOrUpdatePage,
CreateOrUpdateType,
};
use lemmy_db_schema::{
};
// Send apub update
- CreateOrUpdatePost::send(
+ CreateOrUpdatePage::send(
updated_post.into(),
&local_user_view.person.clone().into(),
CreateOrUpdateType::Update,
use lemmy_apub::{
generate_local_apub_endpoint,
protocol::activities::{
- create_or_update::private_message::CreateOrUpdatePrivateMessage,
+ create_or_update::chat_message::CreateOrUpdateChatMessage,
CreateOrUpdateType,
},
EndpointType,
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_private_message"))?;
- CreateOrUpdatePrivateMessage::send(
+ CreateOrUpdateChatMessage::send(
updated_private_message.into(),
&local_user_view.person.into(),
CreateOrUpdateType::Create,
utils::{get_local_user_view_from_jwt, local_site_to_slur_regex},
};
use lemmy_apub::protocol::activities::{
- create_or_update::private_message::CreateOrUpdatePrivateMessage,
+ create_or_update::chat_message::CreateOrUpdateChatMessage,
CreateOrUpdateType,
};
use lemmy_db_schema::{
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
// Send the apub update
- CreateOrUpdatePrivateMessage::send(
+ CreateOrUpdateChatMessage::send(
updated_private_message.into(),
&local_user_view.person.into(),
CreateOrUpdateType::Update,
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"target": "http://enterprise.lemmy.ml/c/main",
"type": "Block",
"removeData": true,
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"target": "http://enterprise.lemmy.ml/c/main",
"type": "Block",
"removeData": true,
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"type": "Undo",
"id": "http://enterprise.lemmy.ml/activities/undo/06a20ffb-3e32-42fb-8f4c-674b36d7c557"
}
\ No newline at end of file
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"type": "Add",
"id": "http://enterprise.lemmy.ml/activities/add/ec069147-77c3-447f-88c8-0ef1df10403f"
}
\ No newline at end of file
],
"type": "Remove",
"target": "http://enterprise.lemmy.ml/c/main/moderators",
+ "audience": "http://enterprise.lemmy.ml/u/main",
"id": "http://enterprise.lemmy.ml/activities/remove/aab114f8-cfbd-4935-a5b7-e1a64603650d"
}
\ No newline at end of file
"to": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"object": "http://enterprise.lemmy.ml/post/7",
"summary": "report this post",
"type": "Flag",
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"type": "Update",
"id": "http://ds9.lemmy.ml/activities/update/d3717cf5-096d-473f-9530-5d52f9d51f5f"
}
\ No newline at end of file
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
+ "cc": [
+ "http://enterprise.lemmy.ml/c/main",
+ "http://ds9.lemmy.ml/u/lemmy_alpha"
+ ],
+ "audience": "http://ds9.lemmy.ml/u/lemmy_alpha",
"content": "hello",
"mediaType": "text/html",
"source": {
"http://enterprise.lemmy.ml/c/main",
"http://ds9.lemmy.ml/u/lemmy_alpha"
],
+ "audience": "http://ds9.lemmy.ml/u/lemmy_alpha",
"tag": [
{
"href": "http://ds9.lemmy.ml/u/lemmy_alpha",
"http://enterprise.lemmy.ml/c/main",
"https://www.w3.org/ns/activitystreams#Public"
],
+ "audience": "https://enterprise.lemmy.ml/c/main",
"name": "test post",
"content": "<p>test body</p>\n",
"mediaType": "text/html",
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "https://enterprise.lemmy.ml/c/main",
"type": "Create",
"id": "http://ds9.lemmy.ml/activities/create/eee6a57a-622f-464d-b560-73ae1fcd3ddf"
}
\ No newline at end of file
"http://enterprise.lemmy.ml/c/main",
"https://www.w3.org/ns/activitystreams#Public"
],
+ "audience": "https://enterprise.lemmy.ml/c/main",
"name": "test post 1",
"content": "<p>test body</p>\n",
"mediaType": "text/html",
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "https://enterprise.lemmy.ml/c/main",
"type": "Update",
"id": "http://ds9.lemmy.ml/activities/update/ab360117-e165-4de4-b7fc-906b62c98631"
}
\ No newline at end of file
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"type": "Delete",
"id": "http://ds9.lemmy.ml/activities/delete/f2abee48-c7bb-41d5-9e27-8775ff32db12"
}
\ No newline at end of file
"https://www.w3.org/ns/activitystreams#Public"
],
"object": "http://ds9.lemmy.ml/u/lemmy_alpha",
- "cc": [
- "http://enterprise.lemmy.ml/c/main"
- ],
"type": "Delete",
"id": "http://ds9.lemmy.ml/activities/delete/f2abee48-c7bb-41d5-9e27-8775ff32db12"
}
\ No newline at end of file
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"type": "Delete",
"summary": "bad comment",
"id": "http://enterprise.lemmy.ml/activities/delete/42ca1a79-f99e-4518-a2ca-ba2df221eb5e"
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"type": "Delete",
"id": "http://ds9.lemmy.ml/activities/delete/b13cca96-7737-41e1-9769-8fbf972b3509"
},
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"type": "Undo",
"id": "http://ds9.lemmy.ml/activities/undo/5e939cfb-b8a1-4de8-950f-9d684e9162b9"
}
\ No newline at end of file
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"type": "Delete",
"summary": "bad comment",
"id": "http://enterprise.lemmy.ml/activities/delete/2598435c-87a3-49cd-81f3-a44b03b7af9d"
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
+ "audience": "http://enterprise.lemmy.ml/u/main",
"type": "Undo",
"id": "http://enterprise.lemmy.ml/activities/undo/a850cf21-3866-4b3a-b80b-56aa00997fee"
}
\ No newline at end of file
{
"actor": "http://enterprise.lemmy.ml/u/lemmy_beta",
"object": "http://ds9.lemmy.ml/post/1",
+ "audience": "https://enterprise.lemmy.ml/c/tenforward",
"type": "Dislike",
"id": "http://enterprise.lemmy.ml/activities/dislike/64d40d40-a829-43a5-8247-1fb595b3ca1c"
}
\ No newline at end of file
{
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"object": "http://ds9.lemmy.ml/comment/1",
+ "audience": "https://enterprise.lemmy.ml/c/tenforward",
"type": "Like",
"id": "http://ds9.lemmy.ml/activities/like/fd61d070-7382-46a9-b2b7-6bb253732877"
}
\ No newline at end of file
"object": {
"actor": "http://enterprise.lemmy.ml/u/lemmy_beta",
"object": "http://ds9.lemmy.ml/post/1",
+ "audience": "https://enterprise.lemmy.ml/c/tenforward",
"type": "Like",
"id": "http://enterprise.lemmy.ml/activities/like/2227ab2c-79e2-4fca-a1d2-1d67dacf2457"
},
+ "audience": "https://enterprise.lemmy.ml/c/tenforward",
"type": "Undo",
"id": "http://enterprise.lemmy.ml/activities/undo/6cc6fb71-39fe-49ea-9506-f0423b101e98"
}
\ No newline at end of file
"object": {
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"object": "http://ds9.lemmy.ml/comment/1",
+ "audience": "https://enterprise.lemmy.ml/c/tenforward",
"type": "Like",
"id": "http://ds9.lemmy.ml/activities/like/efcf7ae2-dfcc-4ff4-9ce4-6adf251ff004"
},
+ "audience": "https://enterprise.lemmy.ml/c/tenforward",
"type": "Undo",
"id": "http://ds9.lemmy.ml/activities/undo/3518565c-24a7-4d9e-8e0a-f7a2f45ac618"
}
\ No newline at end of file
"https://enterprise.lemmy.ml/c/tenforward",
"https://enterprise.lemmy.ml/u/picard"
],
+ "audience": "https://enterprise.lemmy.ml/c/tenforward",
"inReplyTo": "https://enterprise.lemmy.ml/post/55143",
"content": "<p>first comment!</p>\n",
"mediaType": "text/html",
"https://enterprise.lemmy.ml/c/tenforward",
"https://www.w3.org/ns/activitystreams#Public"
],
+ "audience": "https://enterprise.lemmy.ml/c/tenforward",
"name": "Post title",
"content": "<p>This is a post in the /c/tenforward community</p>\n",
"mediaType": "text/html",
use crate::{
activities::{
block::{generate_cc, SiteOrCommunity},
- community::{announce::GetCommunity, send_activity_in_community},
+ community::send_activity_in_community,
generate_activity_id,
send_lemmy_activity,
verify_is_public,
},
activity_lists::AnnouncableActivities,
local_instance,
- objects::{community::ApubCommunity, instance::remote_instance_inboxes, person::ApubPerson},
+ objects::{instance::remote_instance_inboxes, person::ApubPerson},
protocol::activities::block::block_user::BlockUser,
ActorType,
};
expires: Option<NaiveDateTime>,
context: &LemmyContext,
) -> Result<BlockUser, LemmyError> {
+ let audience = if let SiteOrCommunity::Community(c) = target {
+ Some(ObjectId::new(c.actor_id()))
+ } else {
+ None
+ };
Ok(BlockUser {
actor: ObjectId::new(mod_.actor_id()),
to: vec![public()],
BlockType::Block,
&context.settings().get_protocol_and_hostname(),
)?,
+ audience,
expires: expires.map(convert_datetime),
})
}
Ok(())
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for BlockUser {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- let target = self
- .target
- .dereference(context, local_instance(context).await, request_counter)
- .await?;
- match target {
- SiteOrCommunity::Community(c) => Ok(c),
- SiteOrCommunity::Site(_) => Err(anyhow!("Calling get_community() on site activity").into()),
- }
- }
-}
use crate::{
activities::{
block::{generate_cc, SiteOrCommunity},
- community::{announce::GetCommunity, send_activity_in_community},
+ community::send_activity_in_community,
generate_activity_id,
send_lemmy_activity,
verify_is_public,
},
activity_lists::AnnouncableActivities,
local_instance,
- objects::{community::ApubCommunity, instance::remote_instance_inboxes, person::ApubPerson},
+ objects::{instance::remote_instance_inboxes, person::ApubPerson},
protocol::activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
ActorType,
};
context: &LemmyContext,
) -> Result<(), LemmyError> {
let block = BlockUser::new(target, user, mod_, None, reason, None, context).await?;
+ let audience = if let SiteOrCommunity::Community(c) = target {
+ Some(ObjectId::new(c.actor_id()))
+ } else {
+ None
+ };
let id = generate_activity_id(
UndoType::Undo,
cc: generate_cc(target, context.pool()).await?,
kind: UndoType::Undo,
id: id.clone(),
+ audience,
};
let mut inboxes = vec![user.shared_inbox_or_inbox()];
Ok(())
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for UndoBlockUser {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- self.object.get_community(context, request_counter).await
- }
-}
use crate::{
activities::{
- community::{
- announce::GetCommunity,
- get_community_from_moderators_url,
- send_activity_in_community,
- },
+ community::send_activity_in_community,
generate_activity_id,
verify_add_remove_moderator_target,
verify_is_public,
generate_moderators_url,
local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
- protocol::activities::community::add_mod::AddMod,
+ protocol::{activities::community::add_mod::AddMod, InCommunity},
ActorType,
};
use activitypub_federation::{
cc: vec![community.actor_id()],
kind: AddType::Add,
id: id.clone(),
+ audience: Some(ObjectId::new(community.actor_id())),
};
let activity = AnnouncableActivities::AddMod(add);
request_counter: &mut i32,
) -> Result<(), LemmyError> {
verify_is_public(&self.to, &self.cc)?;
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
verify_mod_action(
&self.actor,
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
let new_mod = self
.object
.dereference(context, local_instance(context).await, request_counter)
Ok(())
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for AddMod {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- get_community_from_moderators_url(&self.target, context, request_counter).await
- }
-}
activities::community::announce::{AnnounceActivity, RawAnnouncableActivities},
Id,
IdOrNestedObject,
+ InCommunity,
},
ActorType,
};
if let AnnouncableActivities::Page(_) = activity {
return Err(LemmyError::from_message("Cant receive page"));
}
- let community = activity.get_community(data, &mut 0).await?;
+ let community = activity.community(data, &mut 0).await?;
let actor_id = ObjectId::new(activity.actor().clone());
// verify and receive activity
}
}
-#[async_trait::async_trait(?Send)]
-pub(crate) trait GetCommunity {
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError>;
-}
-
impl AnnounceActivity {
pub(crate) fn new(
object: RawAnnouncableActivities,
}
#[tracing::instrument(skip_all)]
-async fn get_community_from_moderators_url(
+pub(crate) async fn get_community_from_moderators_url(
moderators: &Url,
context: &LemmyContext,
request_counter: &mut i32,
use crate::{
activities::{
- community::{
- announce::GetCommunity,
- get_community_from_moderators_url,
- send_activity_in_community,
- },
+ community::send_activity_in_community,
generate_activity_id,
verify_add_remove_moderator_target,
verify_is_public,
generate_moderators_url,
local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
- protocol::activities::community::remove_mod::RemoveMod,
+ protocol::{activities::community::remove_mod::RemoveMod, InCommunity},
ActorType,
};
use activitypub_federation::{
id: id.clone(),
cc: vec![community.actor_id()],
kind: RemoveType::Remove,
+ audience: Some(ObjectId::new(community.actor_id())),
};
let activity = AnnouncableActivities::RemoveMod(remove);
request_counter: &mut i32,
) -> Result<(), LemmyError> {
verify_is_public(&self.to, &self.cc)?;
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
verify_mod_action(
&self.actor,
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
let remove_mod = self
.object
.dereference(context, local_instance(context).await, request_counter)
Ok(())
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for RemoveMod {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- get_community_from_moderators_url(&self.target, context, request_counter).await
- }
-}
activities::{generate_activity_id, send_lemmy_activity, verify_person_in_community},
local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
- protocol::activities::community::report::Report,
+ protocol::{activities::community::report::Report, InCommunity},
ActorType,
PostOrComment,
};
summary: reason,
kind,
id: id.clone(),
+ audience: Some(ObjectId::new(community.actor_id())),
};
let inbox = vec![community.shared_inbox_or_inbox()];
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- let community = self.to[0]
- .dereference(context, local_instance(context).await, request_counter)
- .await?;
+ let community = self.community(context, request_counter).await?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
Ok(())
}
use crate::{
activities::{
- community::{announce::GetCommunity, send_activity_in_community},
+ community::send_activity_in_community,
generate_activity_id,
verify_is_public,
verify_mod_action,
verify_person_in_community,
},
activity_lists::AnnouncableActivities,
- local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
- protocol::activities::community::update::UpdateCommunity,
+ protocol::{activities::community::update::UpdateCommunity, InCommunity},
ActorType,
};
use activitypub_federation::{
cc: vec![community.actor_id()],
kind: UpdateType::Update,
id: id.clone(),
+ audience: Some(ObjectId::new(community.actor_id())),
};
let activity = AnnouncableActivities::UpdateCommunity(update);
request_counter: &mut i32,
) -> Result<(), LemmyError> {
verify_is_public(&self.to, &self.cc)?;
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
verify_mod_action(
&self.actor,
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
let community_update_form = self.object.into_update_form();
Ok(())
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for UpdateCommunity {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- let cid = ObjectId::new(self.object.id.clone());
- cid
- .dereference(context, local_instance(context).await, request_counter)
- .await
- }
-}
use crate::{
activities::{
check_community_deleted_or_removed,
- community::{announce::GetCommunity, send_activity_in_community},
+ community::send_activity_in_community,
create_or_update::get_comment_notif_recipients,
generate_activity_id,
verify_is_public,
local_instance,
mentions::MentionOrValue,
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
- protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType},
+ protocol::{
+ activities::{create_or_update::note::CreateOrUpdateNote, CreateOrUpdateType},
+ InCommunity,
+ },
ActorType,
};
use activitypub_federation::{
use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
use url::Url;
-impl CreateOrUpdateComment {
+impl CreateOrUpdateNote {
#[tracing::instrument(skip(comment, actor, kind, context))]
pub async fn send(
comment: ApubComment,
)?;
let note = comment.into_apub(context).await?;
- let create_or_update = CreateOrUpdateComment {
+ let create_or_update = CreateOrUpdateNote {
actor: ObjectId::new(actor.actor_id()),
to: vec![public()],
cc: note.cc.clone(),
object: note,
kind,
id: id.clone(),
+ audience: Some(ObjectId::new(community.actor_id())),
};
let tagged_users: Vec<ObjectId<ApubPerson>> = create_or_update
}
#[async_trait::async_trait(?Send)]
-impl ActivityHandler for CreateOrUpdateComment {
+impl ActivityHandler for CreateOrUpdateNote {
type DataType = LemmyContext;
type Error = LemmyError;
) -> Result<(), LemmyError> {
verify_is_public(&self.to, &self.cc)?;
let post = self.object.get_parents(context, request_counter).await?.0;
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
verify_domains_match(self.actor.inner(), self.object.id.inner())?;
Ok(())
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for CreateOrUpdateComment {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- let post = self.object.get_parents(context, request_counter).await?.0;
- let community = Community::read(context.pool(), post.community_id).await?;
- Ok(community.into())
- }
-}
use crate::{
activities::{
check_community_deleted_or_removed,
- community::{announce::GetCommunity, send_activity_in_community},
+ community::send_activity_in_community,
generate_activity_id,
verify_is_public,
verify_mod_action,
},
activity_lists::AnnouncableActivities,
objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
- protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
+ protocol::{
+ activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
+ InCommunity,
+ },
ActorType,
};
use activitypub_federation::{
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
use url::Url;
-impl CreateOrUpdatePost {
+impl CreateOrUpdatePage {
pub(crate) async fn new(
post: ApubPost,
actor: &ApubPerson,
community: &ApubCommunity,
kind: CreateOrUpdateType,
context: &LemmyContext,
- ) -> Result<CreateOrUpdatePost, LemmyError> {
+ ) -> Result<CreateOrUpdatePage, LemmyError> {
let id = generate_activity_id(
kind.clone(),
&context.settings().get_protocol_and_hostname(),
)?;
- Ok(CreateOrUpdatePost {
+ Ok(CreateOrUpdatePage {
actor: ObjectId::new(actor.actor_id()),
to: vec![public()],
object: post.into_apub(context).await?,
cc: vec![community.actor_id()],
kind,
id: id.clone(),
+ audience: Some(ObjectId::new(community.actor_id())),
})
}
let community_id = post.community_id;
let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
- let create_or_update = CreateOrUpdatePost::new(post, actor, &community, kind, context).await?;
+ let create_or_update = CreateOrUpdatePage::new(post, actor, &community, kind, context).await?;
let is_mod_action = create_or_update.object.is_mod_action(context).await?;
let activity = AnnouncableActivities::CreateOrUpdatePost(create_or_update);
send_activity_in_community(activity, actor, &community, vec![], is_mod_action, context).await?;
}
#[async_trait::async_trait(?Send)]
-impl ActivityHandler for CreateOrUpdatePost {
+impl ActivityHandler for CreateOrUpdatePage {
type DataType = LemmyContext;
type Error = LemmyError;
request_counter: &mut i32,
) -> Result<(), LemmyError> {
verify_is_public(&self.to, &self.cc)?;
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
check_community_deleted_or_removed(&community)?;
Ok(())
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for CreateOrUpdatePost {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- self
- .object
- .extract_community(context, request_counter)
- .await
- }
-}
activities::{generate_activity_id, send_lemmy_activity, verify_person},
objects::{person::ApubPerson, private_message::ApubPrivateMessage},
protocol::activities::{
- create_or_update::private_message::CreateOrUpdatePrivateMessage,
+ create_or_update::chat_message::CreateOrUpdateChatMessage,
CreateOrUpdateType,
},
ActorType,
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
use url::Url;
-impl CreateOrUpdatePrivateMessage {
+impl CreateOrUpdateChatMessage {
#[tracing::instrument(skip_all)]
pub async fn send(
private_message: ApubPrivateMessage,
kind.clone(),
&context.settings().get_protocol_and_hostname(),
)?;
- let create_or_update = CreateOrUpdatePrivateMessage {
+ let create_or_update = CreateOrUpdateChatMessage {
id: id.clone(),
actor: ObjectId::new(actor.actor_id()),
to: [ObjectId::new(recipient.actor_id())],
}
#[async_trait::async_trait(?Send)]
-impl ActivityHandler for CreateOrUpdatePrivateMessage {
+impl ActivityHandler for CreateOrUpdateChatMessage {
type DataType = LemmyContext;
type Error = LemmyError;
use crate::{
activities::{
- community::announce::GetCommunity,
deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
generate_activity_id,
},
};
use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
use activitystreams_kinds::activity::DeleteType;
-use anyhow::anyhow;
use lemmy_db_schema::{
source::{
comment::{Comment, CommentUpdateForm},
kind: DeleteType::Delete,
summary,
id,
+ audience: community.map(|c| ObjectId::<ApubCommunity>::new(c.actor_id.clone())),
})
}
}
}
Ok(())
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for Delete {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- _request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? {
- DeletableObjects::Community(c) => c.id,
- DeletableObjects::Comment(c) => {
- let post = Post::read(context.pool(), c.post_id).await?;
- post.community_id
- }
- DeletableObjects::Post(p) => p.community_id,
- DeletableObjects::PrivateMessage(_) => {
- return Err(anyhow!("Private message is not part of community").into())
- }
- };
- let community = Community::read(context.pool(), community_id).await?;
- Ok(community.into())
- }
-}
use crate::{
activities::{
- community::{announce::GetCommunity, send_activity_in_community},
+ community::send_activity_in_community,
send_lemmy_activity,
verify_is_public,
verify_mod_action,
post::ApubPost,
private_message::ApubPrivateMessage,
},
- protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
+ protocol::{
+ activities::deletion::{delete::Delete, undo_delete::UndoDelete},
+ InCommunity,
+ },
ActorType,
};
use activitypub_federation::{
verify_delete_post_or_comment(
&activity.actor,
&p.ap_id.clone().into(),
- &activity.get_community(context, request_counter).await?,
+ &activity.community(context, request_counter).await?,
is_mod_action,
context,
request_counter,
verify_delete_post_or_comment(
&activity.actor,
&c.ap_id.clone().into(),
- &activity.get_community(context, request_counter).await?,
+ &activity.community(context, request_counter).await?,
is_mod_action,
context,
request_counter,
use crate::{
activities::{
- community::announce::GetCommunity,
deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
generate_activity_id,
},
cc: cc.into_iter().collect(),
kind: UndoType::Undo,
id,
+ audience: community.map(|c| ObjectId::<ApubCommunity>::new(c.actor_id.clone())),
})
}
Ok(())
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for UndoDelete {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- self.object.get_community(context, request_counter).await
- }
-}
Ok(())
}
+pub(crate) fn verify_community_matches(
+ a: &ApubCommunity,
+ b: CommunityId,
+) -> Result<(), LemmyError> {
+ if a.id != b {
+ return Err(LemmyError::from_message("Invalid community"));
+ }
+ Ok(())
+}
+
pub(crate) fn check_community_deleted_or_removed(community: &Community) -> Result<(), LemmyError> {
if community.deleted || community.removed {
Err(LemmyError::from_message(
use crate::{
activities::{
- community::{announce::GetCommunity, send_activity_in_community},
+ community::send_activity_in_community,
generate_activity_id,
verify_person_in_community,
voting::{undo_vote_comment, undo_vote_post},
activity_lists::AnnouncableActivities,
local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
- protocol::activities::voting::{
- undo_vote::UndoVote,
- vote::{Vote, VoteType},
+ protocol::{
+ activities::voting::{
+ undo_vote::UndoVote,
+ vote::{Vote, VoteType},
+ },
+ InCommunity,
},
ActorType,
PostOrComment,
) -> Result<(), LemmyError> {
let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
- let object = Vote::new(object, actor, kind.clone(), context)?;
+ let object = Vote::new(object, actor, &community, kind.clone(), context)?;
let id = generate_activity_id(
UndoType::Undo,
&context.settings().get_protocol_and_hostname(),
object,
kind: UndoType::Undo,
id: id.clone(),
+ audience: Some(ObjectId::new(community.actor_id())),
};
let activity = AnnouncableActivities::UndoVote(undo_vote);
send_activity_in_community(activity, actor, &community, vec![], false, context).await
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
self.object.verify(context, request_counter).await?;
}
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for UndoVote {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- self.object.get_community(context, request_counter).await
- }
-}
use crate::{
activities::{
- community::{announce::GetCommunity, send_activity_in_community},
+ community::send_activity_in_community,
generate_activity_id,
verify_person_in_community,
voting::{vote_comment, vote_post},
activity_lists::AnnouncableActivities,
local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
- protocol::activities::voting::vote::{Vote, VoteType},
+ protocol::{
+ activities::voting::vote::{Vote, VoteType},
+ InCommunity,
+ },
ActorType,
PostOrComment,
};
use anyhow::anyhow;
use lemmy_db_schema::{
newtypes::CommunityId,
- source::{community::Community, local_site::LocalSite, post::Post},
+ source::{community::Community, local_site::LocalSite},
traits::Crud,
};
use lemmy_utils::error::LemmyError;
pub(in crate::activities::voting) fn new(
object: &PostOrComment,
actor: &ApubPerson,
+ community: &ApubCommunity,
kind: VoteType,
context: &LemmyContext,
) -> Result<Vote, LemmyError> {
object: ObjectId::new(object.ap_id()),
kind: kind.clone(),
id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?,
+ audience: Some(ObjectId::new(community.actor_id())),
})
}
context: &LemmyContext,
) -> Result<(), LemmyError> {
let community = Community::read(context.pool(), community_id).await?.into();
- let vote = Vote::new(object, actor, kind, context)?;
+ let vote = Vote::new(object, actor, &community, kind, context)?;
let activity = AnnouncableActivities::Vote(vote);
send_activity_in_community(activity, actor, &community, vec![], false, context).await
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- let community = self.get_community(context, request_counter).await?;
+ let community = self.community(context, request_counter).await?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
let enable_downvotes = LocalSite::read(context.pool())
.await
}
}
}
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for Vote {
- #[tracing::instrument(skip_all)]
- async fn get_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- let object = self
- .object
- .dereference(context, local_instance(context).await, request_counter)
- .await?;
- let cid = match object {
- PostOrComment::Post(p) => p.community_id,
- PostOrComment::Comment(c) => Post::read(context.pool(), c.post_id).await?.community_id,
- };
- let community = Community::read(context.pool(), cid).await?;
- Ok(community.into())
- }
-}
use crate::{
- activities::community::announce::GetCommunity,
objects::community::ApubCommunity,
protocol::{
activities::{
update::UpdateCommunity,
},
create_or_update::{
- comment::CreateOrUpdateComment,
- post::CreateOrUpdatePost,
- private_message::CreateOrUpdatePrivateMessage,
+ chat_message::CreateOrUpdateChatMessage,
+ note::CreateOrUpdateNote,
+ page::CreateOrUpdatePage,
},
deletion::{delete::Delete, delete_user::DeleteUser, undo_delete::UndoDelete},
following::{accept::AcceptFollow, follow::Follow, undo_follow::UndoFollow},
voting::{undo_vote::UndoVote, vote::Vote},
},
objects::page::Page,
+ InCommunity,
},
};
use activitypub_federation::{data::Data, deser::context::WithContext, traits::ActivityHandler};
pub enum PersonInboxActivities {
AcceptFollow(AcceptFollow),
UndoFollow(UndoFollow),
- FollowCommunity(Follow),
- CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
+ CreateOrUpdatePrivateMessage(CreateOrUpdateChatMessage),
Delete(Delete),
UndoDelete(UndoDelete),
AnnounceActivity(AnnounceActivity),
#[serde(untagged)]
#[enum_delegate::implement(ActivityHandler)]
pub enum AnnouncableActivities {
- CreateOrUpdateComment(CreateOrUpdateComment),
- CreateOrUpdatePost(CreateOrUpdatePost),
+ CreateOrUpdateComment(CreateOrUpdateNote),
+ CreateOrUpdatePost(CreateOrUpdatePage),
Vote(Vote),
UndoVote(UndoVote),
Delete(Delete),
}
#[async_trait::async_trait(?Send)]
-impl GetCommunity for AnnouncableActivities {
+impl InCommunity for AnnouncableActivities {
#[tracing::instrument(skip(self, context))]
- async fn get_community(
+ async fn community(
&self,
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<ApubCommunity, LemmyError> {
use AnnouncableActivities::*;
- let community = match self {
- CreateOrUpdateComment(a) => a.get_community(context, request_counter).await?,
- CreateOrUpdatePost(a) => a.get_community(context, request_counter).await?,
- Vote(a) => a.get_community(context, request_counter).await?,
- UndoVote(a) => a.get_community(context, request_counter).await?,
- Delete(a) => a.get_community(context, request_counter).await?,
- UndoDelete(a) => a.get_community(context, request_counter).await?,
- UpdateCommunity(a) => a.get_community(context, request_counter).await?,
- BlockUser(a) => a.get_community(context, request_counter).await?,
- UndoBlockUser(a) => a.get_community(context, request_counter).await?,
- AddMod(a) => a.get_community(context, request_counter).await?,
- RemoveMod(a) => a.get_community(context, request_counter).await?,
+ match self {
+ CreateOrUpdateComment(a) => a.community(context, request_counter).await,
+ CreateOrUpdatePost(a) => a.community(context, request_counter).await,
+ Vote(a) => a.community(context, request_counter).await,
+ UndoVote(a) => a.community(context, request_counter).await,
+ Delete(a) => a.community(context, request_counter).await,
+ UndoDelete(a) => a.community(context, request_counter).await,
+ UpdateCommunity(a) => a.community(context, request_counter).await,
+ BlockUser(a) => a.community(context, request_counter).await,
+ UndoBlockUser(a) => a.community(context, request_counter).await,
+ AddMod(a) => a.community(context, request_counter).await,
+ RemoveMod(a) => a.community(context, request_counter).await,
Page(_) => unimplemented!(),
- };
- Ok(community)
+ }
}
}
protocol::{
activities::{
community::announce::AnnounceActivity,
- create_or_update::post::CreateOrUpdatePost,
+ create_or_update::page::CreateOrUpdatePage,
CreateOrUpdateType,
},
collections::group_outbox::GroupOutbox,
for post in self.0 {
let person = Person::read(data.1.pool(), post.creator_id).await?.into();
let create =
- CreateOrUpdatePost::new(post, &person, &data.0, CreateOrUpdateType::Create, &data.1)
+ CreateOrUpdatePage::new(post, &person, &data.0, CreateOrUpdateType::Create, &data.1)
.await?;
let announcable = AnnouncableActivities::CreateOrUpdatePost(create);
let announce = AnnounceActivity::new(announcable.try_into()?, &data.0, &data.1)?;
use crate::{
- objects::{comment::ApubComment, post::ApubPost},
- protocol::objects::{note::Note, page::Page},
+ objects::{comment::ApubComment, community::ApubCommunity, post::ApubPost},
+ protocol::{
+ objects::{note::Note, page::Page},
+ InCommunity,
+ },
};
use activitypub_federation::traits::ApubObject;
use chrono::NaiveDateTime;
+use lemmy_db_schema::{
+ source::{community::Community, post::Post},
+ traits::Crud,
+};
use lemmy_utils::error::LemmyError;
use lemmy_websocket::LemmyContext;
use serde::Deserialize;
.into()
}
}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for PostOrComment {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ _: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let cid = match self {
+ PostOrComment::Post(p) => p.community_id,
+ PostOrComment::Comment(c) => Post::read(context.pool(), c.post_id).await?.community_id,
+ };
+ Ok(Community::read(context.pool(), cid).await?.into())
+ }
+}
objects::{read_from_string_or_source, verify_is_remote_object},
protocol::{
objects::{note::Note, LanguageTag},
+ InCommunity,
Source,
},
PostOrComment,
ObjectId::<PostOrComment>::new(post.ap_id)
};
let language = LanguageTag::new_single(self.language_id, context.pool()).await?;
- let maa =
- collect_non_local_mentions(&self, ObjectId::new(community.actor_id), context, &mut 0).await?;
+ let maa = collect_non_local_mentions(
+ &self,
+ ObjectId::new(community.actor_id.clone()),
+ context,
+ &mut 0,
+ )
+ .await?;
let note = Note {
r#type: NoteType::Note,
tag: maa.tags,
distinguished: Some(self.distinguished),
language,
+ audience: Some(ObjectId::new(community.actor_id)),
};
Ok(note)
verify_domains_match(note.id.inner(), expected_domain)?;
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
verify_is_public(¬e.to, ¬e.cc)?;
- let (post, _) = note.get_parents(context, request_counter).await?;
- let community_id = post.community_id;
- let community = Community::read(context.pool(), community_id).await?;
+ let community = note.community(context, request_counter).await?;
let local_site_data = fetch_local_site_data(context.pool()).await?;
check_apub_id_valid_with_strictness(
context.settings(),
)?;
verify_is_remote_object(note.id.inner(), context.settings())?;
- verify_person_in_community(
- ¬e.attributed_to,
- &community.into(),
- context,
- request_counter,
- )
- .await?;
+ verify_person_in_community(¬e.attributed_to, &community, context, request_counter).await?;
+ let (post, _) = note.get_parents(context, request_counter).await?;
if post.locked {
return Err(LemmyError::from_message("Post is locked"));
}
LanguageTag,
},
ImageObject,
+ InCommunity,
Source,
},
};
kind: PageType::Page,
id: ObjectId::new(self.ap_id.clone()),
attributed_to: AttributedTo::Lemmy(ObjectId::new(creator.actor_id)),
- to: vec![community.actor_id.into(), public()],
+ to: vec![community.actor_id.clone().into(), public()],
cc: vec![],
name: self.name.clone(),
content: self.body.as_ref().map(|b| markdown_to_html(b)),
language,
published: Some(convert_datetime(self.published)),
updated: self.updated.map(convert_datetime),
+ audience: Some(ObjectId::new(community.actor_id)),
};
Ok(page)
}
let local_site_data = fetch_local_site_data(context.pool()).await?;
- let community = page.extract_community(context, request_counter).await?;
+ let community = page.community(context, request_counter).await?;
check_apub_id_valid_with_strictness(
page.id.inner(),
community.local,
.creator()?
.dereference(context, local_instance(context).await, request_counter)
.await?;
- let community = page.extract_community(context, request_counter).await?;
+ let community = page.community(context, request_counter).await?;
let form = if !page.is_mod_action(context).await? {
let first_attachment = page.attachment.into_iter().map(Attachment::url).next();
-use crate::{activities::block::SiteOrCommunity, objects::person::ApubPerson};
+use crate::{
+ activities::{block::SiteOrCommunity, verify_community_matches},
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::InCommunity,
+};
use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
use activitystreams_kinds::activity::BlockType;
+use anyhow::anyhow;
use chrono::{DateTime, FixedOffset};
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
+use serde_with::skip_serializing_none;
use url::Url;
+#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct BlockUser {
#[serde(rename = "type")]
pub(crate) kind: BlockType,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
/// Quick and dirty solution.
/// TODO: send a separate Delete activity instead
pub(crate) summary: Option<String>,
pub(crate) expires: Option<DateTime<FixedOffset>>,
}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for BlockUser {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let target = self
+ .target
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ let target_community = match target {
+ SiteOrCommunity::Community(c) => c,
+ SiteOrCommunity::Site(_) => return Err(anyhow!("activity is not in community").into()),
+ };
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, target_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(target_community)
+ }
+ }
+}
-use crate::{objects::person::ApubPerson, protocol::activities::block::block_user::BlockUser};
+use crate::{
+ activities::verify_community_matches,
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::{activities::block::block_user::BlockUser, InCommunity},
+};
use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
use activitystreams_kinds::activity::UndoType;
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
+use serde_with::skip_serializing_none;
use url::Url;
+#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UndoBlockUser {
#[serde(rename = "type")]
pub(crate) kind: UndoType,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
+}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for UndoBlockUser {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let object_community = self.object.community(context, request_counter).await?;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, object_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(object_community)
+ }
+ }
}
-use crate::objects::person::ApubPerson;
+use crate::{
+ activities::{community::get_community_from_moderators_url, verify_community_matches},
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::InCommunity,
+};
use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
use activitystreams_kinds::activity::AddType;
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[serde(rename = "type")]
pub(crate) kind: AddType,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
+}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for AddMod {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let mod_community =
+ get_community_from_moderators_url(&self.target, context, request_counter).await?;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, mod_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(mod_community)
+ }
+ }
}
-use crate::objects::person::ApubPerson;
+use crate::{
+ activities::{community::get_community_from_moderators_url, verify_community_matches},
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::InCommunity,
+};
use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
use activitystreams_kinds::activity::RemoveType;
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
pub(crate) kind: RemoveType,
pub(crate) target: Url,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
+}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for RemoveMod {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let mod_community =
+ get_community_from_moderators_url(&self.target, context, request_counter).await?;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, mod_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(mod_community)
+ }
+ }
}
use crate::{
+ activities::verify_community_matches,
fetcher::post_or_comment::PostOrComment,
+ local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::InCommunity,
};
use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one};
use activitystreams_kinds::activity::FlagType;
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[serde(rename = "type")]
pub(crate) kind: FlagType,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
+}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for Report {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let to_community = self.to[0]
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, to_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(to_community)
+ }
+ }
}
-use crate::{objects::person::ApubPerson, protocol::objects::group::Group};
+use crate::{
+ activities::verify_community_matches,
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::{objects::group::Group, InCommunity},
+};
use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
use activitystreams_kinds::activity::UpdateType;
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[serde(rename = "type")]
pub(crate) kind: UpdateType,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
+}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for UpdateCommunity {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let object_community: ApubCommunity = ObjectId::new(self.object.id.clone())
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, object_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(object_community)
+ }
+ }
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
-pub struct CreateOrUpdatePrivateMessage {
+pub struct CreateOrUpdateChatMessage {
pub(crate) id: Url,
pub(crate) actor: ObjectId<ApubPerson>,
#[serde(deserialize_with = "deserialize_one")]
+++ /dev/null
-use crate::{
- mentions::MentionOrValue,
- objects::person::ApubPerson,
- protocol::{activities::CreateOrUpdateType, objects::note::Note},
-};
-use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct CreateOrUpdateComment {
- pub(crate) actor: ObjectId<ApubPerson>,
- #[serde(deserialize_with = "deserialize_one_or_many")]
- pub(crate) to: Vec<Url>,
- pub(crate) object: Note,
- #[serde(deserialize_with = "deserialize_one_or_many")]
- pub(crate) cc: Vec<Url>,
- #[serde(default)]
- pub(crate) tag: Vec<MentionOrValue>,
- #[serde(rename = "type")]
- pub(crate) kind: CreateOrUpdateType,
- pub(crate) id: Url,
-}
-pub mod comment;
-pub mod post;
-pub mod private_message;
+pub mod chat_message;
+pub mod note;
+pub mod page;
#[cfg(test)]
mod tests {
use crate::protocol::{
activities::create_or_update::{
- comment::CreateOrUpdateComment,
- post::CreateOrUpdatePost,
- private_message::CreateOrUpdatePrivateMessage,
+ chat_message::CreateOrUpdateChatMessage,
+ note::CreateOrUpdateNote,
+ page::CreateOrUpdatePage,
},
tests::test_parse_lemmy_item,
};
#[test]
fn test_parse_lemmy_create_or_update() {
- test_parse_lemmy_item::<CreateOrUpdatePost>(
+ test_parse_lemmy_item::<CreateOrUpdatePage>(
"assets/lemmy/activities/create_or_update/create_page.json",
)
.unwrap();
- test_parse_lemmy_item::<CreateOrUpdatePost>(
+ test_parse_lemmy_item::<CreateOrUpdatePage>(
"assets/lemmy/activities/create_or_update/update_page.json",
)
.unwrap();
- test_parse_lemmy_item::<CreateOrUpdateComment>(
+ test_parse_lemmy_item::<CreateOrUpdateNote>(
"assets/lemmy/activities/create_or_update/create_note.json",
)
.unwrap();
- test_parse_lemmy_item::<CreateOrUpdatePrivateMessage>(
+ test_parse_lemmy_item::<CreateOrUpdateChatMessage>(
"assets/lemmy/activities/create_or_update/create_private_message.json",
)
.unwrap();
--- /dev/null
+use crate::{
+ activities::verify_community_matches,
+ local_instance,
+ mentions::MentionOrValue,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::{activities::CreateOrUpdateType, objects::note::Note, InCommunity},
+};
+use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
+use lemmy_db_schema::{source::community::Community, traits::Crud};
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateOrUpdateNote {
+ pub(crate) actor: ObjectId<ApubPerson>,
+ #[serde(deserialize_with = "deserialize_one_or_many")]
+ pub(crate) to: Vec<Url>,
+ pub(crate) object: Note,
+ #[serde(deserialize_with = "deserialize_one_or_many")]
+ pub(crate) cc: Vec<Url>,
+ #[serde(default)]
+ pub(crate) tag: Vec<MentionOrValue>,
+ #[serde(rename = "type")]
+ pub(crate) kind: CreateOrUpdateType,
+ pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
+}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for CreateOrUpdateNote {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let post = self.object.get_parents(context, request_counter).await?.0;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, post.community_id)?;
+ Ok(audience)
+ } else {
+ let community = Community::read(context.pool(), post.community_id).await?;
+ Ok(community.into())
+ }
+ }
+}
--- /dev/null
+use crate::{
+ activities::verify_community_matches,
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::{activities::CreateOrUpdateType, objects::page::Page, InCommunity},
+};
+use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateOrUpdatePage {
+ pub(crate) actor: ObjectId<ApubPerson>,
+ #[serde(deserialize_with = "deserialize_one_or_many")]
+ pub(crate) to: Vec<Url>,
+ pub(crate) object: Page,
+ #[serde(deserialize_with = "deserialize_one_or_many")]
+ pub(crate) cc: Vec<Url>,
+ #[serde(rename = "type")]
+ pub(crate) kind: CreateOrUpdateType,
+ pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
+}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for CreateOrUpdatePage {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let object_community = self.object.community(context, request_counter).await?;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, object_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(object_community)
+ }
+ }
+}
+++ /dev/null
-use crate::{
- objects::person::ApubPerson,
- protocol::{activities::CreateOrUpdateType, objects::page::Page},
-};
-use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct CreateOrUpdatePost {
- pub(crate) actor: ObjectId<ApubPerson>,
- #[serde(deserialize_with = "deserialize_one_or_many")]
- pub(crate) to: Vec<Url>,
- pub(crate) object: Page,
- #[serde(deserialize_with = "deserialize_one_or_many")]
- pub(crate) cc: Vec<Url>,
- #[serde(rename = "type")]
- pub(crate) kind: CreateOrUpdateType,
- pub(crate) id: Url,
-}
use crate::{
- objects::person::ApubPerson,
- protocol::{objects::tombstone::Tombstone, IdOrNestedObject},
+ activities::{deletion::DeletableObjects, verify_community_matches},
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::{objects::tombstone::Tombstone, IdOrNestedObject, InCommunity},
};
use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
use activitystreams_kinds::activity::DeleteType;
+use anyhow::anyhow;
+use lemmy_db_schema::{
+ source::{community::Community, post::Post},
+ traits::Crud,
+};
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use url::Url;
#[serde(rename = "type")]
pub(crate) kind: DeleteType,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
#[serde(deserialize_with = "deserialize_one_or_many")]
#[serde(default)]
/// deleting their own content.
pub(crate) summary: Option<String>,
}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for Delete {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? {
+ DeletableObjects::Community(c) => c.id,
+ DeletableObjects::Comment(c) => {
+ let post = Post::read(context.pool(), c.post_id).await?;
+ post.community_id
+ }
+ DeletableObjects::Post(p) => p.community_id,
+ DeletableObjects::PrivateMessage(_) => {
+ return Err(anyhow!("Private message is not part of community").into())
+ }
+ };
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, community_id)?;
+ Ok(audience)
+ } else {
+ let community = Community::read(context.pool(), community_id).await?;
+ Ok(community.into())
+ }
+ }
+}
-use crate::{objects::person::ApubPerson, protocol::activities::deletion::delete::Delete};
+use crate::{
+ activities::verify_community_matches,
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::{activities::deletion::delete::Delete, InCommunity},
+};
use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
use activitystreams_kinds::activity::UndoType;
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
+use serde_with::skip_serializing_none;
use url::Url;
+#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UndoDelete {
#[serde(rename = "type")]
pub(crate) kind: UndoType,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
#[serde(deserialize_with = "deserialize_one_or_many", default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub(crate) cc: Vec<Url>,
}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for UndoDelete {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let object_community = self.object.community(context, request_counter).await?;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, object_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(object_community)
+ }
+ }
+}
use crate::protocol::{
activities::{
community::announce::AnnounceActivity,
- create_or_update::{comment::CreateOrUpdateComment, post::CreateOrUpdatePost},
+ create_or_update::{note::CreateOrUpdateNote, page::CreateOrUpdatePage},
deletion::delete::Delete,
following::{follow::Follow, undo_follow::UndoFollow},
voting::{undo_vote::UndoVote, vote::Vote},
#[test]
fn test_parse_smithereen_activities() {
- test_json::<CreateOrUpdateComment>("assets/smithereen/activities/create_note.json").unwrap();
+ test_json::<CreateOrUpdateNote>("assets/smithereen/activities/create_note.json").unwrap();
}
#[test]
fn test_parse_pleroma_activities() {
- test_json::<CreateOrUpdateComment>("assets/pleroma/activities/create_note.json").unwrap();
+ test_json::<CreateOrUpdateNote>("assets/pleroma/activities/create_note.json").unwrap();
test_json::<Delete>("assets/pleroma/activities/delete.json").unwrap();
test_json::<Follow>("assets/pleroma/activities/follow.json").unwrap();
}
#[test]
fn test_parse_mastodon_activities() {
- test_json::<CreateOrUpdateComment>("assets/mastodon/activities/create_note.json").unwrap();
+ test_json::<CreateOrUpdateNote>("assets/mastodon/activities/create_note.json").unwrap();
test_json::<Delete>("assets/mastodon/activities/delete.json").unwrap();
test_json::<Follow>("assets/mastodon/activities/follow.json").unwrap();
test_json::<UndoFollow>("assets/mastodon/activities/undo_follow.json").unwrap();
#[test]
fn test_parse_lotide_activities() {
- test_json::<CreateOrUpdatePost>("assets/lotide/activities/create_page.json").unwrap();
- test_json::<CreateOrUpdatePost>("assets/lotide/activities/create_page_image.json").unwrap();
- test_json::<CreateOrUpdateComment>("assets/lotide/activities/create_note_reply.json").unwrap();
+ test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page.json").unwrap();
+ test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page_image.json").unwrap();
+ test_json::<CreateOrUpdateNote>("assets/lotide/activities/create_note_reply.json").unwrap();
}
#[test]
fn test_parse_friendica_activities() {
- test_json::<CreateOrUpdatePost>("assets/friendica/activities/create_page_1.json").unwrap();
- test_json::<CreateOrUpdatePost>("assets/friendica/activities/create_page_2.json").unwrap();
- test_json::<CreateOrUpdateComment>("assets/friendica/activities/create_note.json").unwrap();
- test_json::<CreateOrUpdateComment>("assets/friendica/activities/update_note.json").unwrap();
+ test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_1.json").unwrap();
+ test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_2.json").unwrap();
+ test_json::<CreateOrUpdateNote>("assets/friendica/activities/create_note.json").unwrap();
+ test_json::<CreateOrUpdateNote>("assets/friendica/activities/update_note.json").unwrap();
test_json::<Delete>("assets/friendica/activities/delete.json").unwrap();
test_json::<Vote>("assets/friendica/activities/like_page.json").unwrap();
test_json::<Vote>("assets/friendica/activities/dislike_page.json").unwrap();
#[test]
fn test_parse_gnusocial_activities() {
- test_json::<CreateOrUpdatePost>("assets/gnusocial/activities/create_page.json").unwrap();
- test_json::<CreateOrUpdateComment>("assets/gnusocial/activities/create_note.json").unwrap();
+ test_json::<CreateOrUpdatePage>("assets/gnusocial/activities/create_page.json").unwrap();
+ test_json::<CreateOrUpdateNote>("assets/gnusocial/activities/create_note.json").unwrap();
test_json::<Vote>("assets/gnusocial/activities/like_note.json").unwrap();
}
-use crate::{objects::person::ApubPerson, protocol::activities::voting::vote::Vote};
+use crate::{
+ activities::verify_community_matches,
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::{activities::voting::vote::Vote, InCommunity},
+};
use activitypub_federation::core::object_id::ObjectId;
use activitystreams_kinds::activity::UndoType;
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[serde(rename = "type")]
pub(crate) kind: UndoType,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
+}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for UndoVote {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let local_instance = local_instance(context).await;
+ let object_community = self.object.community(context, request_counter).await?;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance, request_counter)
+ .await?;
+ verify_community_matches(&audience, object_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(object_community)
+ }
+ }
}
-use crate::{fetcher::post_or_comment::PostOrComment, objects::person::ApubPerson};
+use crate::{
+ activities::verify_community_matches,
+ fetcher::post_or_comment::PostOrComment,
+ local_instance,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::InCommunity,
+};
use activitypub_federation::core::object_id::ObjectId;
use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
use strum_macros::Display;
#[serde(rename = "type")]
pub(crate) kind: VoteType,
pub(crate) id: Url,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
}
#[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq, Eq)]
}
}
}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for Vote {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let local_instance = local_instance(context).await;
+ let object_community = self
+ .object
+ .dereference(context, local_instance, request_counter)
+ .await?
+ .community(context, request_counter)
+ .await?;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance, request_counter)
+ .await?;
+ verify_community_matches(&audience, object_community.id)?;
+ Ok(audience)
+ } else {
+ Ok(object_community)
+ }
+ }
+}
-use crate::local_instance;
+use crate::{local_instance, objects::community::ApubCommunity};
use activitypub_federation::{deser::values::MediaTypeMarkdown, utils::fetch_object_http};
use activitystreams_kinds::object::ImageType;
use lemmy_db_schema::newtypes::DbUrl;
}
}
+#[async_trait::async_trait(?Send)]
+pub trait InCommunity {
+ // TODO: after we use audience field and remove backwards compat, it should be possible to change
+ // this to simply `fn community(&self) -> Result<ObjectId<ApubCommunity>, LemmyError>`
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError>;
+}
+
#[cfg(test)]
pub(crate) mod tests {
use activitypub_federation::deser::context::WithContext;
use crate::{
+ activities::verify_community_matches,
fetcher::post_or_comment::PostOrComment,
local_instance,
mentions::MentionOrValue,
- objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
- protocol::{objects::LanguageTag, Source},
+ objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
+ protocol::{objects::LanguageTag, InCommunity, Source},
};
use activitypub_federation::{
core::object_id::ObjectId,
};
use activitystreams_kinds::object::NoteType;
use chrono::{DateTime, FixedOffset};
-use lemmy_db_schema::{source::post::Post, traits::Crud};
+use lemmy_db_schema::{
+ source::{community::Community, post::Post},
+ traits::Crud,
+};
use lemmy_utils::error::LemmyError;
use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
// lemmy extension
pub(crate) distinguished: Option<bool>,
pub(crate) language: Option<LanguageTag>,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
}
impl Note {
}
}
}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for Note {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let (post, _) = self.get_parents(context, request_counter).await?;
+ let community_id = post.community_id;
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, local_instance(context).await, request_counter)
+ .await?;
+ verify_community_matches(&audience, community_id)?;
+ Ok(audience)
+ } else {
+ Ok(Community::read(context.pool(), community_id).await?.into())
+ }
+ }
+}
use crate::{
+ activities::verify_community_matches,
fetcher::user_or_community::{PersonOrGroupType, UserOrCommunity},
local_instance,
objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
- protocol::{objects::LanguageTag, ImageObject, Source},
+ protocol::{objects::LanguageTag, ImageObject, InCommunity, Source},
};
use activitypub_federation::{
core::object_id::ObjectId,
pub(crate) published: Option<DateTime<FixedOffset>>,
pub(crate) updated: Option<DateTime<FixedOffset>>,
pub(crate) language: Option<LanguageTag>,
+ pub(crate) audience: Option<ObjectId<ApubCommunity>>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
false
}
- pub(crate) async fn extract_community(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubCommunity, LemmyError> {
- match &self.attributed_to {
- AttributedTo::Lemmy(_) => {
- let mut iter = self.to.iter().merge(self.cc.iter());
- loop {
- if let Some(cid) = iter.next() {
- let cid = ObjectId::new(cid.clone());
- if let Ok(c) = cid
- .dereference(context, local_instance(context).await, request_counter)
- .await
- {
- break Ok(c);
- }
- } else {
- return Err(LemmyError::from_message("No community found in cc"));
- }
- }
- }
- AttributedTo::Peertube(p) => {
- p.iter()
- .find(|a| a.kind == PersonOrGroupType::Group)
- .map(|a| ObjectId::<ApubCommunity>::new(a.id.clone().into_inner()))
- .ok_or_else(|| LemmyError::from_message("page does not specify group"))?
- .dereference(context, local_instance(context).await, request_counter)
- .await
- }
- }
- }
-
pub(crate) fn creator(&self) -> Result<ObjectId<ApubPerson>, LemmyError> {
match &self.attributed_to {
AttributedTo::Lemmy(l) => Ok(l.clone()),
Ok(())
}
}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for Page {
+ async fn community(
+ &self,
+ context: &LemmyContext,
+ request_counter: &mut i32,
+ ) -> Result<ApubCommunity, LemmyError> {
+ let instance = local_instance(context).await;
+ let community = match &self.attributed_to {
+ AttributedTo::Lemmy(_) => {
+ let mut iter = self.to.iter().merge(self.cc.iter());
+ loop {
+ if let Some(cid) = iter.next() {
+ let cid = ObjectId::new(cid.clone());
+ if let Ok(c) = cid.dereference(context, instance, request_counter).await {
+ break c;
+ }
+ } else {
+ return Err(LemmyError::from_message("No community found in cc"));
+ }
+ }
+ }
+ AttributedTo::Peertube(p) => {
+ p.iter()
+ .find(|a| a.kind == PersonOrGroupType::Group)
+ .map(|a| ObjectId::<ApubCommunity>::new(a.id.clone().into_inner()))
+ .ok_or_else(|| LemmyError::from_message("page does not specify group"))?
+ .dereference(context, instance, request_counter)
+ .await?
+ }
+ };
+ if let Some(audience) = &self.audience {
+ let audience = audience
+ .dereference(context, instance, request_counter)
+ .await?;
+ verify_community_matches(&audience, community.id)?;
+ Ok(audience)
+ } else {
+ Ok(community)
+ }
+ }
+}