-use crate::Perform;
+use std::convert::TryInto;
+
use actix_web::web::Data;
+
use lemmy_api_common::{
blocking,
check_community_ban,
get_local_user_view_from_jwt,
};
use lemmy_apub::{
- activities::voting::{
+ fetcher::post_or_comment::PostOrComment,
+ protocol::activities::voting::{
undo_vote::UndoVote,
vote::{Vote, VoteType},
},
- fetcher::post_or_comment::PostOrComment,
};
use lemmy_db_schema::{
newtypes::LocalUserId,
use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView};
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation};
-use std::convert::TryInto;
+
+use crate::Perform;
#[async_trait::async_trait(?Send)]
impl Perform for MarkCommentAsRead {
-use crate::Perform;
use actix_web::web::Data;
+
use lemmy_api_common::{
blocking,
check_community_ban,
get_local_user_view_from_jwt,
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_views::{
comment_report_view::{CommentReportQueryBuilder, CommentReportView},
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
+use crate::Perform;
+
/// Creates a comment report and notifies the moderators of the community
#[async_trait::async_trait(?Send)]
impl Perform for CreateCommentReport {
is_mod_or_admin,
};
use lemmy_apub::{
- activities::{
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::activities::{
community::{
add_mod::AddMod,
block_user::BlockUserFromCommunity,
remove_mod::RemoveMod,
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::{
source::{
post::*,
};
use lemmy_apub::{
- activities::{
- post::create_or_update::CreateOrUpdatePost,
+ fetcher::post_or_comment::PostOrComment,
+ objects::post::ApubPost,
+ protocol::activities::{
+ create_or_update::post::CreateOrUpdatePost,
voting::{
undo_vote::UndoVote,
vote::{Vote, VoteType},
},
CreateOrUpdateType,
},
- fetcher::post_or_comment::PostOrComment,
- objects::post::ApubPost,
};
use lemmy_db_schema::{
source::{moderator::*, post::*},
-use crate::Perform;
use actix_web::web::Data;
+
use lemmy_api_common::{
blocking,
check_community_ban,
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::{
source::post_report::{PostReport, PostReportForm},
traits::Reportable,
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
+use crate::Perform;
+
/// Creates a post report and notifies the moderators of the community
#[async_trait::async_trait(?Send)]
impl Perform for CreatePostReport {
-use crate::PerformCrud;
use actix_web::web::Data;
+
use lemmy_api_common::{
blocking,
check_community_ban,
get_post,
};
use lemmy_apub::{
- activities::{
- comment::create_or_update::CreateOrUpdateComment,
+ fetcher::post_or_comment::PostOrComment,
+ generate_local_apub_endpoint,
+ protocol::activities::{
+ create_or_update::comment::CreateOrUpdateComment,
voting::vote::{Vote, VoteType},
CreateOrUpdateType,
},
- fetcher::post_or_comment::PostOrComment,
- generate_local_apub_endpoint,
EndpointType,
};
use lemmy_db_schema::{
UserOperationCrud,
};
+use crate::PerformCrud;
+
#[async_trait::async_trait(?Send)]
impl PerformCrud for CreateComment {
type Response = CommentResponse;
-use crate::PerformCrud;
use actix_web::web::Data;
+
use lemmy_api_common::{
blocking,
check_community_ban,
comment::*,
get_local_user_view_from_jwt,
};
-use lemmy_apub::activities::{
- comment::create_or_update::CreateOrUpdateComment,
+use lemmy_apub::protocol::activities::{
+ create_or_update::comment::CreateOrUpdateComment,
CreateOrUpdateType,
};
use lemmy_db_schema::source::comment::Comment;
UserOperationCrud,
};
+use crate::PerformCrud;
+
#[async_trait::async_trait(?Send)]
impl PerformCrud for EditComment {
type Response = CommentResponse;
community::{CommunityResponse, EditCommunity},
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::{
diesel_option_overwrite_to_url,
naive_now,
-use crate::PerformCrud;
use actix_web::web::Data;
+use log::warn;
+use webmention::{Webmention, WebmentionError};
+
use lemmy_api_common::{
blocking,
check_community_ban,
post::*,
};
use lemmy_apub::{
- activities::{
- post::create_or_update::CreateOrUpdatePost,
+ fetcher::post_or_comment::PostOrComment,
+ generate_local_apub_endpoint,
+ protocol::activities::{
+ create_or_update::post::CreateOrUpdatePost,
voting::vote::{Vote, VoteType},
CreateOrUpdateType,
},
- fetcher::post_or_comment::PostOrComment,
- generate_local_apub_endpoint,
EndpointType,
};
use lemmy_db_schema::{
LemmyError,
};
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)]
impl PerformCrud for CreatePost {
-use crate::PerformCrud;
use actix_web::web::Data;
+
use lemmy_api_common::{
blocking,
check_community_ban,
get_local_user_view_from_jwt,
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::{
naive_now,
source::post::{Post, PostForm},
};
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
+use crate::PerformCrud;
+
#[async_trait::async_trait(?Send)]
impl PerformCrud for EditPost {
type Response = PostResponse;
person::{CreatePrivateMessage, PrivateMessageResponse},
};
use lemmy_apub::{
- activities::{
+ generate_local_apub_endpoint,
+ protocol::activities::{
private_message::create_or_update::CreateOrUpdatePrivateMessage,
CreateOrUpdateType,
},
- generate_local_apub_endpoint,
EndpointType,
};
use lemmy_db_schema::{
get_local_user_view_from_jwt,
person::{DeletePrivateMessage, PrivateMessageResponse},
};
-use lemmy_apub::activities::private_message::{
+use lemmy_apub::protocol::activities::private_message::{
delete::DeletePrivateMessage as DeletePrivateMessageApub,
undo_delete::UndoDeletePrivateMessage,
};
get_local_user_view_from_jwt,
person::{EditPrivateMessage, PrivateMessageResponse},
};
-use lemmy_apub::activities::{
+use lemmy_apub::protocol::activities::{
private_message::create_or_update::CreateOrUpdatePrivateMessage,
CreateOrUpdateType,
};
-use activitystreams::{link::Mention, public, unparsed::Unparsed};
-use serde::{Deserialize, Serialize};
-use url::Url;
+use activitystreams::public;
use lemmy_api_common::{blocking, check_post_deleted_or_removed};
use lemmy_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
+ traits::{ActivityHandler, ActorType, ApubObject},
verify::verify_domains_match,
};
use lemmy_db_schema::{
activities::{
check_community_deleted_or_removed,
comment::{collect_non_local_mentions, get_notif_recipients},
- community::{
- announce::{AnnouncableActivities, GetCommunity},
- send_to_community,
- },
+ community::{announce::GetCommunity, send_to_community},
generate_activity_id,
verify_activity,
verify_is_public,
verify_person_in_community,
- CreateOrUpdateType,
},
+ activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
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 {
pub async fn send(
comment: &ApubComment,
use crate::{
activities::{
- community::{
- announce::{AnnouncableActivities, GetCommunity},
- get_community_from_moderators_url,
- send_to_community,
- },
+ community::{announce::GetCommunity, get_community_from_moderators_url, send_to_community},
generate_activity_id,
verify_activity,
verify_add_remove_moderator_target,
verify_mod_action,
verify_person_in_community,
},
+ activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
generate_moderators_url,
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_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
+ traits::{ActivityHandler, ActorType},
};
use lemmy_db_schema::{
source::community::{CommunityModerator, CommunityModeratorForm},
};
use lemmy_utils::LemmyError;
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 {
pub async fn send(
use crate::{
activities::{
- comment::create_or_update::CreateOrUpdateComment,
- 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},
+ community::list_community_follower_inboxes,
generate_activity_id,
- post::create_or_update::CreateOrUpdatePost,
send_lemmy_activity,
verify_activity,
verify_is_public,
- voting::{undo_vote::UndoVote, vote::Vote},
},
+ activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
http::is_activity_already_known,
insert_activity,
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::{
data::Data,
traits::{ActivityFields, ActivityHandler, ActorType},
- verify::verify_urls_match,
};
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
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)]
pub(crate) trait GetCommunity {
async fn get_community(
) -> 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 {
pub async fn send(
object: AnnouncableActivities,
use crate::{
activities::{
- community::{
- announce::{AnnouncableActivities, GetCommunity},
- send_to_community,
- },
+ 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::block_user::BlockUserFromCommunity,
};
-use activitystreams::{activity::kind::BlockType, public, unparsed::Unparsed};
+use activitystreams::{activity::kind::BlockType, public};
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
+ traits::{ActivityHandler, ActorType},
};
use lemmy_db_schema::{
source::community::{
};
use lemmy_utils::LemmyError;
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 {
pub(in crate::activities::community) fn new(
+use itertools::Itertools;
+use url::Url;
+
+use lemmy_apub_lib::traits::ActorType;
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+
use crate::{
- activities::{
- community::announce::{AnnouncableActivities, AnnounceActivity},
- send_lemmy_activity,
- },
+ activities::send_lemmy_activity,
+ activity_lists::AnnouncableActivities,
check_is_apub_id_valid,
fetcher::object_id::ObjectId,
insert_activity,
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 announce;
pub mod block_user;
pub mod remove_mod;
+pub mod report;
pub mod undo_block_user;
pub mod update;
use crate::{
activities::{
- community::{
- announce::{AnnouncableActivities, GetCommunity},
- get_community_from_moderators_url,
- send_to_community,
- },
+ community::{announce::GetCommunity, get_community_from_moderators_url, send_to_community},
generate_activity_id,
verify_activity,
verify_add_remove_moderator_target,
verify_mod_action,
verify_person_in_community,
},
+ activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
generate_moderators_url,
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_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
+ traits::{ActivityHandler, ActorType},
};
use lemmy_db_schema::{
source::community::{CommunityModerator, CommunityModeratorForm},
};
use lemmy_utils::LemmyError;
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 {
pub async fn send(
-use crate::{
- 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 activitystreams::activity::kind::FlagType;
+
use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse};
use lemmy_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
+ traits::{ActivityHandler, ActorType},
};
use lemmy_db_schema::{
source::{
use lemmy_db_views::{comment_report_view::CommentReportView, post_report_view::PostReportView};
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
-use serde::{Deserialize, Serialize};
-use url::Url;
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct Report {
- actor: ObjectId<ApubPerson>,
- to: [ObjectId<ApubCommunity>; 1],
- object: ObjectId<PostOrComment>,
- summary: String,
- #[serde(rename = "type")]
- kind: FlagType,
- id: Url,
- #[serde(flatten)]
- unparsed: Unparsed,
-}
+use crate::{
+ activities::{
+ generate_activity_id,
+ send_lemmy_activity,
+ verify_activity,
+ verify_person_in_community,
+ },
+ fetcher::object_id::ObjectId,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::activities::community::report::Report,
+ PostOrComment,
+};
impl Report {
pub async fn send(
use crate::{
activities::{
- community::{
- announce::{AnnouncableActivities, GetCommunity},
- block_user::BlockUserFromCommunity,
- send_to_community,
- },
+ 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::{
+ 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_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
+ traits::{ActivityHandler, ActorType},
};
use lemmy_db_schema::{
source::community::{CommunityPersonBan, CommunityPersonBanForm},
};
use lemmy_utils::LemmyError;
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 {
pub async fn send(
-use activitystreams::{activity::kind::UpdateType, public, unparsed::Unparsed};
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::{
- data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
-};
-use lemmy_db_schema::{
- source::community::{Community, CommunityForm},
- traits::Crud,
-};
-use lemmy_utils::LemmyError;
-use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
-
use crate::{
activities::{
- community::{
- announce::{AnnouncableActivities, GetCommunity},
- send_to_community,
- },
+ 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::objects::group::Group,
+ protocol::{activities::community::update::UpdateCommunity, 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,
-}
+use activitystreams::{activity::kind::UpdateType, public};
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::{
+ data::Data,
+ traits::{ActivityHandler, ActorType, ApubObject},
+};
+use lemmy_db_schema::{
+ source::community::{Community, CommunityForm},
+ traits::Crud,
+};
+use lemmy_utils::LemmyError;
+use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
impl UpdateCommunity {
pub async fn send(
-use crate::{
- 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 activitystreams::{activity::kind::DeleteType, public};
use anyhow::anyhow;
+use url::Url;
+
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
+ traits::{ActivityHandler, ActorType},
};
use lemmy_db_schema::{
source::{
LemmyContext,
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:
-/// - user deletes their post
-/// - user deletes their comment
-/// - remote community mod deletes local community
-/// - remote community deletes itself (triggered by a mod)
-///
-/// TODO: we should probably change how community deletions work to simplify this. Probably by
-/// wrapping it in an announce just like other activities, instead of having the community send it.
-#[skip_serializing_none]
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct Delete {
- actor: ObjectId<ApubPerson>,
- to: Vec<Url>,
- pub(in crate::activities::deletion) object: Url,
- pub(in crate::activities::deletion) cc: Vec<Url>,
- #[serde(rename = "type")]
- 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,
-}
+use crate::{
+ activities::{
+ community::{announce::GetCommunity, send_to_community},
+ deletion::{
+ receive_delete_action,
+ verify_delete_activity,
+ DeletableObjects,
+ WebsocketMessages,
+ },
+ generate_activity_id,
+ verify_activity,
+ verify_is_public,
+ },
+ activity_lists::AnnouncableActivities,
+ fetcher::object_id::ObjectId,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::activities::deletion::delete::Delete,
+};
#[async_trait::async_trait(?Send)]
impl ActivityHandler for Delete {
-use crate::{
- 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 url::Url;
+
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
traits::{ActivityFields, ActorType, ApubObject},
LemmyContext,
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 undo_delete;
+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::{
activities::{
- community::{
- announce::{AnnouncableActivities, GetCommunity},
- send_to_community,
- },
+ community::{announce::GetCommunity, send_to_community},
deletion::{
- delete::Delete,
receive_delete_action,
verify_delete_activity,
DeletableObjects,
verify_activity,
verify_is_public,
},
+ activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
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)]
impl ActivityHandler for UndoDelete {
use crate::{
- activities::{
- following::follow::FollowCommunity,
- generate_activity_id,
- send_lemmy_activity,
- verify_activity,
- },
+ activities::{generate_activity_id, send_lemmy_activity, verify_activity},
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_apub_lib::{
data::Data,
use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
use lemmy_utils::LemmyError;
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 {
pub async fn send(
use crate::{
activities::{
- following::accept::AcceptFollowCommunity,
generate_activity_id,
send_lemmy_activity,
verify_activity,
},
fetcher::object_id::ObjectId,
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_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
+ traits::{ActivityHandler, ActorType},
verify::verify_urls_match,
};
use lemmy_db_schema::{
};
use lemmy_utils::LemmyError;
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 {
pub(in crate::activities::following) fn new(
pub mod accept;
pub mod follow;
-pub mod undo;
+pub mod undo_follow;
use crate::{
- activities::{
- following::follow::FollowCommunity,
- 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,
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_apub_lib::{
data::Data,
};
use lemmy_utils::LemmyError;
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 {
pub async fn send(
use lemmy_utils::{settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext;
use log::info;
-use serde::{Deserialize, Serialize};
-use strum_macros::ToString;
+use serde::Serialize;
use url::{ParseError, Url};
use uuid::Uuid;
pub mod following;
pub mod post;
pub mod private_message;
-pub mod report;
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
/// doesn't have a site ban.
async fn verify_person(
-use activitystreams::{public, unparsed::Unparsed};
+use activitystreams::public;
use anyhow::anyhow;
-use serde::{Deserialize, Serialize};
-use url::Url;
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
use crate::{
activities::{
check_community_deleted_or_removed,
- community::{
- announce::{AnnouncableActivities, GetCommunity},
- send_to_community,
- },
+ community::{announce::GetCommunity, send_to_community},
generate_activity_id,
verify_activity,
verify_is_public,
verify_mod_action,
verify_person_in_community,
- CreateOrUpdateType,
},
+ activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
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 {
pub(crate) async fn new(
post: &ApubPost,
use crate::{
- activities::{
- generate_activity_id,
- send_lemmy_activity,
- verify_activity,
- verify_person,
- CreateOrUpdateType,
- },
+ activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
fetcher::object_id::ObjectId,
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_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
+ traits::{ActivityHandler, ActorType, ApubObject},
verify::verify_domains_match,
};
use lemmy_db_schema::{source::person::Person, traits::Crud};
use lemmy_utils::LemmyError;
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 {
pub async fn send(
activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
fetcher::object_id::ObjectId,
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_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
+ traits::{ActivityHandler, ActorType},
verify::verify_domains_match,
};
use lemmy_db_schema::{
};
use lemmy_utils::LemmyError;
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 {
pub(in crate::activities::private_message) fn new(
use crate::{
- activities::{
- generate_activity_id,
- private_message::delete::DeletePrivateMessage,
- send_lemmy_activity,
- verify_activity,
- verify_person,
- },
+ activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
fetcher::object_id::ObjectId,
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_apub_lib::{
data::Data,
};
use lemmy_utils::LemmyError;
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 {
pub async fn send(
-use crate::{
- activities::voting::vote::VoteType,
- objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
-};
use lemmy_api_common::blocking;
use lemmy_db_schema::{
source::{
UserOperation,
};
+use crate::{
+ objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
+ protocol::activities::voting::vote::VoteType,
+};
+
pub mod undo_vote;
pub mod vote;
+use std::ops::Deref;
+
+use activitystreams::{activity::kind::UndoType, public};
+
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::{
+ data::Data,
+ traits::{ActivityFields, ActivityHandler, ActorType},
+ verify::verify_urls_match,
+};
+use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+
use crate::{
activities::{
- community::{
- announce::{AnnouncableActivities, GetCommunity},
- send_to_community,
- },
+ community::{announce::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},
- },
+ voting::{undo_vote_comment, undo_vote_post},
},
+ activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::activities::voting::{
+ undo_vote::UndoVote,
+ vote::{Vote, VoteType},
+ },
PostOrComment,
};
-use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::{
- data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
- verify::verify_urls_match,
-};
-use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use std::ops::Deref;
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct UndoVote {
- actor: ObjectId<ApubPerson>,
- to: Vec<Url>,
- object: Vote,
- cc: Vec<Url>,
- #[serde(rename = "type")]
- kind: UndoType,
- id: Url,
- #[serde(flatten)]
- unparsed: Unparsed,
-}
impl UndoVote {
pub async fn send(
-use crate::{
- activities::{
- community::{
- 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 std::ops::Deref;
+
+use activitystreams::public;
+
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
data::Data,
- traits::{ActivityFields, ActivityHandler, ActorType},
+ traits::{ActivityHandler, ActorType},
};
use lemmy_db_schema::{
newtypes::CommunityId,
};
use lemmy_utils::LemmyError;
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)]
-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,
- }
- }
-}
-#[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,
-}
+use crate::{
+ activities::{
+ community::{announce::GetCommunity, send_to_community},
+ generate_activity_id,
+ verify_activity,
+ verify_is_public,
+ verify_person_in_community,
+ voting::{vote_comment, vote_post},
+ },
+ activity_lists::AnnouncableActivities,
+ fetcher::object_id::ObjectId,
+ objects::{community::ApubCommunity, person::ApubPerson},
+ protocol::activities::voting::vote::{Vote, VoteType},
+ PostOrComment,
+};
impl Vote {
pub(in crate::activities::voting) fn new(
--- /dev/null
+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)
+ }
+}
-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 chrono::NaiveDateTime;
+use url::Url;
+
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
data::Data,
traits::Crud,
};
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)]
pub(crate) struct ApubCommunityOutbox(Vec<ApubPost>);
-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::{
- activities::{
- community::announce::{AnnouncableActivities, AnnounceActivity, GetCommunity},
- following::{follow::FollowCommunity, undo::UndoFollowCommunity},
- report::Report,
- verify_person_in_community,
- },
+ activities::{community::announce::GetCommunity, verify_person_in_community},
+ activity_lists::GroupInboxActivities,
collections::{
community_moderators::ApubCommunityModerators,
community_outbox::ApubCommunityOutbox,
receive_activity,
},
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)]
pub(crate) struct CommunityQuery {
}
}
-#[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.
pub async fn community_inbox(
request: HttpRequest,
use crate::{
+ activity_lists::SharedInboxActivities,
check_is_apub_id_valid,
context::WithContext,
fetcher::get_or_fetch_and_upsert_actor,
- http::{
- community::{receive_group_inbox, GroupInboxActivities},
- person::{receive_person_inbox, PersonInboxActivities},
- },
+ http::{community::receive_group_inbox, person::receive_person_inbox},
insert_activity,
};
use actix_web::{
mod post;
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(
request: HttpRequest,
payload: Payload,
-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::{
- activities::{
- community::announce::{AnnouncableActivities, AnnounceActivity},
- following::accept::AcceptFollowCommunity,
- private_message::{
- create_or_update::CreateOrUpdatePrivateMessage,
- delete::DeletePrivateMessage,
- undo_delete::UndoDeletePrivateMessage,
- },
- },
+ activity_lists::PersonInboxActivities,
context::WithContext,
http::{
create_apub_response,
objects::person::ApubPerson,
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)]
pub struct PersonQuery {
}
}
-#[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(
request: HttpRequest,
payload: Payload,
pub mod activities;
+pub(crate) mod activity_lists;
pub(crate) mod collections;
mod context;
pub mod fetcher;
pub mod http;
pub mod migrations;
pub mod objects;
-pub(crate) mod protocol;
+pub mod protocol;
#[macro_use]
extern crate lazy_static;
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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;
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+pub mod comment;
+pub mod post;
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+pub mod delete;
+pub mod undo_delete;
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+pub(crate) mod accept;
+pub mod follow;
+pub mod undo_follow;
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+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,
+}
--- /dev/null
+pub mod create_or_update;
+pub mod delete;
+pub mod undo_delete;
--- /dev/null
+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,
+}
--- /dev/null
+pub mod undo_vote;
+pub mod vote;
--- /dev/null
+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,
+}
--- /dev/null
+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,
+ }
+ }
+}
-use crate::activities::post::create_or_update::CreateOrUpdatePost;
+use crate::protocol::activities::create_or_update::post::CreateOrUpdatePost;
use activitystreams::collection::kind::OrderedCollectionType;
use serde::{Deserialize, Serialize};
use url::Url;
use lemmy_apub_lib::values::MediaTypeMarkdown;
+pub mod activities;
pub(crate) mod collections;
pub(crate) mod objects;