2023-08-02 16:52:41 +00:00
|
|
|
use crate::{
|
|
|
|
community::BanFromCommunity,
|
|
|
|
context::LemmyContext,
|
|
|
|
person::BanPerson,
|
|
|
|
post::{DeletePost, RemovePost},
|
|
|
|
};
|
2023-07-19 13:49:41 +00:00
|
|
|
use activitypub_federation::config::Data;
|
|
|
|
use futures::future::BoxFuture;
|
2023-08-01 13:53:36 +00:00
|
|
|
use lemmy_db_schema::{
|
2023-08-02 16:52:41 +00:00
|
|
|
newtypes::{CommunityId, DbUrl, PersonId},
|
|
|
|
source::{
|
|
|
|
comment::Comment,
|
|
|
|
community::Community,
|
|
|
|
person::Person,
|
|
|
|
post::Post,
|
|
|
|
private_message::PrivateMessage,
|
|
|
|
},
|
2023-08-01 13:53:36 +00:00
|
|
|
};
|
2023-08-02 16:52:41 +00:00
|
|
|
use lemmy_db_views::structs::PrivateMessageView;
|
2023-09-09 16:25:03 +00:00
|
|
|
use lemmy_utils::error::LemmyResult;
|
|
|
|
use once_cell::sync::OnceCell;
|
2023-08-02 16:52:41 +00:00
|
|
|
use url::Url;
|
2023-07-19 13:49:41 +00:00
|
|
|
|
|
|
|
type MatchOutgoingActivitiesBoxed =
|
|
|
|
Box<for<'a> fn(SendActivityData, &'a Data<LemmyContext>) -> BoxFuture<'a, LemmyResult<()>>>;
|
|
|
|
|
2023-09-09 16:25:03 +00:00
|
|
|
/// This static is necessary so that the api_common crates don't need to depend on lemmy_apub
|
2023-07-19 13:49:41 +00:00
|
|
|
pub static MATCH_OUTGOING_ACTIVITIES: OnceCell<MatchOutgoingActivitiesBoxed> = OnceCell::new();
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum SendActivityData {
|
|
|
|
CreatePost(Post),
|
2023-08-01 13:53:36 +00:00
|
|
|
UpdatePost(Post),
|
2023-08-02 16:52:41 +00:00
|
|
|
DeletePost(Post, Person, DeletePost),
|
|
|
|
RemovePost(Post, Person, RemovePost),
|
|
|
|
LockPost(Post, Person, bool),
|
|
|
|
FeaturePost(Post, Person, bool),
|
2023-07-28 14:39:38 +00:00
|
|
|
CreateComment(Comment),
|
2023-08-02 16:52:41 +00:00
|
|
|
UpdateComment(Comment),
|
2023-08-01 13:53:36 +00:00
|
|
|
DeleteComment(Comment, Person, Community),
|
|
|
|
RemoveComment(Comment, Person, Community, Option<String>),
|
|
|
|
LikePostOrComment(DbUrl, Person, Community, i16),
|
2023-08-02 09:32:16 +00:00
|
|
|
FollowCommunity(Community, Person, bool),
|
2023-08-02 16:52:41 +00:00
|
|
|
UpdateCommunity(Person, Community),
|
|
|
|
DeleteCommunity(Person, Community, bool),
|
|
|
|
RemoveCommunity(Person, Community, Option<String>, bool),
|
|
|
|
AddModToCommunity(Person, CommunityId, PersonId, bool),
|
|
|
|
BanFromCommunity(Person, CommunityId, Person, BanFromCommunity),
|
|
|
|
BanFromSite(Person, Person, BanPerson),
|
|
|
|
CreatePrivateMessage(PrivateMessageView),
|
|
|
|
UpdatePrivateMessage(PrivateMessageView),
|
|
|
|
DeletePrivateMessage(Person, PrivateMessage, bool),
|
2023-08-28 10:23:45 +00:00
|
|
|
DeleteUser(Person, bool),
|
2023-08-02 16:52:41 +00:00
|
|
|
CreateReport(Url, Person, Community, String),
|
2023-07-19 13:49:41 +00:00
|
|
|
}
|
|
|
|
|
2023-09-09 16:25:03 +00:00
|
|
|
pub struct ActivityChannel;
|
2023-07-19 13:49:41 +00:00
|
|
|
|
|
|
|
impl ActivityChannel {
|
|
|
|
pub async fn submit_activity(
|
|
|
|
data: SendActivityData,
|
|
|
|
context: &Data<LemmyContext>,
|
|
|
|
) -> LemmyResult<()> {
|
2023-09-09 16:25:03 +00:00
|
|
|
MATCH_OUTGOING_ACTIVITIES
|
|
|
|
.get()
|
|
|
|
.expect("retrieve function pointer")(data, context)
|
|
|
|
.await
|
2023-07-19 13:49:41 +00:00
|
|
|
}
|
|
|
|
}
|