Move activity structs to protocol folder

This commit is contained in:
Felix Ableitner 2021-10-29 12:32:42 +02:00
parent 5ff044346f
commit 03d8ac75ef
71 changed files with 910 additions and 751 deletions

View file

@ -1,5 +1,7 @@
use crate::Perform; use std::convert::TryInto;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -9,11 +11,11 @@ use lemmy_api_common::{
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
}; };
use lemmy_apub::{ use lemmy_apub::{
activities::voting::{ fetcher::post_or_comment::PostOrComment,
protocol::activities::voting::{
undo_vote::UndoVote, undo_vote::UndoVote,
vote::{Vote, VoteType}, vote::{Vote, VoteType},
}, },
fetcher::post_or_comment::PostOrComment,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::LocalUserId, newtypes::LocalUserId,
@ -23,7 +25,8 @@ use lemmy_db_schema::{
use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView}; use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView};
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation}; use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation};
use std::convert::TryInto;
use crate::Perform;
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl Perform for MarkCommentAsRead { impl Perform for MarkCommentAsRead {

View file

@ -1,5 +1,5 @@
use crate::Perform;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -7,7 +7,7 @@ use lemmy_api_common::{
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
is_mod_or_admin, is_mod_or_admin,
}; };
use lemmy_apub::{activities::report::Report, fetcher::object_id::ObjectId}; use lemmy_apub::{fetcher::object_id::ObjectId, protocol::activities::community::report::Report};
use lemmy_db_schema::{source::comment_report::*, traits::Reportable}; use lemmy_db_schema::{source::comment_report::*, traits::Reportable};
use lemmy_db_views::{ use lemmy_db_views::{
comment_report_view::{CommentReportQueryBuilder, CommentReportView}, comment_report_view::{CommentReportQueryBuilder, CommentReportView},
@ -16,6 +16,8 @@ use lemmy_db_views::{
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
use crate::Perform;
/// Creates a comment report and notifies the moderators of the community /// Creates a comment report and notifies the moderators of the community
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl Perform for CreateCommentReport { impl Perform for CreateCommentReport {

View file

@ -10,16 +10,16 @@ use lemmy_api_common::{
is_mod_or_admin, is_mod_or_admin,
}; };
use lemmy_apub::{ use lemmy_apub::{
activities::{ objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::{
community::{ community::{
add_mod::AddMod, add_mod::AddMod,
block_user::BlockUserFromCommunity, block_user::BlockUserFromCommunity,
remove_mod::RemoveMod, remove_mod::RemoveMod,
undo_block_user::UndoBlockUserFromCommunity, undo_block_user::UndoBlockUserFromCommunity,
}, },
following::{follow::FollowCommunity as FollowCommunityApub, undo::UndoFollowCommunity}, following::{follow::FollowCommunity as FollowCommunityApub, undo_follow::UndoFollowCommunity},
}, },
objects::{community::ApubCommunity, person::ApubPerson},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{

View file

@ -12,16 +12,16 @@ use lemmy_api_common::{
post::*, post::*,
}; };
use lemmy_apub::{ use lemmy_apub::{
activities::{ fetcher::post_or_comment::PostOrComment,
post::create_or_update::CreateOrUpdatePost, objects::post::ApubPost,
protocol::activities::{
create_or_update::post::CreateOrUpdatePost,
voting::{ voting::{
undo_vote::UndoVote, undo_vote::UndoVote,
vote::{Vote, VoteType}, vote::{Vote, VoteType},
}, },
CreateOrUpdateType, CreateOrUpdateType,
}, },
fetcher::post_or_comment::PostOrComment,
objects::post::ApubPost,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{moderator::*, post::*}, source::{moderator::*, post::*},

View file

@ -1,5 +1,5 @@
use crate::Perform;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -13,7 +13,7 @@ use lemmy_api_common::{
ResolvePostReport, ResolvePostReport,
}, },
}; };
use lemmy_apub::{activities::report::Report, fetcher::object_id::ObjectId}; use lemmy_apub::{fetcher::object_id::ObjectId, protocol::activities::community::report::Report};
use lemmy_db_schema::{ use lemmy_db_schema::{
source::post_report::{PostReport, PostReportForm}, source::post_report::{PostReport, PostReportForm},
traits::Reportable, traits::Reportable,
@ -25,6 +25,8 @@ use lemmy_db_views::{
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
use crate::Perform;
/// Creates a post report and notifies the moderators of the community /// Creates a post report and notifies the moderators of the community
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl Perform for CreatePostReport { impl Perform for CreatePostReport {

View file

@ -1,5 +1,5 @@
use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -11,13 +11,13 @@ use lemmy_api_common::{
get_post, get_post,
}; };
use lemmy_apub::{ use lemmy_apub::{
activities::{ fetcher::post_or_comment::PostOrComment,
comment::create_or_update::CreateOrUpdateComment, generate_local_apub_endpoint,
protocol::activities::{
create_or_update::comment::CreateOrUpdateComment,
voting::vote::{Vote, VoteType}, voting::vote::{Vote, VoteType},
CreateOrUpdateType, CreateOrUpdateType,
}, },
fetcher::post_or_comment::PostOrComment,
generate_local_apub_endpoint,
EndpointType, EndpointType,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -40,6 +40,8 @@ use lemmy_websocket::{
UserOperationCrud, UserOperationCrud,
}; };
use crate::PerformCrud;
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for CreateComment { impl PerformCrud for CreateComment {
type Response = CommentResponse; type Response = CommentResponse;

View file

@ -1,5 +1,5 @@
use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -8,8 +8,8 @@ use lemmy_api_common::{
comment::*, comment::*,
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
}; };
use lemmy_apub::activities::{ use lemmy_apub::protocol::activities::{
comment::create_or_update::CreateOrUpdateComment, create_or_update::comment::CreateOrUpdateComment,
CreateOrUpdateType, CreateOrUpdateType,
}; };
use lemmy_db_schema::source::comment::Comment; use lemmy_db_schema::source::comment::Comment;
@ -26,6 +26,8 @@ use lemmy_websocket::{
UserOperationCrud, UserOperationCrud,
}; };
use crate::PerformCrud;
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for EditComment { impl PerformCrud for EditComment {
type Response = CommentResponse; type Response = CommentResponse;

View file

@ -5,7 +5,7 @@ use lemmy_api_common::{
community::{CommunityResponse, EditCommunity}, community::{CommunityResponse, EditCommunity},
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
}; };
use lemmy_apub::activities::community::update::UpdateCommunity; use lemmy_apub::protocol::activities::community::update::UpdateCommunity;
use lemmy_db_schema::{ use lemmy_db_schema::{
diesel_option_overwrite_to_url, diesel_option_overwrite_to_url,
naive_now, naive_now,

View file

@ -1,5 +1,7 @@
use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use log::warn;
use webmention::{Webmention, WebmentionError};
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -10,13 +12,13 @@ use lemmy_api_common::{
post::*, post::*,
}; };
use lemmy_apub::{ use lemmy_apub::{
activities::{ fetcher::post_or_comment::PostOrComment,
post::create_or_update::CreateOrUpdatePost, generate_local_apub_endpoint,
protocol::activities::{
create_or_update::post::CreateOrUpdatePost,
voting::vote::{Vote, VoteType}, voting::vote::{Vote, VoteType},
CreateOrUpdateType, CreateOrUpdateType,
}, },
fetcher::post_or_comment::PostOrComment,
generate_local_apub_endpoint,
EndpointType, EndpointType,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -31,8 +33,8 @@ use lemmy_utils::{
LemmyError, LemmyError,
}; };
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
use log::warn;
use webmention::{Webmention, WebmentionError}; use crate::PerformCrud;
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for CreatePost { impl PerformCrud for CreatePost {

View file

@ -1,5 +1,5 @@
use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -7,7 +7,10 @@ use lemmy_api_common::{
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
post::*, post::*,
}; };
use lemmy_apub::activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType}; use lemmy_apub::protocol::activities::{
create_or_update::post::CreateOrUpdatePost,
CreateOrUpdateType,
};
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
source::post::{Post, PostForm}, source::post::{Post, PostForm},
@ -22,6 +25,8 @@ use lemmy_utils::{
}; };
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
use crate::PerformCrud;
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for EditPost { impl PerformCrud for EditPost {
type Response = PostResponse; type Response = PostResponse;

View file

@ -7,11 +7,11 @@ use lemmy_api_common::{
person::{CreatePrivateMessage, PrivateMessageResponse}, person::{CreatePrivateMessage, PrivateMessageResponse},
}; };
use lemmy_apub::{ use lemmy_apub::{
activities::{ generate_local_apub_endpoint,
protocol::activities::{
private_message::create_or_update::CreateOrUpdatePrivateMessage, private_message::create_or_update::CreateOrUpdatePrivateMessage,
CreateOrUpdateType, CreateOrUpdateType,
}, },
generate_local_apub_endpoint,
EndpointType, EndpointType,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View file

@ -5,7 +5,7 @@ use lemmy_api_common::{
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
person::{DeletePrivateMessage, PrivateMessageResponse}, person::{DeletePrivateMessage, PrivateMessageResponse},
}; };
use lemmy_apub::activities::private_message::{ use lemmy_apub::protocol::activities::private_message::{
delete::DeletePrivateMessage as DeletePrivateMessageApub, delete::DeletePrivateMessage as DeletePrivateMessageApub,
undo_delete::UndoDeletePrivateMessage, undo_delete::UndoDeletePrivateMessage,
}; };

View file

@ -5,7 +5,7 @@ use lemmy_api_common::{
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
person::{EditPrivateMessage, PrivateMessageResponse}, person::{EditPrivateMessage, PrivateMessageResponse},
}; };
use lemmy_apub::activities::{ use lemmy_apub::protocol::activities::{
private_message::create_or_update::CreateOrUpdatePrivateMessage, private_message::create_or_update::CreateOrUpdatePrivateMessage,
CreateOrUpdateType, CreateOrUpdateType,
}; };

View file

@ -1,11 +1,9 @@
use activitystreams::{link::Mention, public, unparsed::Unparsed}; use activitystreams::public;
use serde::{Deserialize, Serialize};
use url::Url;
use lemmy_api_common::{blocking, check_post_deleted_or_removed}; use lemmy_api_common::{blocking, check_post_deleted_or_removed};
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType, ApubObject}, traits::{ActivityHandler, ActorType, ApubObject},
verify::verify_domains_match, verify::verify_domains_match,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -19,37 +17,18 @@ use crate::{
activities::{ activities::{
check_community_deleted_or_removed, check_community_deleted_or_removed,
comment::{collect_non_local_mentions, get_notif_recipients}, comment::{collect_non_local_mentions, get_notif_recipients},
community::{ community::{announce::GetCommunity, send_to_community},
announce::{AnnouncableActivities, GetCommunity},
send_to_community,
},
generate_activity_id, generate_activity_id,
verify_activity, verify_activity,
verify_is_public, verify_is_public,
verify_person_in_community, verify_person_in_community,
CreateOrUpdateType,
}, },
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson}, objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
protocol::objects::note::Note, protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType},
}; };
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrUpdateComment {
actor: ObjectId<ApubPerson>,
to: Vec<Url>,
object: Note,
cc: Vec<Url>,
#[serde(default)]
tag: Vec<Mention>,
#[serde(rename = "type")]
kind: CreateOrUpdateType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl CreateOrUpdateComment { impl CreateOrUpdateComment {
pub async fn send( pub async fn send(
comment: &ApubComment, comment: &ApubComment,

View file

@ -1,10 +1,6 @@
use crate::{ use crate::{
activities::{ activities::{
community::{ community::{announce::GetCommunity, get_community_from_moderators_url, send_to_community},
announce::{AnnouncableActivities, GetCommunity},
get_community_from_moderators_url,
send_to_community,
},
generate_activity_id, generate_activity_id,
verify_activity, verify_activity,
verify_add_remove_moderator_target, verify_add_remove_moderator_target,
@ -12,15 +8,17 @@ use crate::{
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::add_mod::AddMod,
}; };
use activitystreams::{activity::kind::AddType, public, unparsed::Unparsed}; use activitystreams::{activity::kind::AddType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::community::{CommunityModerator, CommunityModeratorForm}, source::community::{CommunityModerator, CommunityModeratorForm},
@ -28,23 +26,6 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct AddMod {
actor: ObjectId<ApubPerson>,
to: Vec<Url>,
object: ObjectId<ApubPerson>,
target: Url,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: AddType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl AddMod { impl AddMod {
pub async fn send( pub async fn send(

View file

@ -1,55 +1,27 @@
use crate::{ use crate::{
activities::{ activities::{
comment::create_or_update::CreateOrUpdateComment, community::list_community_follower_inboxes,
community::{
add_mod::AddMod,
block_user::BlockUserFromCommunity,
list_community_follower_inboxes,
remove_mod::RemoveMod,
undo_block_user::UndoBlockUserFromCommunity,
update::UpdateCommunity,
},
deletion::{delete::Delete, undo_delete::UndoDelete},
generate_activity_id, generate_activity_id,
post::create_or_update::CreateOrUpdatePost,
send_lemmy_activity, send_lemmy_activity,
verify_activity, verify_activity,
verify_is_public, verify_is_public,
voting::{undo_vote::UndoVote, vote::Vote},
}, },
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
http::is_activity_already_known, http::is_activity_already_known,
insert_activity, insert_activity,
objects::community::ApubCommunity, objects::community::ApubCommunity,
protocol::activities::community::announce::AnnounceActivity,
}; };
use activitystreams::{activity::kind::AnnounceType, public, unparsed::Unparsed}; use activitystreams::{activity::kind::AnnounceType, public};
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityFields, ActivityHandler, ActorType},
verify::verify_urls_match,
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url; use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum AnnouncableActivities {
CreateOrUpdateComment(CreateOrUpdateComment),
CreateOrUpdatePost(Box<CreateOrUpdatePost>),
Vote(Vote),
UndoVote(UndoVote),
Delete(Delete),
UndoDelete(UndoDelete),
UpdateCommunity(Box<UpdateCommunity>),
BlockUserFromCommunity(BlockUserFromCommunity),
UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
AddMod(AddMod),
RemoveMod(RemoveMod),
}
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
pub(crate) trait GetCommunity { pub(crate) trait GetCommunity {
async fn get_community( async fn get_community(
@ -59,46 +31,6 @@ pub(crate) trait GetCommunity {
) -> Result<ApubCommunity, LemmyError>; ) -> Result<ApubCommunity, LemmyError>;
} }
#[async_trait::async_trait(?Send)]
impl GetCommunity for AnnouncableActivities {
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?,
BlockUserFromCommunity(a) => a.get_community(context, request_counter).await?,
UndoBlockUserFromCommunity(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?,
};
verify_urls_match(self.actor(), &community.actor_id())?;
Ok(community)
}
}
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct AnnounceActivity {
actor: ObjectId<ApubCommunity>,
to: Vec<Url>,
object: AnnouncableActivities,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: AnnounceType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl AnnounceActivity { impl AnnounceActivity {
pub async fn send( pub async fn send(
object: AnnouncableActivities, object: AnnouncableActivities,

View file

@ -1,23 +1,22 @@
use crate::{ use crate::{
activities::{ activities::{
community::{ community::{announce::GetCommunity, send_to_community},
announce::{AnnouncableActivities, GetCommunity},
send_to_community,
},
generate_activity_id, generate_activity_id,
verify_activity, verify_activity,
verify_is_public, verify_is_public,
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::block_user::BlockUserFromCommunity,
}; };
use activitystreams::{activity::kind::BlockType, public, unparsed::Unparsed}; use activitystreams::{activity::kind::BlockType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::community::{ source::community::{
@ -30,23 +29,6 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct BlockUserFromCommunity {
actor: ObjectId<ApubPerson>,
to: Vec<Url>,
pub(in crate::activities::community) object: ObjectId<ApubPerson>,
cc: Vec<Url>,
target: ObjectId<ApubCommunity>,
#[serde(rename = "type")]
kind: BlockType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl BlockUserFromCommunity { impl BlockUserFromCommunity {
pub(in crate::activities::community) fn new( pub(in crate::activities::community) fn new(

View file

@ -1,23 +1,25 @@
use itertools::Itertools;
use url::Url;
use lemmy_apub_lib::traits::ActorType;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use crate::{ use crate::{
activities::{ activities::send_lemmy_activity,
community::announce::{AnnouncableActivities, AnnounceActivity}, activity_lists::AnnouncableActivities,
send_lemmy_activity,
},
check_is_apub_id_valid, check_is_apub_id_valid,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
insert_activity, insert_activity,
objects::community::ApubCommunity, objects::community::ApubCommunity,
protocol::activities::community::announce::AnnounceActivity,
}; };
use itertools::Itertools;
use lemmy_apub_lib::traits::ActorType;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use url::Url;
pub mod add_mod; pub mod add_mod;
pub mod announce; pub mod announce;
pub mod block_user; pub mod block_user;
pub mod remove_mod; pub mod remove_mod;
pub mod report;
pub mod undo_block_user; pub mod undo_block_user;
pub mod update; pub mod update;

View file

@ -1,10 +1,6 @@
use crate::{ use crate::{
activities::{ activities::{
community::{ community::{announce::GetCommunity, get_community_from_moderators_url, send_to_community},
announce::{AnnouncableActivities, GetCommunity},
get_community_from_moderators_url,
send_to_community,
},
generate_activity_id, generate_activity_id,
verify_activity, verify_activity,
verify_add_remove_moderator_target, verify_add_remove_moderator_target,
@ -12,15 +8,17 @@ use crate::{
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::remove_mod::RemoveMod,
}; };
use activitystreams::{activity::kind::RemoveType, public, unparsed::Unparsed}; use activitystreams::{activity::kind::RemoveType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::community::{CommunityModerator, CommunityModeratorForm}, source::community::{CommunityModerator, CommunityModeratorForm},
@ -28,23 +26,6 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct RemoveMod {
actor: ObjectId<ApubPerson>,
to: Vec<Url>,
pub(in crate::activities) object: ObjectId<ApubPerson>,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: RemoveType,
pub(in crate::activities) target: Url,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl RemoveMod { impl RemoveMod {
pub async fn send( pub async fn send(

View file

@ -1,19 +1,9 @@
use crate::{ use activitystreams::activity::kind::FlagType;
activities::{
generate_activity_id,
send_lemmy_activity,
verify_activity,
verify_person_in_community,
},
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
PostOrComment,
};
use activitystreams::{activity::kind::FlagType, unparsed::Unparsed};
use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse}; use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse};
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
@ -25,22 +15,19 @@ use lemmy_db_schema::{
use lemmy_db_views::{comment_report_view::CommentReportView, post_report_view::PostReportView}; use lemmy_db_views::{comment_report_view::CommentReportView, post_report_view::PostReportView};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)] use crate::{
#[serde(rename_all = "camelCase")] activities::{
pub struct Report { generate_activity_id,
actor: ObjectId<ApubPerson>, send_lemmy_activity,
to: [ObjectId<ApubCommunity>; 1], verify_activity,
object: ObjectId<PostOrComment>, verify_person_in_community,
summary: String, },
#[serde(rename = "type")] fetcher::object_id::ObjectId,
kind: FlagType, objects::{community::ApubCommunity, person::ApubPerson},
id: Url, protocol::activities::community::report::Report,
#[serde(flatten)] PostOrComment,
unparsed: Unparsed, };
}
impl Report { impl Report {
pub async fn send( pub async fn send(

View file

@ -1,24 +1,25 @@
use crate::{ use crate::{
activities::{ activities::{
community::{ community::{announce::GetCommunity, send_to_community},
announce::{AnnouncableActivities, GetCommunity},
block_user::BlockUserFromCommunity,
send_to_community,
},
generate_activity_id, generate_activity_id,
verify_activity, verify_activity,
verify_is_public, verify_is_public,
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::{
block_user::BlockUserFromCommunity,
undo_block_user::UndoBlockUserFromCommunity,
},
}; };
use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed}; use activitystreams::{activity::kind::UndoType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::community::{CommunityPersonBan, CommunityPersonBanForm}, source::community::{CommunityPersonBan, CommunityPersonBanForm},
@ -26,22 +27,6 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UndoBlockUserFromCommunity {
actor: ObjectId<ApubPerson>,
to: Vec<Url>,
object: BlockUserFromCommunity,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: UndoType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl UndoBlockUserFromCommunity { impl UndoBlockUserFromCommunity {
pub async fn send( pub async fn send(

View file

@ -1,11 +1,22 @@
use activitystreams::{activity::kind::UpdateType, public, unparsed::Unparsed}; use crate::{
use serde::{Deserialize, Serialize}; activities::{
use url::Url; community::{announce::GetCommunity, send_to_community},
generate_activity_id,
verify_activity,
verify_is_public,
verify_mod_action,
verify_person_in_community,
},
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
protocol::{activities::community::update::UpdateCommunity, objects::group::Group},
};
use activitystreams::{activity::kind::UpdateType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType, ApubObject}, traits::{ActivityHandler, ActorType, ApubObject},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::community::{Community, CommunityForm}, source::community::{Community, CommunityForm},
@ -14,40 +25,6 @@ use lemmy_db_schema::{
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
use crate::{
activities::{
community::{
announce::{AnnouncableActivities, GetCommunity},
send_to_community,
},
generate_activity_id,
verify_activity,
verify_is_public,
verify_mod_action,
verify_person_in_community,
},
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
protocol::objects::group::Group,
};
/// This activity is received from a remote community mod, and updates the description or other
/// fields of a local community.
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UpdateCommunity {
actor: ObjectId<ApubPerson>,
to: Vec<Url>,
// TODO: would be nice to use a separate struct here, which only contains the fields updated here
object: Group,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: UpdateType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl UpdateCommunity { impl UpdateCommunity {
pub async fn send( pub async fn send(
community: &ApubCommunity, community: &ApubCommunity,

View file

@ -1,28 +1,11 @@
use crate::{ use activitystreams::{activity::kind::DeleteType, public};
activities::{
community::{
announce::{AnnouncableActivities, GetCommunity},
send_to_community,
},
deletion::{
receive_delete_action,
verify_delete_activity,
DeletableObjects,
WebsocketMessages,
},
generate_activity_id,
verify_activity,
verify_is_public,
},
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
};
use activitystreams::{activity::kind::DeleteType, public, unparsed::Unparsed};
use anyhow::anyhow; use anyhow::anyhow;
use url::Url;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
@ -46,35 +29,25 @@ use lemmy_websocket::{
LemmyContext, LemmyContext,
UserOperationCrud, UserOperationCrud,
}; };
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use url::Url;
/// This is very confusing, because there are four distinct cases to handle: use crate::{
/// - user deletes their post activities::{
/// - user deletes their comment community::{announce::GetCommunity, send_to_community},
/// - remote community mod deletes local community deletion::{
/// - remote community deletes itself (triggered by a mod) receive_delete_action,
/// verify_delete_activity,
/// TODO: we should probably change how community deletions work to simplify this. Probably by DeletableObjects,
/// wrapping it in an announce just like other activities, instead of having the community send it. WebsocketMessages,
#[skip_serializing_none] },
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)] generate_activity_id,
#[serde(rename_all = "camelCase")] verify_activity,
pub struct Delete { verify_is_public,
actor: ObjectId<ApubPerson>, },
to: Vec<Url>, activity_lists::AnnouncableActivities,
pub(in crate::activities::deletion) object: Url, fetcher::object_id::ObjectId,
pub(in crate::activities::deletion) cc: Vec<Url>, objects::{community::ApubCommunity, person::ApubPerson},
#[serde(rename = "type")] protocol::activities::deletion::delete::Delete,
kind: DeleteType, };
/// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
/// deleting their own content.
pub(in crate::activities::deletion) summary: Option<String>,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl ActivityHandler for Delete { impl ActivityHandler for Delete {

View file

@ -1,12 +1,5 @@
use crate::{ use url::Url;
activities::{
deletion::{delete::Delete, undo_delete::UndoDelete},
verify_mod_action,
verify_person_in_community,
},
fetcher::object_id::ObjectId,
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
traits::{ActivityFields, ActorType, ApubObject}, traits::{ActivityFields, ActorType, ApubObject},
@ -19,7 +12,13 @@ use lemmy_websocket::{
LemmyContext, LemmyContext,
UserOperationCrud, UserOperationCrud,
}; };
use url::Url;
use crate::{
activities::{verify_mod_action, verify_person_in_community},
fetcher::object_id::ObjectId,
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
};
pub mod delete; pub mod delete;
pub mod undo_delete; pub mod undo_delete;

View file

@ -1,11 +1,24 @@
use activitystreams::{activity::kind::UndoType, public};
use anyhow::anyhow;
use url::Url;
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
data::Data,
traits::{ActivityHandler, ActorType},
};
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
use lemmy_utils::LemmyError;
use lemmy_websocket::{
send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
LemmyContext,
UserOperationCrud,
};
use crate::{ use crate::{
activities::{ activities::{
community::{ community::{announce::GetCommunity, send_to_community},
announce::{AnnouncableActivities, GetCommunity},
send_to_community,
},
deletion::{ deletion::{
delete::Delete,
receive_delete_action, receive_delete_action,
verify_delete_activity, verify_delete_activity,
DeletableObjects, DeletableObjects,
@ -15,39 +28,11 @@ use crate::{
verify_activity, verify_activity,
verify_is_public, verify_is_public,
}, },
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
}; };
use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
use anyhow::anyhow;
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
data::Data,
traits::{ActivityFields, ActivityHandler, ActorType},
};
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
use lemmy_utils::LemmyError;
use lemmy_websocket::{
send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
LemmyContext,
UserOperationCrud,
};
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UndoDelete {
actor: ObjectId<ApubPerson>,
to: Vec<Url>,
object: Delete,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: UndoType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl ActivityHandler for UndoDelete { impl ActivityHandler for UndoDelete {

View file

@ -1,14 +1,9 @@
use crate::{ use crate::{
activities::{ activities::{generate_activity_id, send_lemmy_activity, verify_activity},
following::follow::FollowCommunity,
generate_activity_id,
send_lemmy_activity,
verify_activity,
},
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
}; };
use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed}; use activitystreams::activity::kind::AcceptType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -18,21 +13,6 @@ use lemmy_apub_lib::{
use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable}; use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct AcceptFollowCommunity {
actor: ObjectId<ApubCommunity>,
to: [ObjectId<ApubPerson>; 1],
object: FollowCommunity,
#[serde(rename = "type")]
kind: AcceptType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl AcceptFollowCommunity { impl AcceptFollowCommunity {
pub async fn send( pub async fn send(

View file

@ -1,6 +1,5 @@
use crate::{ use crate::{
activities::{ activities::{
following::accept::AcceptFollowCommunity,
generate_activity_id, generate_activity_id,
send_lemmy_activity, send_lemmy_activity,
verify_activity, verify_activity,
@ -9,12 +8,13 @@ use crate::{
}, },
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
}; };
use activitystreams::{activity::kind::FollowType, unparsed::Unparsed}; use activitystreams::activity::kind::FollowType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
verify::verify_urls_match, verify::verify_urls_match,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -23,21 +23,6 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct FollowCommunity {
pub(in crate::activities::following) actor: ObjectId<ApubPerson>,
pub(in crate::activities::following) to: [ObjectId<ApubCommunity>; 1],
pub(in crate::activities::following) object: ObjectId<ApubCommunity>,
#[serde(rename = "type")]
kind: FollowType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl FollowCommunity { impl FollowCommunity {
pub(in crate::activities::following) fn new( pub(in crate::activities::following) fn new(

View file

@ -1,3 +1,3 @@
pub mod accept; pub mod accept;
pub mod follow; pub mod follow;
pub mod undo; pub mod undo_follow;

View file

@ -1,15 +1,10 @@
use crate::{ use crate::{
activities::{ activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
following::follow::FollowCommunity,
generate_activity_id,
send_lemmy_activity,
verify_activity,
verify_person,
},
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity},
}; };
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -22,21 +17,6 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UndoFollowCommunity {
actor: ObjectId<ApubPerson>,
to: [ObjectId<ApubCommunity>; 1],
object: FollowCommunity,
#[serde(rename = "type")]
kind: UndoType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl UndoFollowCommunity { impl UndoFollowCommunity {
pub async fn send( pub async fn send(

View file

@ -22,8 +22,7 @@ use lemmy_db_views_actor::{
use lemmy_utils::{settings::structs::Settings, LemmyError}; use lemmy_utils::{settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use log::info; use log::info;
use serde::{Deserialize, Serialize}; use serde::Serialize;
use strum_macros::ToString;
use url::{ParseError, Url}; use url::{ParseError, Url};
use uuid::Uuid; use uuid::Uuid;
@ -33,15 +32,8 @@ pub mod deletion;
pub mod following; pub mod following;
pub mod post; pub mod post;
pub mod private_message; pub mod private_message;
pub mod report;
pub mod voting; pub mod voting;
#[derive(Clone, Debug, ToString, Deserialize, Serialize)]
pub enum CreateOrUpdateType {
Create,
Update,
}
/// Checks that the specified Url actually identifies a Person (by fetching it), and that the person /// Checks that the specified Url actually identifies a Person (by fetching it), and that the person
/// doesn't have a site ban. /// doesn't have a site ban.
async fn verify_person( async fn verify_person(

View file

@ -1,7 +1,5 @@
use activitystreams::{public, unparsed::Unparsed}; use activitystreams::public;
use anyhow::anyhow; use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use url::Url;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
@ -16,36 +14,19 @@ use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCru
use crate::{ use crate::{
activities::{ activities::{
check_community_deleted_or_removed, check_community_deleted_or_removed,
community::{ community::{announce::GetCommunity, send_to_community},
announce::{AnnouncableActivities, GetCommunity},
send_to_community,
},
generate_activity_id, generate_activity_id,
verify_activity, verify_activity,
verify_is_public, verify_is_public,
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
CreateOrUpdateType,
}, },
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost}, objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
protocol::objects::page::Page, protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
}; };
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrUpdatePost {
actor: ObjectId<ApubPerson>,
to: Vec<Url>,
object: Page,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: CreateOrUpdateType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl CreateOrUpdatePost { impl CreateOrUpdatePost {
pub(crate) async fn new( pub(crate) async fn new(
post: &ApubPost, post: &ApubPost,

View file

@ -1,40 +1,21 @@
use crate::{ use crate::{
activities::{ activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
generate_activity_id,
send_lemmy_activity,
verify_activity,
verify_person,
CreateOrUpdateType,
},
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage}, objects::{person::ApubPerson, private_message::ApubPrivateMessage},
protocol::objects::chat_message::ChatMessage, protocol::activities::{
private_message::create_or_update::CreateOrUpdatePrivateMessage,
CreateOrUpdateType,
},
}; };
use activitystreams::unparsed::Unparsed;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType, ApubObject}, traits::{ActivityHandler, ActorType, ApubObject},
verify::verify_domains_match, verify::verify_domains_match,
}; };
use lemmy_db_schema::{source::person::Person, traits::Crud}; use lemmy_db_schema::{source::person::Person, traits::Crud};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrUpdatePrivateMessage {
id: Url,
actor: ObjectId<ApubPerson>,
to: [ObjectId<ApubPerson>; 1],
object: ChatMessage,
#[serde(rename = "type")]
kind: CreateOrUpdateType,
#[serde(flatten)]
pub unparsed: Unparsed,
}
impl CreateOrUpdatePrivateMessage { impl CreateOrUpdatePrivateMessage {
pub async fn send( pub async fn send(

View file

@ -2,12 +2,13 @@ use crate::{
activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person}, activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage}, objects::{person::ApubPerson, private_message::ApubPrivateMessage},
protocol::activities::private_message::delete::DeletePrivateMessage,
}; };
use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed}; use activitystreams::activity::kind::DeleteType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
verify::verify_domains_match, verify::verify_domains_match,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -16,21 +17,6 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct DeletePrivateMessage {
actor: ObjectId<ApubPerson>,
to: [ObjectId<ApubPerson>; 1],
pub(in crate::activities::private_message) object: ObjectId<ApubPrivateMessage>,
#[serde(rename = "type")]
kind: DeleteType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl DeletePrivateMessage { impl DeletePrivateMessage {
pub(in crate::activities::private_message) fn new( pub(in crate::activities::private_message) fn new(

View file

@ -1,15 +1,13 @@
use crate::{ use crate::{
activities::{ activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
generate_activity_id,
private_message::delete::DeletePrivateMessage,
send_lemmy_activity,
verify_activity,
verify_person,
},
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage}, objects::{person::ApubPerson, private_message::ApubPrivateMessage},
protocol::activities::private_message::{
delete::DeletePrivateMessage,
undo_delete::UndoDeletePrivateMessage,
},
}; };
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -22,21 +20,6 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UndoDeletePrivateMessage {
actor: ObjectId<ApubPerson>,
to: [ObjectId<ApubPerson>; 1],
object: DeletePrivateMessage,
#[serde(rename = "type")]
kind: UndoType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl UndoDeletePrivateMessage { impl UndoDeletePrivateMessage {
pub async fn send( pub async fn send(

View file

@ -1,7 +1,3 @@
use crate::{
activities::voting::vote::VoteType,
objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
@ -17,6 +13,11 @@ use lemmy_websocket::{
UserOperation, UserOperation,
}; };
use crate::{
objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
protocol::activities::voting::vote::VoteType,
};
pub mod undo_vote; pub mod undo_vote;
pub mod vote; pub mod vote;

View file

@ -1,24 +1,7 @@
use crate::{ use std::ops::Deref;
activities::{
community::{ use activitystreams::{activity::kind::UndoType, public};
announce::{AnnouncableActivities, GetCommunity},
send_to_community,
},
generate_activity_id,
verify_activity,
verify_is_public,
verify_person_in_community,
voting::{
undo_vote_comment,
undo_vote_post,
vote::{Vote, VoteType},
},
},
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
PostOrComment,
};
use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -28,23 +11,25 @@ use lemmy_apub_lib::{
use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud}; use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use std::ops::Deref;
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)] use crate::{
#[serde(rename_all = "camelCase")] activities::{
pub struct UndoVote { community::{announce::GetCommunity, send_to_community},
actor: ObjectId<ApubPerson>, generate_activity_id,
to: Vec<Url>, verify_activity,
object: Vote, verify_is_public,
cc: Vec<Url>, verify_person_in_community,
#[serde(rename = "type")] voting::{undo_vote_comment, undo_vote_post},
kind: UndoType, },
id: Url, activity_lists::AnnouncableActivities,
#[serde(flatten)] fetcher::object_id::ObjectId,
unparsed: Unparsed, objects::{community::ApubCommunity, person::ApubPerson},
} protocol::activities::voting::{
undo_vote::UndoVote,
vote::{Vote, VoteType},
},
PostOrComment,
};
impl UndoVote { impl UndoVote {
pub async fn send( pub async fn send(

View file

@ -1,25 +1,11 @@
use crate::{ use std::ops::Deref;
activities::{
community::{ use activitystreams::public;
announce::{AnnouncableActivities, GetCommunity},
send_to_community,
},
generate_activity_id,
verify_activity,
verify_is_public,
verify_person_in_community,
voting::{vote_comment, vote_post},
},
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
PostOrComment,
};
use activitystreams::{public, unparsed::Unparsed};
use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::CommunityId, newtypes::CommunityId,
@ -28,51 +14,22 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use std::{convert::TryFrom, ops::Deref};
use strum_macros::ToString;
use url::Url;
#[derive(Clone, Debug, ToString, Deserialize, Serialize)] use crate::{
pub enum VoteType { activities::{
Like, community::{announce::GetCommunity, send_to_community},
Dislike, generate_activity_id,
} verify_activity,
verify_is_public,
impl TryFrom<i16> for VoteType { verify_person_in_community,
type Error = LemmyError; voting::{vote_comment, vote_post},
},
fn try_from(value: i16) -> Result<Self, Self::Error> { activity_lists::AnnouncableActivities,
match value { fetcher::object_id::ObjectId,
1 => Ok(VoteType::Like), objects::{community::ApubCommunity, person::ApubPerson},
-1 => Ok(VoteType::Dislike), protocol::activities::voting::vote::{Vote, VoteType},
_ => Err(anyhow!("invalid vote value").into()), PostOrComment,
} };
}
}
impl From<&VoteType> for i16 {
fn from(value: &VoteType) -> i16 {
match value {
VoteType::Like => 1,
VoteType::Dislike => -1,
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct Vote {
actor: ObjectId<ApubPerson>,
to: Vec<Url>,
pub(in crate::activities::voting) object: ObjectId<PostOrComment>,
cc: Vec<Url>,
#[serde(rename = "type")]
pub(in crate::activities::voting) kind: VoteType,
id: Url,
#[serde(flatten)]
unparsed: Unparsed,
}
impl Vote { impl Vote {
pub(in crate::activities::voting) fn new( pub(in crate::activities::voting) fn new(

View file

@ -0,0 +1,113 @@
use serde::{Deserialize, Serialize};
use lemmy_apub_lib::{
traits::{ActivityFields, ActivityHandler, ActorType},
verify::verify_urls_match,
};
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use crate::{
activities::community::announce::GetCommunity,
objects::community::ApubCommunity,
protocol::activities::{
community::{
add_mod::AddMod,
announce::AnnounceActivity,
block_user::BlockUserFromCommunity,
remove_mod::RemoveMod,
report::Report,
undo_block_user::UndoBlockUserFromCommunity,
update::UpdateCommunity,
},
create_or_update::{comment::CreateOrUpdateComment, post::CreateOrUpdatePost},
deletion::{delete::Delete, undo_delete::UndoDelete},
following::{
accept::AcceptFollowCommunity,
follow::FollowCommunity,
undo_follow::UndoFollowCommunity,
},
private_message::{
create_or_update::CreateOrUpdatePrivateMessage,
delete::DeletePrivateMessage,
undo_delete::UndoDeletePrivateMessage,
},
voting::{undo_vote::UndoVote, vote::Vote},
},
};
#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum SharedInboxActivities {
GroupInboxActivities(GroupInboxActivities),
// 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.
PersonInboxActivities(PersonInboxActivities),
}
#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum GroupInboxActivities {
FollowCommunity(FollowCommunity),
UndoFollowCommunity(UndoFollowCommunity),
AnnouncableActivities(AnnouncableActivities),
Report(Report),
}
#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum PersonInboxActivities {
AcceptFollowCommunity(AcceptFollowCommunity),
/// Some activities can also be sent from user to user, eg a comment with mentions
AnnouncableActivities(AnnouncableActivities),
CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
DeletePrivateMessage(DeletePrivateMessage),
UndoDeletePrivateMessage(UndoDeletePrivateMessage),
AnnounceActivity(Box<AnnounceActivity>),
}
#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum AnnouncableActivities {
CreateOrUpdateComment(CreateOrUpdateComment),
CreateOrUpdatePost(Box<CreateOrUpdatePost>),
Vote(Vote),
UndoVote(UndoVote),
Delete(Delete),
UndoDelete(UndoDelete),
UpdateCommunity(Box<UpdateCommunity>),
BlockUserFromCommunity(BlockUserFromCommunity),
UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
AddMod(AddMod),
RemoveMod(RemoveMod),
}
#[async_trait::async_trait(?Send)]
impl GetCommunity for AnnouncableActivities {
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?,
BlockUserFromCommunity(a) => a.get_community(context, request_counter).await?,
UndoBlockUserFromCommunity(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?,
};
verify_urls_match(self.actor(), &community.actor_id())?;
Ok(community)
}
}

View file

@ -1,12 +1,7 @@
use crate::{
activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType},
collections::CommunityContext,
generate_outbox_url,
objects::{person::ApubPerson, post::ApubPost},
protocol::collections::group_outbox::GroupOutbox,
};
use activitystreams::collection::kind::OrderedCollectionType; use activitystreams::collection::kind::OrderedCollectionType;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use url::Url;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -18,7 +13,16 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use url::Url;
use crate::{
collections::CommunityContext,
generate_outbox_url,
objects::{person::ApubPerson, post::ApubPost},
protocol::{
activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
collections::group_outbox::GroupOutbox,
},
};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct ApubCommunityOutbox(Vec<ApubPost>); pub(crate) struct ApubCommunityOutbox(Vec<ApubPost>);

View file

@ -1,23 +1,6 @@
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
use log::info;
use serde::{Deserialize, Serialize};
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
verify::verify_domains_match,
};
use lemmy_db_schema::source::community::Community;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use crate::{ use crate::{
activities::{ activities::{community::announce::GetCommunity, verify_person_in_community},
community::announce::{AnnouncableActivities, AnnounceActivity, GetCommunity}, activity_lists::GroupInboxActivities,
following::{follow::FollowCommunity, undo::UndoFollowCommunity},
report::Report,
verify_person_in_community,
},
collections::{ collections::{
community_moderators::ApubCommunityModerators, community_moderators::ApubCommunityModerators,
community_outbox::ApubCommunityOutbox, community_outbox::ApubCommunityOutbox,
@ -33,8 +16,22 @@ use crate::{
receive_activity, receive_activity,
}, },
objects::community::ApubCommunity, objects::community::ApubCommunity,
protocol::collections::group_followers::CommunityFollowers, protocol::{
activities::community::announce::AnnounceActivity,
collections::group_followers::CommunityFollowers,
},
}; };
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
traits::{ActivityFields, ActorType, ApubObject},
verify::verify_domains_match,
};
use lemmy_db_schema::source::community::Community;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use log::info;
use serde::Deserialize;
#[derive(Deserialize)] #[derive(Deserialize)]
pub(crate) struct CommunityQuery { pub(crate) struct CommunityQuery {
@ -61,16 +58,6 @@ pub(crate) async fn get_apub_community_http(
} }
} }
#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum GroupInboxActivities {
FollowCommunity(FollowCommunity),
UndoFollowCommunity(UndoFollowCommunity),
AnnouncableActivities(AnnouncableActivities),
Report(Report),
}
/// Handler for all incoming receive to community inboxes. /// Handler for all incoming receive to community inboxes.
pub async fn community_inbox( pub async fn community_inbox(
request: HttpRequest, request: HttpRequest,

View file

@ -1,11 +1,9 @@
use crate::{ use crate::{
activity_lists::SharedInboxActivities,
check_is_apub_id_valid, check_is_apub_id_valid,
context::WithContext, context::WithContext,
fetcher::get_or_fetch_and_upsert_actor, fetcher::get_or_fetch_and_upsert_actor,
http::{ http::{community::receive_group_inbox, person::receive_person_inbox},
community::{receive_group_inbox, GroupInboxActivities},
person::{receive_person_inbox, PersonInboxActivities},
},
insert_activity, insert_activity,
}; };
use actix_web::{ use actix_web::{
@ -39,16 +37,6 @@ mod person;
mod post; mod post;
pub mod routes; pub mod routes;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum SharedInboxActivities {
GroupInboxActivities(GroupInboxActivities),
// 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.
PersonInboxActivities(PersonInboxActivities),
}
pub async fn shared_inbox( pub async fn shared_inbox(
request: HttpRequest, request: HttpRequest,
payload: Payload, payload: Payload,

View file

@ -1,23 +1,5 @@
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
use log::info;
use serde::{Deserialize, Serialize};
use lemmy_api_common::blocking;
use lemmy_apub_lib::traits::{ActivityFields, ActivityHandler, ApubObject};
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use crate::{ use crate::{
activities::{ activity_lists::PersonInboxActivities,
community::announce::{AnnouncableActivities, AnnounceActivity},
following::accept::AcceptFollowCommunity,
private_message::{
create_or_update::CreateOrUpdatePrivateMessage,
delete::DeletePrivateMessage,
undo_delete::UndoDeletePrivateMessage,
},
},
context::WithContext, context::WithContext,
http::{ http::{
create_apub_response, create_apub_response,
@ -28,6 +10,14 @@ use crate::{
objects::person::ApubPerson, objects::person::ApubPerson,
protocol::collections::person_outbox::UserOutbox, protocol::collections::person_outbox::UserOutbox,
}; };
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
use lemmy_api_common::blocking;
use lemmy_apub_lib::traits::ApubObject;
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use log::info;
use serde::Deserialize;
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct PersonQuery { pub struct PersonQuery {
@ -56,19 +46,6 @@ pub(crate) async fn get_apub_person_http(
} }
} }
#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum PersonInboxActivities {
AcceptFollowCommunity(AcceptFollowCommunity),
/// Some activities can also be sent from user to user, eg a comment with mentions
AnnouncableActivities(AnnouncableActivities),
CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
DeletePrivateMessage(DeletePrivateMessage),
UndoDeletePrivateMessage(UndoDeletePrivateMessage),
AnnounceActivity(Box<AnnounceActivity>),
}
pub async fn person_inbox( pub async fn person_inbox(
request: HttpRequest, request: HttpRequest,
payload: Payload, payload: Payload,

View file

@ -1,11 +1,12 @@
pub mod activities; pub mod activities;
pub(crate) mod activity_lists;
pub(crate) mod collections; pub(crate) mod collections;
mod context; mod context;
pub mod fetcher; pub mod fetcher;
pub mod http; pub mod http;
pub mod migrations; pub mod migrations;
pub mod objects; pub mod objects;
pub(crate) mod protocol; pub mod protocol;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;

View file

@ -0,0 +1,20 @@
use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
use activitystreams::{activity::kind::AddType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct AddMod {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: ObjectId<ApubPerson>,
pub(crate) target: Url,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: AddType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,23 @@
use crate::{
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::community::ApubCommunity,
};
use activitystreams::{activity::kind::AnnounceType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct AnnounceActivity {
pub(crate) actor: ObjectId<ApubCommunity>,
pub(crate) to: Vec<Url>,
pub(crate) object: AnnouncableActivities,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: AnnounceType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,23 @@
use crate::{
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
};
use activitystreams::{activity::kind::BlockType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct BlockUserFromCommunity {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: ObjectId<ApubPerson>,
pub(crate) cc: Vec<Url>,
pub(crate) target: ObjectId<ApubCommunity>,
#[serde(rename = "type")]
pub(crate) kind: BlockType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,7 @@
pub mod add_mod;
pub mod announce;
pub mod block_user;
pub mod remove_mod;
pub mod report;
pub mod undo_block_user;
pub mod update;

View file

@ -0,0 +1,20 @@
use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
use activitystreams::{activity::kind::RemoveType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct RemoveMod {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: ObjectId<ApubPerson>,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: RemoveType,
pub(crate) target: Url,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,22 @@
use crate::{
fetcher::{object_id::ObjectId, post_or_comment::PostOrComment},
objects::{community::ApubCommunity, person::ApubPerson},
};
use activitystreams::{activity::kind::FlagType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct Report {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: [ObjectId<ApubCommunity>; 1],
pub(crate) object: ObjectId<PostOrComment>,
pub(crate) summary: String,
#[serde(rename = "type")]
pub(crate) kind: FlagType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,23 @@
use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::activities::community::block_user::BlockUserFromCommunity,
};
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UndoBlockUserFromCommunity {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: BlockUserFromCommunity,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: UndoType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,26 @@
use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::objects::group::Group,
};
use activitystreams::{activity::kind::UpdateType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
/// This activity is received from a remote community mod, and updates the description or other
/// fields of a local community.
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UpdateCommunity {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
// TODO: would be nice to use a separate struct here, which only contains the fields updated here
pub(crate) object: Group,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: UpdateType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,25 @@
use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::{activities::CreateOrUpdateType, objects::note::Note},
};
use activitystreams::{link::Mention, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrUpdateComment {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: Note,
pub(crate) cc: Vec<Url>,
#[serde(default)]
pub(crate) tag: Vec<Mention>,
#[serde(rename = "type")]
pub(crate) kind: CreateOrUpdateType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,2 @@
pub mod comment;
pub mod post;

View file

@ -0,0 +1,23 @@
use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::{activities::CreateOrUpdateType, objects::page::Page},
};
use activitystreams::unparsed::Unparsed;
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrUpdatePost {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: Page,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: CreateOrUpdateType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,24 @@
use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use url::Url;
#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct Delete {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: Url,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: DeleteType,
/// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
/// deleting their own content.
pub(crate) summary: Option<String>,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,2 @@
pub mod delete;
pub mod undo_delete;

View file

@ -0,0 +1,25 @@
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use serde::{Deserialize, Serialize};
use url::Url;
use lemmy_apub_lib::traits::ActivityFields;
use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::activities::deletion::delete::Delete,
};
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UndoDelete {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: Delete,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: UndoType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,22 @@
use crate::{
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::follow::FollowCommunity,
};
use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct AcceptFollowCommunity {
pub(crate) actor: ObjectId<ApubCommunity>,
pub(crate) to: [ObjectId<ApubPerson>; 1],
pub(crate) object: FollowCommunity,
#[serde(rename = "type")]
pub(crate) kind: AcceptType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,21 @@
use crate::{
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
};
use activitystreams::{activity::kind::FollowType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct FollowCommunity {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: [ObjectId<ApubCommunity>; 1],
pub(crate) object: ObjectId<ApubCommunity>,
#[serde(rename = "type")]
pub(crate) kind: FollowType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,3 @@
pub(crate) mod accept;
pub mod follow;
pub mod undo_follow;

View file

@ -0,0 +1,22 @@
use crate::{
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::follow::FollowCommunity,
};
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UndoFollowCommunity {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: [ObjectId<ApubCommunity>; 1],
pub(crate) object: FollowCommunity,
#[serde(rename = "type")]
pub(crate) kind: UndoType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,15 @@
use serde::{Deserialize, Serialize};
use strum_macros::ToString;
pub mod community;
pub mod create_or_update;
pub mod deletion;
pub mod following;
pub mod private_message;
pub mod voting;
#[derive(Clone, Debug, ToString, Deserialize, Serialize)]
pub enum CreateOrUpdateType {
Create,
Update,
}

View file

@ -0,0 +1,22 @@
use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::{activities::CreateOrUpdateType, objects::chat_message::ChatMessage},
};
use activitystreams::unparsed::Unparsed;
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrUpdatePrivateMessage {
pub(crate) id: Url,
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: [ObjectId<ApubPerson>; 1],
pub(crate) object: ChatMessage,
#[serde(rename = "type")]
pub(crate) kind: CreateOrUpdateType,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,21 @@
use crate::{
fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage},
};
use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct DeletePrivateMessage {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: [ObjectId<ApubPerson>; 1],
pub(crate) object: ObjectId<ApubPrivateMessage>,
#[serde(rename = "type")]
pub(crate) kind: DeleteType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,3 @@
pub mod create_or_update;
pub mod delete;
pub mod undo_delete;

View file

@ -0,0 +1,22 @@
use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::activities::private_message::delete::DeletePrivateMessage,
};
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_apub_lib::traits::ActivityFields;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UndoDeletePrivateMessage {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: [ObjectId<ApubPerson>; 1],
pub(crate) object: DeletePrivateMessage,
#[serde(rename = "type")]
pub(crate) kind: UndoType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,2 @@
pub mod undo_vote;
pub mod vote;

View file

@ -0,0 +1,25 @@
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use serde::{Deserialize, Serialize};
use url::Url;
use lemmy_apub_lib::traits::ActivityFields;
use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::activities::voting::vote::Vote,
};
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct UndoVote {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: Vote,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: UndoType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}

View file

@ -0,0 +1,53 @@
use crate::{
fetcher::{object_id::ObjectId, post_or_comment::PostOrComment},
objects::person::ApubPerson,
};
use activitystreams::unparsed::Unparsed;
use anyhow::anyhow;
use lemmy_apub_lib::traits::ActivityFields;
use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
use strum_macros::ToString;
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct Vote {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) object: ObjectId<PostOrComment>,
pub(crate) cc: Vec<Url>,
#[serde(rename = "type")]
pub(crate) kind: VoteType,
pub(crate) id: Url,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}
#[derive(Clone, Debug, ToString, Deserialize, Serialize)]
pub enum VoteType {
Like,
Dislike,
}
impl TryFrom<i16> for VoteType {
type Error = LemmyError;
fn try_from(value: i16) -> Result<Self, Self::Error> {
match value {
1 => Ok(VoteType::Like),
-1 => Ok(VoteType::Dislike),
_ => Err(anyhow!("invalid vote value").into()),
}
}
}
impl From<&VoteType> for i16 {
fn from(value: &VoteType) -> i16 {
match value {
VoteType::Like => 1,
VoteType::Dislike => -1,
}
}
}

View file

@ -1,4 +1,4 @@
use crate::activities::post::create_or_update::CreateOrUpdatePost; use crate::protocol::activities::create_or_update::post::CreateOrUpdatePost;
use activitystreams::collection::kind::OrderedCollectionType; use activitystreams::collection::kind::OrderedCollectionType;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View file

@ -4,6 +4,7 @@ use url::Url;
use lemmy_apub_lib::values::MediaTypeMarkdown; use lemmy_apub_lib::values::MediaTypeMarkdown;
pub mod activities;
pub(crate) mod collections; pub(crate) mod collections;
pub(crate) mod objects; pub(crate) mod objects;