2021-10-29 10:32:42 +00:00
|
|
|
use crate::{
|
2022-06-02 14:33:41 +00:00
|
|
|
activities::{community::announce::GetCommunity, verify_person_in_community},
|
2021-10-29 10:32:42 +00:00
|
|
|
objects::community::ApubCommunity,
|
2021-11-11 19:49:15 +00:00
|
|
|
protocol::{
|
|
|
|
activities::{
|
2022-02-07 19:23:12 +00:00
|
|
|
block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
|
2021-11-11 19:49:15 +00:00
|
|
|
community::{
|
|
|
|
add_mod::AddMod,
|
|
|
|
announce::AnnounceActivity,
|
|
|
|
remove_mod::RemoveMod,
|
|
|
|
report::Report,
|
|
|
|
update::UpdateCommunity,
|
|
|
|
},
|
2022-02-14 15:14:24 +00:00
|
|
|
create_or_update::{
|
|
|
|
comment::CreateOrUpdateComment,
|
|
|
|
post::CreateOrUpdatePost,
|
|
|
|
private_message::CreateOrUpdatePrivateMessage,
|
|
|
|
},
|
2022-04-07 20:52:17 +00:00
|
|
|
deletion::{delete::Delete, delete_user::DeleteUser, undo_delete::UndoDelete},
|
2021-11-11 19:49:15 +00:00
|
|
|
following::{
|
|
|
|
accept::AcceptFollowCommunity,
|
|
|
|
follow::FollowCommunity,
|
|
|
|
undo_follow::UndoFollowCommunity,
|
|
|
|
},
|
|
|
|
voting::{undo_vote::UndoVote, vote::Vote},
|
2021-10-29 10:32:42 +00:00
|
|
|
},
|
2021-11-18 15:20:35 +00:00
|
|
|
objects::page::Page,
|
2022-05-06 23:53:33 +00:00
|
|
|
Id,
|
2021-10-29 10:32:42 +00:00
|
|
|
},
|
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{
|
|
|
|
core::object_id::ObjectId,
|
|
|
|
data::Data,
|
|
|
|
deser::context::WithContext,
|
|
|
|
traits::{activity_handler, ActivityHandler},
|
|
|
|
};
|
|
|
|
use lemmy_utils::error::LemmyError;
|
2021-11-01 13:05:20 +00:00
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
use serde::{Deserialize, Serialize};
|
2022-05-06 23:53:33 +00:00
|
|
|
use url::Url;
|
2021-10-29 10:32:42 +00:00
|
|
|
|
2022-06-02 14:33:41 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
2021-10-29 10:32:42 +00:00
|
|
|
#[serde(untagged)]
|
2022-06-02 14:33:41 +00:00
|
|
|
#[activity_handler(LemmyContext, LemmyError)]
|
2021-10-29 10:32:42 +00:00
|
|
|
pub enum SharedInboxActivities {
|
2022-06-02 14:33:41 +00:00
|
|
|
GroupInboxActivities(Box<WithContext<GroupInboxActivities>>),
|
2021-10-29 10:32:42 +00:00
|
|
|
// Note, pm activities need to be at the end, otherwise comments will end up here. We can probably
|
|
|
|
// avoid this problem by replacing createpm.object with our own struct, instead of NoteExt.
|
2022-06-02 14:33:41 +00:00
|
|
|
PersonInboxActivities(Box<WithContext<PersonInboxActivities>>),
|
2021-10-29 10:32:42 +00:00
|
|
|
}
|
|
|
|
|
2022-06-02 14:33:41 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
2021-10-29 10:32:42 +00:00
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum GroupInboxActivities {
|
|
|
|
FollowCommunity(FollowCommunity),
|
|
|
|
UndoFollowCommunity(UndoFollowCommunity),
|
2021-11-06 13:25:34 +00:00
|
|
|
AnnouncableActivities(Box<AnnouncableActivities>),
|
2021-10-29 10:32:42 +00:00
|
|
|
Report(Report),
|
|
|
|
}
|
|
|
|
|
2022-06-02 14:33:41 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2021-10-29 10:32:42 +00:00
|
|
|
#[serde(untagged)]
|
2022-06-02 14:33:41 +00:00
|
|
|
#[activity_handler(LemmyContext, LemmyError)]
|
2021-10-29 10:32:42 +00:00
|
|
|
pub enum PersonInboxActivities {
|
|
|
|
AcceptFollowCommunity(AcceptFollowCommunity),
|
|
|
|
/// Some activities can also be sent from user to user, eg a comment with mentions
|
|
|
|
AnnouncableActivities(AnnouncableActivities),
|
|
|
|
CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
|
2022-02-14 15:14:24 +00:00
|
|
|
Delete(Delete),
|
|
|
|
UndoDelete(UndoDelete),
|
2021-11-06 13:25:34 +00:00
|
|
|
AnnounceActivity(AnnounceActivity),
|
2021-10-29 10:32:42 +00:00
|
|
|
}
|
|
|
|
|
2022-06-02 14:33:41 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2021-10-29 10:32:42 +00:00
|
|
|
#[serde(untagged)]
|
2022-06-02 14:33:41 +00:00
|
|
|
#[activity_handler(LemmyContext, LemmyError)]
|
2021-10-29 10:32:42 +00:00
|
|
|
pub enum AnnouncableActivities {
|
|
|
|
CreateOrUpdateComment(CreateOrUpdateComment),
|
2022-04-01 18:25:19 +00:00
|
|
|
CreateOrUpdatePost(Box<CreateOrUpdatePost>),
|
2021-10-29 10:32:42 +00:00
|
|
|
Vote(Vote),
|
|
|
|
UndoVote(UndoVote),
|
|
|
|
Delete(Delete),
|
|
|
|
UndoDelete(UndoDelete),
|
2021-11-06 13:25:34 +00:00
|
|
|
UpdateCommunity(UpdateCommunity),
|
2022-02-07 19:23:12 +00:00
|
|
|
BlockUser(BlockUser),
|
|
|
|
UndoBlockUser(UndoBlockUser),
|
2021-10-29 10:32:42 +00:00
|
|
|
AddMod(AddMod),
|
|
|
|
RemoveMod(RemoveMod),
|
2021-11-11 19:49:15 +00:00
|
|
|
// For compatibility with Pleroma/Mastodon (send only)
|
|
|
|
Page(Page),
|
2021-10-29 10:32:42 +00:00
|
|
|
}
|
|
|
|
|
2022-06-02 14:33:41 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2022-02-07 19:23:12 +00:00
|
|
|
#[serde(untagged)]
|
2022-06-02 14:33:41 +00:00
|
|
|
#[activity_handler(LemmyContext, LemmyError)]
|
2022-04-07 20:52:17 +00:00
|
|
|
#[allow(clippy::enum_variant_names)]
|
2022-02-07 19:23:12 +00:00
|
|
|
pub enum SiteInboxActivities {
|
|
|
|
BlockUser(BlockUser),
|
|
|
|
UndoBlockUser(UndoBlockUser),
|
2022-04-07 20:52:17 +00:00
|
|
|
DeleteUser(DeleteUser),
|
2022-02-07 19:23:12 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 10:32:42 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl GetCommunity for AnnouncableActivities {
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip(self, context))]
|
2021-10-29 10:32:42 +00:00
|
|
|
async fn get_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?,
|
2022-02-07 19:23:12 +00:00
|
|
|
BlockUser(a) => a.get_community(context, request_counter).await?,
|
|
|
|
UndoBlockUser(a) => a.get_community(context, request_counter).await?,
|
2021-10-29 10:32:42 +00:00
|
|
|
AddMod(a) => a.get_community(context, request_counter).await?,
|
|
|
|
RemoveMod(a) => a.get_community(context, request_counter).await?,
|
2021-11-11 19:49:15 +00:00
|
|
|
Page(_) => unimplemented!(),
|
2021-10-29 10:32:42 +00:00
|
|
|
};
|
|
|
|
Ok(community)
|
|
|
|
}
|
|
|
|
}
|
2022-05-06 23:53:33 +00:00
|
|
|
|
|
|
|
impl Id for AnnouncableActivities {
|
2022-06-02 14:33:41 +00:00
|
|
|
fn object_id(&self) -> &Url {
|
|
|
|
ActivityHandler::id(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need to implement this manually to announce matching activities
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl ActivityHandler for GroupInboxActivities {
|
|
|
|
type DataType = LemmyContext;
|
|
|
|
type Error = LemmyError;
|
|
|
|
|
2022-05-06 23:53:33 +00:00
|
|
|
fn id(&self) -> &Url {
|
|
|
|
match self {
|
2022-06-02 14:33:41 +00:00
|
|
|
GroupInboxActivities::FollowCommunity(a) => a.id(),
|
|
|
|
GroupInboxActivities::UndoFollowCommunity(a) => a.id(),
|
|
|
|
GroupInboxActivities::AnnouncableActivities(a) => a.object_id(),
|
|
|
|
GroupInboxActivities::Report(a) => a.id(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn actor(&self) -> &Url {
|
|
|
|
match self {
|
|
|
|
GroupInboxActivities::FollowCommunity(a) => a.actor(),
|
|
|
|
GroupInboxActivities::UndoFollowCommunity(a) => a.actor(),
|
|
|
|
GroupInboxActivities::AnnouncableActivities(a) => a.actor(),
|
|
|
|
GroupInboxActivities::Report(a) => a.actor(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn verify(
|
|
|
|
&self,
|
|
|
|
data: &Data<Self::DataType>,
|
|
|
|
request_counter: &mut i32,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
match self {
|
|
|
|
GroupInboxActivities::FollowCommunity(a) => a.verify(data, request_counter).await,
|
|
|
|
GroupInboxActivities::UndoFollowCommunity(a) => a.verify(data, request_counter).await,
|
|
|
|
GroupInboxActivities::AnnouncableActivities(a) => a.verify(data, request_counter).await,
|
|
|
|
GroupInboxActivities::Report(a) => a.verify(data, request_counter).await,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn receive(
|
|
|
|
self,
|
|
|
|
data: &Data<Self::DataType>,
|
|
|
|
request_counter: &mut i32,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
match self {
|
|
|
|
GroupInboxActivities::FollowCommunity(a) => a.receive(data, request_counter).await,
|
|
|
|
GroupInboxActivities::UndoFollowCommunity(a) => a.receive(data, request_counter).await,
|
|
|
|
GroupInboxActivities::AnnouncableActivities(activity) => {
|
|
|
|
activity.clone().receive(data, request_counter).await?;
|
|
|
|
|
|
|
|
// Ignore failures in get_community(). those happen because Delete/PrivateMessage is not in a
|
|
|
|
// community, but looks identical to Delete/Post or Delete/Comment which are in a community.
|
|
|
|
let community = activity.get_community(data, &mut 0).await;
|
|
|
|
if let Ok(community) = community {
|
|
|
|
if community.local {
|
|
|
|
let actor_id = ObjectId::new(activity.actor().clone());
|
|
|
|
verify_person_in_community(&actor_id, &community, data, &mut 0).await?;
|
|
|
|
AnnounceActivity::send(*activity, &community, data).await?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
GroupInboxActivities::Report(a) => a.receive(data, request_counter).await,
|
2022-05-06 23:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|