Rewrite remaining federation actions, get rid of PerformCrud trait (#3794)
* Rewrite ban actions * Rewrite delete/remove actions * Rewrite remove/delete community * Rewrite report actions * Rewrite feature/lock post * Rewrite update community actions * Rewrite remaining federation actions * Get rid of PerformCrud trait * clippy
This commit is contained in:
parent
be1389420b
commit
27be1efb74
46 changed files with 1699 additions and 1927 deletions
|
@ -30,9 +30,6 @@ else
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "killall existing lemmy_server processes"
|
|
||||||
killall -s1 lemmy_server || true
|
|
||||||
|
|
||||||
echo "$PWD"
|
echo "$PWD"
|
||||||
|
|
||||||
echo "start alpha"
|
echo "start alpha"
|
||||||
|
|
|
@ -7,12 +7,14 @@ pushd ..
|
||||||
cargo build
|
cargo build
|
||||||
rm target/lemmy_server || true
|
rm target/lemmy_server || true
|
||||||
cp target/debug/lemmy_server target/lemmy_server
|
cp target/debug/lemmy_server target/lemmy_server
|
||||||
|
killall -s1 lemmy_server || true
|
||||||
./api_tests/prepare-drone-federation-test.sh
|
./api_tests/prepare-drone-federation-test.sh
|
||||||
popd
|
popd
|
||||||
|
|
||||||
yarn
|
yarn
|
||||||
yarn api-test || true
|
yarn api-test || true
|
||||||
|
|
||||||
|
killall -s1 lemmy_server || true
|
||||||
for INSTANCE in lemmy_alpha lemmy_beta lemmy_gamma lemmy_delta lemmy_epsilon; do
|
for INSTANCE in lemmy_alpha lemmy_beta lemmy_gamma lemmy_delta lemmy_epsilon; do
|
||||||
psql "$LEMMY_DATABASE_URL" -c "DROP DATABASE $INSTANCE"
|
psql "$LEMMY_DATABASE_URL" -c "DROP DATABASE $INSTANCE"
|
||||||
done
|
done
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use crate::{check_report_reason, Perform};
|
use crate::check_report_reason;
|
||||||
use actix_web::web::Data;
|
use activitypub_federation::config::Data;
|
||||||
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, CreateCommentReport},
|
comment::{CommentReportResponse, CreateCommentReport},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
local_user_view_from_jwt,
|
local_user_view_from_jwt,
|
||||||
|
@ -21,20 +23,15 @@ use lemmy_db_views::structs::{CommentReportView, CommentView};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
/// 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)]
|
|
||||||
impl Perform for CreateCommentReport {
|
|
||||||
type Response = CommentReportResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(
|
pub async fn create_comment_report(
|
||||||
&self,
|
data: Json<CreateCommentReport>,
|
||||||
context: &Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<CommentReportResponse, LemmyError> {
|
) -> Result<Json<CommentReportResponse>, LemmyError> {
|
||||||
let data: &CreateCommentReport = self;
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
let reason = sanitize_html(self.reason.trim());
|
let reason = sanitize_html(data.reason.trim());
|
||||||
check_report_reason(&reason, &local_site)?;
|
check_report_reason(&reason, &local_site)?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
@ -68,8 +65,18 @@ impl Perform for CreateCommentReport {
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(CommentReportResponse {
|
ActivityChannel::submit_activity(
|
||||||
|
SendActivityData::CreateReport(
|
||||||
|
comment_view.comment.ap_id.inner().clone(),
|
||||||
|
local_user_view.person,
|
||||||
|
comment_view.community,
|
||||||
|
data.reason.clone(),
|
||||||
|
),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(CommentReportResponse {
|
||||||
comment_report_view,
|
comment_report_view,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::Perform;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{AddModToCommunity, AddModToCommunityResponse},
|
community::{AddModToCommunity, AddModToCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{is_mod_or_admin, local_user_view_from_jwt},
|
utils::{is_mod_or_admin, local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -15,17 +16,12 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl Perform for AddModToCommunity {
|
|
||||||
type Response = AddModToCommunityResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(
|
pub async fn add_mod_to_community(
|
||||||
&self,
|
data: Json<AddModToCommunity>,
|
||||||
context: &Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<AddModToCommunityResponse, LemmyError> {
|
) -> Result<Json<AddModToCommunityResponse>, LemmyError> {
|
||||||
let data: &AddModToCommunity = self;
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
||||||
|
@ -64,9 +60,18 @@ impl Perform for AddModToCommunity {
|
||||||
// Note: in case a remote mod is added, this returns the old moderators list, it will only get
|
// Note: in case a remote mod is added, this returns the old moderators list, it will only get
|
||||||
// updated once we receive an activity from the community (like `Announce/Add/Moderator`)
|
// updated once we receive an activity from the community (like `Announce/Add/Moderator`)
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let moderators =
|
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
|
||||||
|
|
||||||
Ok(AddModToCommunityResponse { moderators })
|
ActivityChannel::submit_activity(
|
||||||
}
|
SendActivityData::AddModToCommunity(
|
||||||
|
local_user_view.person,
|
||||||
|
data.community_id,
|
||||||
|
data.person_id,
|
||||||
|
data.added,
|
||||||
|
),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(AddModToCommunityResponse { moderators }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::Perform;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{BanFromCommunity, BanFromCommunityResponse},
|
community::{BanFromCommunity, BanFromCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
local_user_view_from_jwt,
|
local_user_view_from_jwt,
|
||||||
|
@ -28,25 +29,24 @@ use lemmy_utils::{
|
||||||
utils::{time::naive_from_unix, validation::is_valid_body_field},
|
utils::{time::naive_from_unix, validation::is_valid_body_field},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl Perform for BanFromCommunity {
|
|
||||||
type Response = BanFromCommunityResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(
|
pub async fn ban_from_community(
|
||||||
&self,
|
data: Json<BanFromCommunity>,
|
||||||
context: &Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<BanFromCommunityResponse, LemmyError> {
|
) -> Result<Json<BanFromCommunityResponse>, LemmyError> {
|
||||||
let data: &BanFromCommunity = self;
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
|
||||||
let banned_person_id = data.person_id;
|
let banned_person_id = data.person_id;
|
||||||
let remove_data = data.remove_data.unwrap_or(false);
|
let remove_data = data.remove_data.unwrap_or(false);
|
||||||
let expires = data.expires.map(naive_from_unix);
|
let expires = data.expires.map(naive_from_unix);
|
||||||
|
|
||||||
// Verify that only mods or admins can ban
|
// Verify that only mods or admins can ban
|
||||||
is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id).await?;
|
is_mod_or_admin(
|
||||||
|
&mut context.pool(),
|
||||||
|
local_user_view.person.id,
|
||||||
|
data.community_id,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
is_valid_body_field(&data.reason, false)?;
|
is_valid_body_field(&data.reason, false)?;
|
||||||
|
|
||||||
let community_user_ban_form = CommunityPersonBanForm {
|
let community_user_ban_form = CommunityPersonBanForm {
|
||||||
|
@ -78,7 +78,7 @@ impl Perform for BanFromCommunity {
|
||||||
|
|
||||||
// Remove/Restore their data if that's desired
|
// Remove/Restore their data if that's desired
|
||||||
if remove_data {
|
if remove_data {
|
||||||
remove_user_data_in_community(community_id, banned_person_id, &mut context.pool()).await?;
|
remove_user_data_in_community(data.community_id, banned_person_id, &mut context.pool()).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
|
@ -93,12 +93,21 @@ impl Perform for BanFromCommunity {
|
||||||
|
|
||||||
ModBanFromCommunity::create(&mut context.pool(), &form).await?;
|
ModBanFromCommunity::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
let person_id = data.person_id;
|
let person_view = PersonView::read(&mut context.pool(), data.person_id).await?;
|
||||||
let person_view = PersonView::read(&mut context.pool(), person_id).await?;
|
|
||||||
|
|
||||||
Ok(BanFromCommunityResponse {
|
ActivityChannel::submit_activity(
|
||||||
|
SendActivityData::BanFromCommunity(
|
||||||
|
local_user_view.person,
|
||||||
|
data.community_id,
|
||||||
|
person_view.person.clone(),
|
||||||
|
data.0.clone(),
|
||||||
|
),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(BanFromCommunityResponse {
|
||||||
person_view,
|
person_view,
|
||||||
banned: data.ban,
|
banned: data.ban,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::Perform;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{BlockCommunity, BlockCommunityResponse},
|
community::{BlockCommunity, BlockCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -15,17 +16,12 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views_actor::structs::CommunityView;
|
use lemmy_db_views_actor::structs::CommunityView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl Perform for BlockCommunity {
|
|
||||||
type Response = BlockCommunityResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(
|
pub async fn block_community(
|
||||||
&self,
|
data: Json<BlockCommunity>,
|
||||||
context: &Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<BlockCommunityResponse, LemmyError> {
|
) -> Result<Json<BlockCommunityResponse>, LemmyError> {
|
||||||
let data: &BlockCommunity = self;
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
@ -58,9 +54,18 @@ impl Perform for BlockCommunity {
|
||||||
let community_view =
|
let community_view =
|
||||||
CommunityView::read(&mut context.pool(), community_id, Some(person_id), None).await?;
|
CommunityView::read(&mut context.pool(), community_id, Some(person_id), None).await?;
|
||||||
|
|
||||||
Ok(BlockCommunityResponse {
|
ActivityChannel::submit_activity(
|
||||||
|
SendActivityData::FollowCommunity(
|
||||||
|
community_view.community.clone(),
|
||||||
|
local_user_view.person.clone(),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(BlockCommunityResponse {
|
||||||
blocked: data.block,
|
blocked: data.block,
|
||||||
community_view,
|
community_view,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::Perform;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_community_response,
|
build_response::build_community_response,
|
||||||
community::{CommunityResponse, HideCommunity},
|
community::{CommunityResponse, HideCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{is_admin, local_user_view_from_jwt, sanitize_html_opt},
|
utils::{is_admin, local_user_view_from_jwt, sanitize_html_opt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -15,16 +16,13 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl Perform for HideCommunity {
|
|
||||||
type Response = CommunityResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
|
pub async fn hide_community(
|
||||||
let data: &HideCommunity = self;
|
data: Json<HideCommunity>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<CommunityResponse>, LemmyError> {
|
||||||
// Verify its a admin (only admin can hide or unhide it)
|
// Verify its a admin (only admin can hide or unhide it)
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
let community_form = CommunityUpdateForm::builder()
|
let community_form = CommunityUpdateForm::builder()
|
||||||
|
@ -39,12 +37,17 @@ impl Perform for HideCommunity {
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
Community::update(&mut context.pool(), community_id, &community_form)
|
let community = Community::update(&mut context.pool(), community_id, &community_form)
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdateCommunityHiddenStatus)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateCommunityHiddenStatus)?;
|
||||||
|
|
||||||
ModHideCommunity::create(&mut context.pool(), &mod_hide_community_form).await?;
|
ModHideCommunity::create(&mut context.pool(), &mod_hide_community_form).await?;
|
||||||
|
|
||||||
build_community_response(context, local_user_view, community_id).await
|
ActivityChannel::submit_activity(
|
||||||
}
|
SendActivityData::UpdateCommunity(local_user_view.person.clone(), community),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
build_community_response(&context, local_user_view, community_id).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
mod add_mod;
|
pub mod add_mod;
|
||||||
mod ban;
|
pub mod ban;
|
||||||
mod block;
|
pub mod block;
|
||||||
pub mod follow;
|
pub mod follow;
|
||||||
mod hide;
|
pub mod hide;
|
||||||
mod transfer;
|
pub mod transfer;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::Perform;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{BanPerson, BanPersonResponse},
|
person::{BanPerson, BanPersonResponse},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{is_admin, local_user_view_from_jwt, remove_user_data, sanitize_html_opt},
|
utils::{is_admin, local_user_view_from_jwt, remove_user_data, sanitize_html_opt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -17,30 +18,25 @@ use lemmy_utils::{
|
||||||
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
|
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
|
||||||
utils::{time::naive_from_unix, validation::is_valid_body_field},
|
utils::{time::naive_from_unix, validation::is_valid_body_field},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl Perform for BanPerson {
|
|
||||||
type Response = BanPersonResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<BanPersonResponse, LemmyError> {
|
pub async fn ban_from_site(
|
||||||
let data: &BanPerson = self;
|
data: Json<BanPerson>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<BanPersonResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
is_valid_body_field(&data.reason, false)?;
|
is_valid_body_field(&data.reason, false)?;
|
||||||
|
|
||||||
let ban = data.ban;
|
|
||||||
let banned_person_id = data.person_id;
|
|
||||||
let expires = data.expires.map(naive_from_unix);
|
let expires = data.expires.map(naive_from_unix);
|
||||||
|
|
||||||
let person = Person::update(
|
let person = Person::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
banned_person_id,
|
data.person_id,
|
||||||
&PersonUpdateForm::builder()
|
&PersonUpdateForm::builder()
|
||||||
.banned(Some(ban))
|
.banned(Some(data.ban))
|
||||||
.ban_expires(Some(expires))
|
.ban_expires(Some(expires))
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
|
@ -70,12 +66,20 @@ impl Perform for BanPerson {
|
||||||
|
|
||||||
ModBan::create(&mut context.pool(), &form).await?;
|
ModBan::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
let person_id = data.person_id;
|
let person_view = PersonView::read(&mut context.pool(), data.person_id).await?;
|
||||||
let person_view = PersonView::read(&mut context.pool(), person_id).await?;
|
|
||||||
|
|
||||||
Ok(BanPersonResponse {
|
ActivityChannel::submit_activity(
|
||||||
|
SendActivityData::BanFromSite(
|
||||||
|
local_user_view.person,
|
||||||
|
person_view.person.clone(),
|
||||||
|
data.0.clone(),
|
||||||
|
),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(BanPersonResponse {
|
||||||
person_view,
|
person_view,
|
||||||
banned: data.ban,
|
banned: data.ban,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::Perform;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_post_response,
|
build_response::build_post_response,
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{FeaturePost, PostResponse},
|
post::{FeaturePost, PostResponse},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
|
@ -22,14 +23,12 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl Perform for FeaturePost {
|
|
||||||
type Response = PostResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
|
pub async fn feature_post(
|
||||||
let data: &FeaturePost = self;
|
data: Json<FeaturePost>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<PostResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
|
@ -65,7 +64,7 @@ impl Perform for FeaturePost {
|
||||||
.featured_local(Some(data.featured))
|
.featured_local(Some(data.featured))
|
||||||
.build()
|
.build()
|
||||||
};
|
};
|
||||||
Post::update(&mut context.pool(), post_id, &new_post).await?;
|
let post = Post::update(&mut context.pool(), post_id, &new_post).await?;
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModFeaturePostForm {
|
let form = ModFeaturePostForm {
|
||||||
|
@ -77,12 +76,12 @@ impl Perform for FeaturePost {
|
||||||
|
|
||||||
ModFeaturePost::create(&mut context.pool(), &form).await?;
|
ModFeaturePost::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
build_post_response(
|
let person_id = local_user_view.person.id;
|
||||||
context,
|
ActivityChannel::submit_activity(
|
||||||
orig_post.community_id,
|
SendActivityData::FeaturePost(post, local_user_view.person, data.featured),
|
||||||
local_user_view.person.id,
|
&context,
|
||||||
post_id,
|
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
}
|
|
||||||
|
build_post_response(&context, orig_post.community_id, person_id, post_id).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,13 +80,11 @@ pub async fn like_post(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Json(
|
|
||||||
build_post_response(
|
build_post_response(
|
||||||
context.deref(),
|
context.deref(),
|
||||||
post.community_id,
|
post.community_id,
|
||||||
local_user_view.person.id,
|
local_user_view.person.id,
|
||||||
post_id,
|
post_id,
|
||||||
)
|
)
|
||||||
.await?,
|
.await
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::Perform;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_post_response,
|
build_response::build_post_response,
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{LockPost, PostResponse},
|
post::{LockPost, PostResponse},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
|
@ -20,14 +21,12 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl Perform for LockPost {
|
|
||||||
type Response = PostResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
|
pub async fn lock_post(
|
||||||
let data: &LockPost = self;
|
data: Json<LockPost>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<PostResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
|
@ -51,7 +50,7 @@ impl Perform for LockPost {
|
||||||
// Update the post
|
// Update the post
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let locked = data.locked;
|
let locked = data.locked;
|
||||||
Post::update(
|
let post = Post::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
post_id,
|
post_id,
|
||||||
&PostUpdateForm::builder().locked(Some(locked)).build(),
|
&PostUpdateForm::builder().locked(Some(locked)).build(),
|
||||||
|
@ -66,12 +65,12 @@ impl Perform for LockPost {
|
||||||
};
|
};
|
||||||
ModLockPost::create(&mut context.pool(), &form).await?;
|
ModLockPost::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
build_post_response(
|
let person_id = local_user_view.person.id;
|
||||||
context,
|
ActivityChannel::submit_activity(
|
||||||
orig_post.community_id,
|
SendActivityData::LockPost(post, local_user_view.person, data.locked),
|
||||||
local_user_view.person.id,
|
&context,
|
||||||
post_id,
|
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
}
|
|
||||||
|
build_post_response(&context, orig_post.community_id, person_id, post_id).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use crate::{check_report_reason, Perform};
|
use crate::check_report_reason;
|
||||||
use actix_web::web::Data;
|
use activitypub_federation::config::Data;
|
||||||
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{CreatePostReport, PostReportResponse},
|
post::{CreatePostReport, PostReportResponse},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
local_user_view_from_jwt,
|
local_user_view_from_jwt,
|
||||||
|
@ -21,17 +23,15 @@ use lemmy_db_views::structs::{PostReportView, PostView};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
/// 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)]
|
|
||||||
impl Perform for CreatePostReport {
|
|
||||||
type Response = PostReportResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostReportResponse, LemmyError> {
|
pub async fn create_post_report(
|
||||||
let data: &CreatePostReport = self;
|
data: Json<CreatePostReport>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<PostReportResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
let reason = sanitize_html(self.reason.trim());
|
let reason = sanitize_html(data.reason.trim());
|
||||||
check_report_reason(&reason, &local_site)?;
|
check_report_reason(&reason, &local_site)?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
@ -66,6 +66,16 @@ impl Perform for CreatePostReport {
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(PostReportResponse { post_report_view })
|
ActivityChannel::submit_activity(
|
||||||
}
|
SendActivityData::CreateReport(
|
||||||
|
post_view.post.ap_id.inner().clone(),
|
||||||
|
local_user_view.person,
|
||||||
|
post_view.community,
|
||||||
|
data.reason.clone(),
|
||||||
|
),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(PostReportResponse { post_report_view }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
mod create;
|
pub mod create;
|
||||||
mod list;
|
pub mod list;
|
||||||
mod resolve;
|
pub mod resolve;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
post::PostResponse,
|
post::PostResponse,
|
||||||
utils::{check_person_block, get_interface_language, is_mod_or_admin, send_email_to_user},
|
utils::{check_person_block, get_interface_language, is_mod_or_admin, send_email_to_user},
|
||||||
};
|
};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId},
|
newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId},
|
||||||
source::{
|
source::{
|
||||||
|
@ -39,10 +39,10 @@ pub async fn build_comment_response(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn build_community_response(
|
pub async fn build_community_response(
|
||||||
context: &Data<LemmyContext>,
|
context: &LemmyContext,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<Json<CommunityResponse>, LemmyError> {
|
||||||
let is_mod_or_admin =
|
let is_mod_or_admin =
|
||||||
is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id)
|
is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id)
|
||||||
.await
|
.await
|
||||||
|
@ -57,10 +57,10 @@ pub async fn build_community_response(
|
||||||
.await?;
|
.await?;
|
||||||
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
||||||
|
|
||||||
Ok(CommunityResponse {
|
Ok(Json(CommunityResponse {
|
||||||
community_view,
|
community_view,
|
||||||
discussion_languages,
|
discussion_languages,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn build_post_response(
|
pub async fn build_post_response(
|
||||||
|
@ -68,7 +68,7 @@ pub async fn build_post_response(
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<Json<PostResponse>, LemmyError> {
|
||||||
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person_id, community_id)
|
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person_id, community_id)
|
||||||
.await
|
.await
|
||||||
.is_ok();
|
.is_ok();
|
||||||
|
@ -79,7 +79,7 @@ pub async fn build_post_response(
|
||||||
Some(is_mod_or_admin),
|
Some(is_mod_or_admin),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(PostResponse { post_view })
|
Ok(Json(PostResponse { post_view }))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this function is a mess and should be split up to handle email seperately
|
// TODO: this function is a mess and should be split up to handle email seperately
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
use crate::context::LemmyContext;
|
use crate::{
|
||||||
|
community::BanFromCommunity,
|
||||||
|
context::LemmyContext,
|
||||||
|
person::BanPerson,
|
||||||
|
post::{DeletePost, RemovePost},
|
||||||
|
};
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::DbUrl,
|
newtypes::{CommunityId, DbUrl, PersonId},
|
||||||
source::{comment::Comment, community::Community, person::Person, post::Post},
|
source::{
|
||||||
|
comment::Comment,
|
||||||
|
community::Community,
|
||||||
|
person::Person,
|
||||||
|
post::Post,
|
||||||
|
private_message::PrivateMessage,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
use lemmy_db_views::structs::PrivateMessageView;
|
||||||
use lemmy_utils::{error::LemmyResult, SYNCHRONOUS_FEDERATION};
|
use lemmy_utils::{error::LemmyResult, SYNCHRONOUS_FEDERATION};
|
||||||
use once_cell::sync::{Lazy, OnceCell};
|
use once_cell::sync::{Lazy, OnceCell};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
|
@ -15,6 +27,7 @@ use tokio::{
|
||||||
},
|
},
|
||||||
task::JoinHandle,
|
task::JoinHandle,
|
||||||
};
|
};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
type MatchOutgoingActivitiesBoxed =
|
type MatchOutgoingActivitiesBoxed =
|
||||||
Box<for<'a> fn(SendActivityData, &'a Data<LemmyContext>) -> BoxFuture<'a, LemmyResult<()>>>;
|
Box<for<'a> fn(SendActivityData, &'a Data<LemmyContext>) -> BoxFuture<'a, LemmyResult<()>>>;
|
||||||
|
@ -26,12 +39,27 @@ pub static MATCH_OUTGOING_ACTIVITIES: OnceCell<MatchOutgoingActivitiesBoxed> = O
|
||||||
pub enum SendActivityData {
|
pub enum SendActivityData {
|
||||||
CreatePost(Post),
|
CreatePost(Post),
|
||||||
UpdatePost(Post),
|
UpdatePost(Post),
|
||||||
|
DeletePost(Post, Person, DeletePost),
|
||||||
|
RemovePost(Post, Person, RemovePost),
|
||||||
|
LockPost(Post, Person, bool),
|
||||||
|
FeaturePost(Post, Person, bool),
|
||||||
CreateComment(Comment),
|
CreateComment(Comment),
|
||||||
|
UpdateComment(Comment),
|
||||||
DeleteComment(Comment, Person, Community),
|
DeleteComment(Comment, Person, Community),
|
||||||
RemoveComment(Comment, Person, Community, Option<String>),
|
RemoveComment(Comment, Person, Community, Option<String>),
|
||||||
UpdateComment(Comment),
|
|
||||||
LikePostOrComment(DbUrl, Person, Community, i16),
|
LikePostOrComment(DbUrl, Person, Community, i16),
|
||||||
FollowCommunity(Community, Person, bool),
|
FollowCommunity(Community, Person, bool),
|
||||||
|
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),
|
||||||
|
DeleteUser(Person),
|
||||||
|
CreateReport(Url, Person, Community, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: instead of static, move this into LemmyContext. make sure that stopping the process with
|
// TODO: instead of static, move this into LemmyContext. make sure that stopping the process with
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::{config::Data, http_signatures::generate_actor_keypair};
|
||||||
use activitypub_federation::http_signatures::generate_actor_keypair;
|
use actix_web::web::Json;
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_community_response,
|
build_response::build_community_response,
|
||||||
community::{CommunityResponse, CreateCommunity},
|
community::{CommunityResponse, CreateCommunity},
|
||||||
|
@ -42,14 +41,12 @@ use lemmy_utils::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl PerformCrud for CreateCommunity {
|
|
||||||
type Response = CommunityResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
|
pub async fn create_community(
|
||||||
let data: &CreateCommunity = self;
|
data: Json<CreateCommunity>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<CommunityResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||||
let local_site = site_view.local_site;
|
let local_site = site_view.local_site;
|
||||||
|
|
||||||
|
@ -143,6 +140,5 @@ impl PerformCrud for CreateCommunity {
|
||||||
CommunityLanguage::update(&mut context.pool(), languages, community_id).await?;
|
CommunityLanguage::update(&mut context.pool(), languages, community_id).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
build_community_response(context, local_user_view, community_id).await
|
build_community_response(&context, local_user_view, community_id).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_community_response,
|
build_response::build_community_response,
|
||||||
community::{CommunityResponse, DeleteCommunity},
|
community::{CommunityResponse, DeleteCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{is_top_mod, local_user_view_from_jwt},
|
utils::{is_top_mod, local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -13,14 +14,12 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl PerformCrud for DeleteCommunity {
|
|
||||||
type Response = CommunityResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
|
pub async fn delete_community(
|
||||||
let data: &DeleteCommunity = self;
|
data: Json<DeleteCommunity>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<CommunityResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
|
|
||||||
// Fetch the community mods
|
// Fetch the community mods
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
@ -33,7 +32,7 @@ impl PerformCrud for DeleteCommunity {
|
||||||
// Do the delete
|
// Do the delete
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let deleted = data.deleted;
|
let deleted = data.deleted;
|
||||||
Community::update(
|
let community = Community::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
community_id,
|
community_id,
|
||||||
&CommunityUpdateForm::builder()
|
&CommunityUpdateForm::builder()
|
||||||
|
@ -43,6 +42,11 @@ impl PerformCrud for DeleteCommunity {
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?;
|
||||||
|
|
||||||
build_community_response(context, local_user_view, community_id).await
|
ActivityChannel::submit_activity(
|
||||||
}
|
SendActivityData::DeleteCommunity(local_user_view.person.clone(), community, data.deleted),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
build_community_response(&context, local_user_view, community_id).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_community_response,
|
build_response::build_community_response,
|
||||||
community::{CommunityResponse, RemoveCommunity},
|
community::{CommunityResponse, RemoveCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{is_admin, local_user_view_from_jwt},
|
utils::{is_admin, local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -18,14 +19,12 @@ use lemmy_utils::{
|
||||||
utils::time::naive_from_unix,
|
utils::time::naive_from_unix,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl PerformCrud for RemoveCommunity {
|
|
||||||
type Response = CommunityResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
|
pub async fn remove_community(
|
||||||
let data: &RemoveCommunity = self;
|
data: Json<RemoveCommunity>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<CommunityResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
|
|
||||||
// Verify its an admin (only an admin can remove a community)
|
// Verify its an admin (only an admin can remove a community)
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
@ -33,7 +32,7 @@ impl PerformCrud for RemoveCommunity {
|
||||||
// Do the remove
|
// Do the remove
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let removed = data.removed;
|
let removed = data.removed;
|
||||||
Community::update(
|
let community = Community::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
community_id,
|
community_id,
|
||||||
&CommunityUpdateForm::builder()
|
&CommunityUpdateForm::builder()
|
||||||
|
@ -54,6 +53,16 @@ impl PerformCrud for RemoveCommunity {
|
||||||
};
|
};
|
||||||
ModRemoveCommunity::create(&mut context.pool(), &form).await?;
|
ModRemoveCommunity::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
build_community_response(context, local_user_view, community_id).await
|
ActivityChannel::submit_activity(
|
||||||
}
|
SendActivityData::RemoveCommunity(
|
||||||
|
local_user_view.person.clone(),
|
||||||
|
community,
|
||||||
|
data.reason.clone(),
|
||||||
|
data.removed,
|
||||||
|
),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
build_community_response(&context, local_user_view, community_id).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_community_response,
|
build_response::build_community_response,
|
||||||
community::{CommunityResponse, EditCommunity},
|
community::{CommunityResponse, EditCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{local_site_to_slur_regex, local_user_view_from_jwt, sanitize_html_opt},
|
utils::{local_site_to_slur_regex, local_user_view_from_jwt, sanitize_html_opt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -22,14 +23,12 @@ use lemmy_utils::{
|
||||||
utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
|
utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl PerformCrud for EditCommunity {
|
|
||||||
type Response = CommunityResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
|
pub async fn update_community(
|
||||||
let data: &EditCommunity = self;
|
data: Json<EditCommunity>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<CommunityResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
let slur_regex = local_site_to_slur_regex(&local_site);
|
let slur_regex = local_site_to_slur_regex(&local_site);
|
||||||
|
@ -77,10 +76,15 @@ impl PerformCrud for EditCommunity {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
Community::update(&mut context.pool(), community_id, &community_form)
|
let community = Community::update(&mut context.pool(), community_id, &community_form)
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?;
|
||||||
|
|
||||||
build_community_response(context, local_user_view, community_id).await
|
ActivityChannel::submit_activity(
|
||||||
}
|
SendActivityData::UpdateCommunity(local_user_view.person.clone(), community),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
build_community_response(&context, local_user_view, community_id).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
custom_emoji::{CreateCustomEmoji, CustomEmojiResponse},
|
custom_emoji::{CreateCustomEmoji, CustomEmojiResponse},
|
||||||
|
@ -13,14 +13,12 @@ use lemmy_db_schema::source::{
|
||||||
use lemmy_db_views::structs::CustomEmojiView;
|
use lemmy_db_views::structs::CustomEmojiView;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for CreateCustomEmoji {
|
pub async fn create_custom_emoji(
|
||||||
type Response = CustomEmojiResponse;
|
data: Json<CreateCustomEmoji>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<CustomEmojiResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CustomEmojiResponse, LemmyError> {
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let data: &CreateCustomEmoji = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
|
@ -48,6 +46,5 @@ impl PerformCrud for CreateCustomEmoji {
|
||||||
}
|
}
|
||||||
CustomEmojiKeyword::create(&mut context.pool(), keywords).await?;
|
CustomEmojiKeyword::create(&mut context.pool(), keywords).await?;
|
||||||
let view = CustomEmojiView::get(&mut context.pool(), emoji.id).await?;
|
let view = CustomEmojiView::get(&mut context.pool(), emoji.id).await?;
|
||||||
Ok(CustomEmojiResponse { custom_emoji: view })
|
Ok(Json(CustomEmojiResponse { custom_emoji: view }))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
custom_emoji::{DeleteCustomEmoji, DeleteCustomEmojiResponse},
|
custom_emoji::{DeleteCustomEmoji, DeleteCustomEmojiResponse},
|
||||||
|
@ -8,24 +8,18 @@ use lemmy_api_common::{
|
||||||
use lemmy_db_schema::source::custom_emoji::CustomEmoji;
|
use lemmy_db_schema::source::custom_emoji::CustomEmoji;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for DeleteCustomEmoji {
|
pub async fn delete_custom_emoji(
|
||||||
type Response = DeleteCustomEmojiResponse;
|
data: Json<DeleteCustomEmoji>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<DeleteCustomEmojiResponse>, LemmyError> {
|
||||||
async fn perform(
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
&self,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<DeleteCustomEmojiResponse, LemmyError> {
|
|
||||||
let data: &DeleteCustomEmoji = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
CustomEmoji::delete(&mut context.pool(), data.id).await?;
|
CustomEmoji::delete(&mut context.pool(), data.id).await?;
|
||||||
Ok(DeleteCustomEmojiResponse {
|
Ok(Json(DeleteCustomEmojiResponse {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
success: true,
|
success: true,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
mod create;
|
pub mod create;
|
||||||
mod delete;
|
pub mod delete;
|
||||||
mod update;
|
pub mod update;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
custom_emoji::{CustomEmojiResponse, EditCustomEmoji},
|
custom_emoji::{CustomEmojiResponse, EditCustomEmoji},
|
||||||
|
@ -13,14 +13,12 @@ use lemmy_db_schema::source::{
|
||||||
use lemmy_db_views::structs::CustomEmojiView;
|
use lemmy_db_views::structs::CustomEmojiView;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for EditCustomEmoji {
|
pub async fn update_custom_emoji(
|
||||||
type Response = CustomEmojiResponse;
|
data: Json<EditCustomEmoji>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<CustomEmojiResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CustomEmojiResponse, LemmyError> {
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let data: &EditCustomEmoji = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
|
@ -47,6 +45,5 @@ impl PerformCrud for EditCustomEmoji {
|
||||||
}
|
}
|
||||||
CustomEmojiKeyword::create(&mut context.pool(), keywords).await?;
|
CustomEmojiKeyword::create(&mut context.pool(), keywords).await?;
|
||||||
let view = CustomEmojiView::get(&mut context.pool(), emoji.id).await?;
|
let view = CustomEmojiView::get(&mut context.pool(), emoji.id).await?;
|
||||||
Ok(CustomEmojiResponse { custom_emoji: view })
|
Ok(Json(CustomEmojiResponse { custom_emoji: view }))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::context::LemmyContext;
|
|
||||||
use lemmy_utils::error::LemmyError;
|
|
||||||
|
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
pub mod community;
|
pub mod community;
|
||||||
pub mod custom_emoji;
|
pub mod custom_emoji;
|
||||||
|
@ -9,10 +5,3 @@ pub mod post;
|
||||||
pub mod private_message;
|
pub mod private_message;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
pub trait PerformCrud {
|
|
||||||
type Response: serde::ser::Serialize + Send + Clone + Sync;
|
|
||||||
|
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
|
|
||||||
}
|
|
||||||
|
|
|
@ -194,7 +194,5 @@ pub async fn create_post(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Json(
|
build_post_response(&context, community_id, person_id, post_id).await
|
||||||
build_post_response(&context, community_id, person_id, post_id).await?,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_post_response,
|
build_response::build_post_response,
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{DeletePost, PostResponse},
|
post::{DeletePost, PostResponse},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, check_community_deleted_or_removed, local_user_view_from_jwt},
|
utils::{check_community_ban, check_community_deleted_or_removed, local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -12,14 +13,12 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl PerformCrud for DeletePost {
|
|
||||||
type Response = PostResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
|
pub async fn delete_post(
|
||||||
let data: &DeletePost = self;
|
data: Json<DeletePost>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<PostResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
|
@ -43,21 +42,21 @@ impl PerformCrud for DeletePost {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the post
|
// Update the post
|
||||||
let post_id = data.post_id;
|
let post = Post::update(
|
||||||
let deleted = data.deleted;
|
|
||||||
Post::update(
|
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
post_id,
|
data.post_id,
|
||||||
&PostUpdateForm::builder().deleted(Some(deleted)).build(),
|
&PostUpdateForm::builder()
|
||||||
|
.deleted(Some(data.deleted))
|
||||||
|
.build(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
build_post_response(
|
let person_id = local_user_view.person.id;
|
||||||
context,
|
ActivityChannel::submit_activity(
|
||||||
orig_post.community_id,
|
SendActivityData::DeletePost(post, local_user_view.person, data.0.clone()),
|
||||||
local_user_view.person.id,
|
&context,
|
||||||
post_id,
|
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
}
|
|
||||||
|
build_post_response(&context, orig_post.community_id, person_id, data.post_id).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_post_response,
|
build_response::build_post_response,
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{PostResponse, RemovePost},
|
post::{PostResponse, RemovePost},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt},
|
utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -15,14 +16,12 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
|
||||||
impl PerformCrud for RemovePost {
|
|
||||||
type Response = PostResponse;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
|
pub async fn remove_post(
|
||||||
let data: &RemovePost = self;
|
data: Json<RemovePost>,
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<PostResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
|
@ -45,7 +44,7 @@ impl PerformCrud for RemovePost {
|
||||||
// Update the post
|
// Update the post
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let removed = data.removed;
|
let removed = data.removed;
|
||||||
Post::update(
|
let post = Post::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
post_id,
|
post_id,
|
||||||
&PostUpdateForm::builder().removed(Some(removed)).build(),
|
&PostUpdateForm::builder().removed(Some(removed)).build(),
|
||||||
|
@ -61,12 +60,12 @@ impl PerformCrud for RemovePost {
|
||||||
};
|
};
|
||||||
ModRemovePost::create(&mut context.pool(), &form).await?;
|
ModRemovePost::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
build_post_response(
|
let person_id = local_user_view.person.id;
|
||||||
context,
|
ActivityChannel::submit_activity(
|
||||||
orig_post.community_id,
|
SendActivityData::RemovePost(post, local_user_view.person, data.0),
|
||||||
local_user_view.person.id,
|
&context,
|
||||||
post_id,
|
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
}
|
|
||||||
|
build_post_response(&context, orig_post.community_id, person_id, post_id).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,13 +113,11 @@ pub async fn update_post(
|
||||||
|
|
||||||
ActivityChannel::submit_activity(SendActivityData::UpdatePost(updated_post), &context).await?;
|
ActivityChannel::submit_activity(SendActivityData::UpdatePost(updated_post), &context).await?;
|
||||||
|
|
||||||
Ok(Json(
|
|
||||||
build_post_response(
|
build_post_response(
|
||||||
context.deref(),
|
context.deref(),
|
||||||
orig_post.community_id,
|
orig_post.community_id,
|
||||||
local_user_view.person.id,
|
local_user_view.person.id,
|
||||||
post_id,
|
post_id,
|
||||||
)
|
)
|
||||||
.await?,
|
.await
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{CreatePrivateMessage, PrivateMessageResponse},
|
private_message::{CreatePrivateMessage, PrivateMessageResponse},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_person_block,
|
check_person_block,
|
||||||
generate_local_apub_endpoint,
|
generate_local_apub_endpoint,
|
||||||
|
@ -27,17 +28,12 @@ use lemmy_utils::{
|
||||||
utils::{slurs::remove_slurs, validation::is_valid_body_field},
|
utils::{slurs::remove_slurs, validation::is_valid_body_field},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for CreatePrivateMessage {
|
pub async fn create_private_message(
|
||||||
type Response = PrivateMessageResponse;
|
data: Json<CreatePrivateMessage>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<PrivateMessageResponse>, LemmyError> {
|
||||||
async fn perform(
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
&self,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
|
||||||
let data: &CreatePrivateMessage = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
let content = sanitize_html(&data.content);
|
let content = sanitize_html(&data.content);
|
||||||
|
@ -57,8 +53,7 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
.recipient_id(data.recipient_id)
|
.recipient_id(data.recipient_id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_private_message =
|
let inserted_private_message = PrivateMessage::create(&mut context.pool(), &private_message_form)
|
||||||
PrivateMessage::create(&mut context.pool(), &private_message_form)
|
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntCreatePrivateMessage)?;
|
.with_lemmy_type(LemmyErrorType::CouldntCreatePrivateMessage)?;
|
||||||
|
|
||||||
|
@ -97,8 +92,13 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(PrivateMessageResponse {
|
ActivityChannel::submit_activity(
|
||||||
|
SendActivityData::CreatePrivateMessage(view.clone()),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(PrivateMessageResponse {
|
||||||
private_message_view: view,
|
private_message_view: view,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -12,22 +13,16 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views::structs::PrivateMessageView;
|
use lemmy_db_views::structs::PrivateMessageView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for DeletePrivateMessage {
|
pub async fn delete_private_message(
|
||||||
type Response = PrivateMessageResponse;
|
data: Json<DeletePrivateMessage>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<PrivateMessageResponse>, LemmyError> {
|
||||||
async fn perform(
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
&self,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
|
||||||
let data: &DeletePrivateMessage = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
let orig_private_message =
|
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||||
PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
|
||||||
if local_user_view.person.id != orig_private_message.creator_id {
|
if local_user_view.person.id != orig_private_message.creator_id {
|
||||||
return Err(LemmyErrorType::EditPrivateMessageNotAllowed)?;
|
return Err(LemmyErrorType::EditPrivateMessageNotAllowed)?;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +30,7 @@ impl PerformCrud for DeletePrivateMessage {
|
||||||
// Doing the update
|
// Doing the update
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
let deleted = data.deleted;
|
let deleted = data.deleted;
|
||||||
PrivateMessage::update(
|
let private_message = PrivateMessage::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
private_message_id,
|
private_message_id,
|
||||||
&PrivateMessageUpdateForm::builder()
|
&PrivateMessageUpdateForm::builder()
|
||||||
|
@ -45,9 +40,14 @@ impl PerformCrud for DeletePrivateMessage {
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
||||||
|
|
||||||
|
ActivityChannel::submit_activity(
|
||||||
|
SendActivityData::DeletePrivateMessage(local_user_view.person, private_message, data.deleted),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
||||||
Ok(PrivateMessageResponse {
|
Ok(Json(PrivateMessageResponse {
|
||||||
private_message_view: view,
|
private_message_view: view,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{EditPrivateMessage, PrivateMessageResponse},
|
private_message::{EditPrivateMessage, PrivateMessageResponse},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{local_site_to_slur_regex, local_user_view_from_jwt, sanitize_html},
|
utils::{local_site_to_slur_regex, local_user_view_from_jwt, sanitize_html},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -19,23 +20,17 @@ use lemmy_utils::{
|
||||||
utils::{slurs::remove_slurs, validation::is_valid_body_field},
|
utils::{slurs::remove_slurs, validation::is_valid_body_field},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for EditPrivateMessage {
|
pub async fn update_private_message(
|
||||||
type Response = PrivateMessageResponse;
|
data: Json<EditPrivateMessage>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<PrivateMessageResponse>, LemmyError> {
|
||||||
async fn perform(
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
&self,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
|
||||||
let data: &EditPrivateMessage = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
let orig_private_message =
|
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||||
PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
|
||||||
if local_user_view.person.id != orig_private_message.creator_id {
|
if local_user_view.person.id != orig_private_message.creator_id {
|
||||||
return Err(LemmyErrorType::EditPrivateMessageNotAllowed)?;
|
return Err(LemmyErrorType::EditPrivateMessageNotAllowed)?;
|
||||||
}
|
}
|
||||||
|
@ -59,8 +54,13 @@ impl PerformCrud for EditPrivateMessage {
|
||||||
|
|
||||||
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
||||||
|
|
||||||
Ok(PrivateMessageResponse {
|
ActivityChannel::submit_activity(
|
||||||
|
SendActivityData::UpdatePrivateMessage(view.clone()),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(PrivateMessageResponse {
|
||||||
private_message_view: view,
|
private_message_view: view,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::{config::Data, http_signatures::generate_actor_keypair};
|
||||||
use activitypub_federation::http_signatures::generate_actor_keypair;
|
use actix_web::web::Json;
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{LoginResponse, Register},
|
person::{LoginResponse, Register},
|
||||||
|
@ -38,14 +37,11 @@ use lemmy_utils::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for Register {
|
pub async fn register(
|
||||||
type Response = LoginResponse;
|
data: Json<Register>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<LoginResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
|
|
||||||
let data: &Register = self;
|
|
||||||
|
|
||||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||||
let local_site = site_view.local_site;
|
let local_site = site_view.local_site;
|
||||||
let require_registration_application =
|
let require_registration_application =
|
||||||
|
@ -209,6 +205,5 @@ impl PerformCrud for Register {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(login_response)
|
Ok(Json(login_response))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use bcrypt::verify;
|
use bcrypt::verify;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{DeleteAccount, DeleteAccountResponse},
|
person::{DeleteAccount, DeleteAccountResponse},
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for DeleteAccount {
|
pub async fn delete_account(
|
||||||
type Response = DeleteAccountResponse;
|
data: Json<DeleteAccount>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<DeleteAccountResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), &context).await?;
|
||||||
let data = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
|
|
||||||
|
|
||||||
// Verify the password
|
// Verify the password
|
||||||
let valid: bool = verify(
|
let valid: bool = verify(
|
||||||
|
@ -27,6 +26,11 @@ impl PerformCrud for DeleteAccount {
|
||||||
return Err(LemmyErrorType::IncorrectLogin)?;
|
return Err(LemmyErrorType::IncorrectLogin)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(DeleteAccountResponse {})
|
ActivityChannel::submit_activity(
|
||||||
}
|
SendActivityData::DeleteUser(local_user_view.person),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(DeleteAccountResponse {}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
mod create;
|
pub mod create;
|
||||||
mod delete;
|
pub mod delete;
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{community::ApubCommunity, instance::ApubSite, person::ApubPerson},
|
objects::{community::ApubCommunity, instance::ApubSite},
|
||||||
protocol::{
|
protocol::{
|
||||||
activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
|
activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
|
||||||
objects::{group::Group, instance::Instance},
|
objects::{group::Group, instance::Instance},
|
||||||
},
|
},
|
||||||
SendActivity,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
|
@ -12,19 +11,18 @@ use activitypub_federation::{
|
||||||
traits::{Actor, Object},
|
traits::{Actor, Object},
|
||||||
};
|
};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{community::BanFromCommunity, context::LemmyContext, person::BanPerson};
|
||||||
community::{BanFromCommunity, BanFromCommunityResponse},
|
|
||||||
context::LemmyContext,
|
|
||||||
person::{BanPerson, BanPersonResponse},
|
|
||||||
utils::local_user_view_from_jwt,
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
newtypes::CommunityId,
|
||||||
source::{community::Community, person::Person, site::Site},
|
source::{community::Community, person::Person, site::Site},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbPool,
|
utils::DbPool,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::SiteView;
|
||||||
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix};
|
use lemmy_utils::{
|
||||||
|
error::{LemmyError, LemmyResult},
|
||||||
|
utils::time::naive_from_unix,
|
||||||
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -132,40 +130,35 @@ async fn generate_cc(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
pub(crate) async fn send_ban_from_site(
|
||||||
impl SendActivity for BanPerson {
|
mod_: Person,
|
||||||
type Response = BanPersonResponse;
|
banned_user: Person,
|
||||||
|
data: BanPerson,
|
||||||
async fn send_activity(
|
context: Data<LemmyContext>,
|
||||||
request: &Self,
|
|
||||||
_response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let person = Person::read(&mut context.pool(), request.person_id).await?;
|
|
||||||
let site = SiteOrCommunity::Site(SiteView::read_local(&mut context.pool()).await?.site.into());
|
let site = SiteOrCommunity::Site(SiteView::read_local(&mut context.pool()).await?.site.into());
|
||||||
let expires = request.expires.map(naive_from_unix);
|
let expires = data.expires.map(naive_from_unix);
|
||||||
|
|
||||||
// if the action affects a local user, federate to other instances
|
// if the action affects a local user, federate to other instances
|
||||||
if person.local {
|
if banned_user.local {
|
||||||
if request.ban {
|
if data.ban {
|
||||||
BlockUser::send(
|
BlockUser::send(
|
||||||
&site,
|
&site,
|
||||||
&person.into(),
|
&banned_user.into(),
|
||||||
&local_user_view.person.into(),
|
&mod_.into(),
|
||||||
request.remove_data.unwrap_or(false),
|
data.remove_data.unwrap_or(false),
|
||||||
request.reason.clone(),
|
data.reason.clone(),
|
||||||
expires,
|
expires,
|
||||||
context,
|
&context,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
UndoBlockUser::send(
|
UndoBlockUser::send(
|
||||||
&site,
|
&site,
|
||||||
&person.into(),
|
&banned_user.into(),
|
||||||
&local_user_view.person.into(),
|
&mod_.into(),
|
||||||
request.reason.clone(),
|
data.reason.clone(),
|
||||||
context,
|
&context,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -173,46 +166,38 @@ impl SendActivity for BanPerson {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
pub(crate) async fn send_ban_from_community(
|
||||||
impl SendActivity for BanFromCommunity {
|
mod_: Person,
|
||||||
type Response = BanFromCommunityResponse;
|
community_id: CommunityId,
|
||||||
|
banned_person: Person,
|
||||||
async fn send_activity(
|
data: BanFromCommunity,
|
||||||
request: &Self,
|
context: Data<LemmyContext>,
|
||||||
_response: &Self::Response,
|
) -> LemmyResult<()> {
|
||||||
context: &Data<LemmyContext>,
|
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let community: ApubCommunity = Community::read(&mut context.pool(), request.community_id)
|
|
||||||
.await?
|
.await?
|
||||||
.into();
|
.into();
|
||||||
let banned_person: ApubPerson = Person::read(&mut context.pool(), request.person_id)
|
let expires = data.expires.map(naive_from_unix);
|
||||||
.await?
|
|
||||||
.into();
|
|
||||||
let expires = request.expires.map(naive_from_unix);
|
|
||||||
|
|
||||||
if request.ban {
|
if data.ban {
|
||||||
BlockUser::send(
|
BlockUser::send(
|
||||||
&SiteOrCommunity::Community(community),
|
&SiteOrCommunity::Community(community),
|
||||||
&banned_person,
|
&banned_person.into(),
|
||||||
&local_user_view.person.clone().into(),
|
&mod_.into(),
|
||||||
request.remove_data.unwrap_or(false),
|
data.remove_data.unwrap_or(false),
|
||||||
request.reason.clone(),
|
data.reason.clone(),
|
||||||
expires,
|
expires,
|
||||||
context,
|
&context,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
UndoBlockUser::send(
|
UndoBlockUser::send(
|
||||||
&SiteOrCommunity::Community(community),
|
&SiteOrCommunity::Community(community),
|
||||||
&banned_person,
|
&banned_person.into(),
|
||||||
&local_user_view.person.clone().into(),
|
&mod_.into(),
|
||||||
request.reason.clone(),
|
data.reason.clone(),
|
||||||
context,
|
&context,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ use crate::{
|
||||||
activities::community::{collection_add::CollectionAdd, collection_remove::CollectionRemove},
|
activities::community::{collection_add::CollectionAdd, collection_remove::CollectionRemove},
|
||||||
InCommunity,
|
InCommunity,
|
||||||
},
|
},
|
||||||
SendActivity,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
|
@ -22,13 +21,12 @@ use activitypub_federation::{
|
||||||
traits::{ActivityHandler, Actor},
|
traits::{ActivityHandler, Actor},
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{AddModToCommunity, AddModToCommunityResponse},
|
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{FeaturePost, PostResponse},
|
utils::{generate_featured_url, generate_moderators_url},
|
||||||
utils::{generate_featured_url, generate_moderators_url, local_user_view_from_jwt},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
impls::community::CollectionType,
|
impls::community::CollectionType,
|
||||||
|
newtypes::{CommunityId, PersonId},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityModerator, CommunityModeratorForm},
|
community::{Community, CommunityModerator, CommunityModeratorForm},
|
||||||
moderator::{ModAddCommunity, ModAddCommunityForm},
|
moderator::{ModAddCommunity, ModAddCommunityForm},
|
||||||
|
@ -165,61 +163,41 @@ impl ActivityHandler for CollectionAdd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
pub(crate) async fn send_add_mod_to_community(
|
||||||
impl SendActivity for AddModToCommunity {
|
actor: Person,
|
||||||
type Response = AddModToCommunityResponse;
|
community_id: CommunityId,
|
||||||
|
updated_mod_id: PersonId,
|
||||||
async fn send_activity(
|
added: bool,
|
||||||
request: &Self,
|
context: Data<LemmyContext>,
|
||||||
_response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
let actor: ApubPerson = actor.into();
|
||||||
let community: ApubCommunity = Community::read(&mut context.pool(), request.community_id)
|
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
||||||
.await?
|
.await?
|
||||||
.into();
|
.into();
|
||||||
let updated_mod: ApubPerson = Person::read(&mut context.pool(), request.person_id)
|
let updated_mod: ApubPerson = Person::read(&mut context.pool(), updated_mod_id)
|
||||||
.await?
|
.await?
|
||||||
.into();
|
.into();
|
||||||
if request.added {
|
if added {
|
||||||
CollectionAdd::send_add_mod(
|
CollectionAdd::send_add_mod(&community, &updated_mod, &actor, &context).await
|
||||||
&community,
|
|
||||||
&updated_mod,
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
} else {
|
} else {
|
||||||
CollectionRemove::send_remove_mod(
|
CollectionRemove::send_remove_mod(&community, &updated_mod, &actor, &context).await
|
||||||
&community,
|
|
||||||
&updated_mod,
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
pub(crate) async fn send_feature_post(
|
||||||
impl SendActivity for FeaturePost {
|
post: Post,
|
||||||
type Response = PostResponse;
|
actor: Person,
|
||||||
|
featured: bool,
|
||||||
async fn send_activity(
|
context: Data<LemmyContext>,
|
||||||
request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
let actor: ApubPerson = actor.into();
|
||||||
let community = Community::read(&mut context.pool(), response.post_view.community.id)
|
let post: ApubPost = post.into();
|
||||||
|
let community = Community::read(&mut context.pool(), post.community_id)
|
||||||
.await?
|
.await?
|
||||||
.into();
|
.into();
|
||||||
let post = response.post_view.post.clone().into();
|
if featured {
|
||||||
let person = local_user_view.person.into();
|
CollectionAdd::send_add_featured_post(&community, &post, &actor, &context).await
|
||||||
if request.featured {
|
|
||||||
CollectionAdd::send_add_featured_post(&community, &post, &person, context).await
|
|
||||||
} else {
|
} else {
|
||||||
CollectionRemove::send_remove_featured_post(&community, &post, &person, context).await
|
CollectionRemove::send_remove_featured_post(&community, &post, &actor, &context).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,25 +9,23 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_lists::AnnouncableActivities,
|
activity_lists::AnnouncableActivities,
|
||||||
insert_received_activity,
|
insert_received_activity,
|
||||||
|
objects::community::ApubCommunity,
|
||||||
protocol::{
|
protocol::{
|
||||||
activities::community::lock_page::{LockPage, LockType, UndoLockPage},
|
activities::community::lock_page::{LockPage, LockType, UndoLockPage},
|
||||||
InCommunity,
|
InCommunity,
|
||||||
},
|
},
|
||||||
SendActivity,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
|
fetch::object_id::ObjectId,
|
||||||
kinds::{activity::UndoType, public},
|
kinds::{activity::UndoType, public},
|
||||||
traits::ActivityHandler,
|
traits::ActivityHandler,
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::context::LemmyContext;
|
||||||
context::LemmyContext,
|
|
||||||
post::{LockPost, PostResponse},
|
|
||||||
utils::local_user_view_from_jwt,
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
community::Community,
|
community::Community,
|
||||||
|
person::Person,
|
||||||
post::{Post, PostUpdateForm},
|
post::{Post, PostUpdateForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
|
@ -102,32 +100,30 @@ impl ActivityHandler for UndoLockPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
pub(crate) async fn send_lock_post(
|
||||||
impl SendActivity for LockPost {
|
post: Post,
|
||||||
type Response = PostResponse;
|
actor: Person,
|
||||||
|
locked: bool,
|
||||||
async fn send_activity(
|
context: Data<LemmyContext>,
|
||||||
request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
let community: ApubCommunity = Community::read(&mut context.pool(), post.community_id)
|
||||||
|
.await?
|
||||||
|
.into();
|
||||||
let id = generate_activity_id(
|
let id = generate_activity_id(
|
||||||
LockType::Lock,
|
LockType::Lock,
|
||||||
&context.settings().get_protocol_and_hostname(),
|
&context.settings().get_protocol_and_hostname(),
|
||||||
)?;
|
)?;
|
||||||
let community_id = response.post_view.community.actor_id.clone();
|
let community_id = community.actor_id.inner().clone();
|
||||||
let actor = local_user_view.person.actor_id.clone().into();
|
|
||||||
let lock = LockPage {
|
let lock = LockPage {
|
||||||
actor,
|
actor: actor.actor_id.clone().into(),
|
||||||
to: vec![public()],
|
to: vec![public()],
|
||||||
object: response.post_view.post.ap_id.clone().into(),
|
object: ObjectId::from(post.ap_id),
|
||||||
cc: vec![community_id.clone().into()],
|
cc: vec![community_id.clone()],
|
||||||
kind: LockType::Lock,
|
kind: LockType::Lock,
|
||||||
id,
|
id,
|
||||||
audience: Some(community_id.into()),
|
audience: Some(community_id.into()),
|
||||||
};
|
};
|
||||||
let activity = if request.locked {
|
let activity = if locked {
|
||||||
AnnouncableActivities::LockPost(lock)
|
AnnouncableActivities::LockPost(lock)
|
||||||
} else {
|
} else {
|
||||||
let id = generate_activity_id(
|
let id = generate_activity_id(
|
||||||
|
@ -145,16 +141,6 @@ impl SendActivity for LockPost {
|
||||||
};
|
};
|
||||||
AnnouncableActivities::UndoLockPost(undo)
|
AnnouncableActivities::UndoLockPost(undo)
|
||||||
};
|
};
|
||||||
let community = Community::read(&mut context.pool(), response.post_view.community.id).await?;
|
send_activity_in_community(activity, &actor.into(), &community, vec![], true, &context).await?;
|
||||||
send_activity_in_community(
|
|
||||||
activity,
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
&community.into(),
|
|
||||||
vec![],
|
|
||||||
true,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ use crate::{
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
protocol::{activities::community::report::Report, InCommunity},
|
protocol::{activities::community::report::Report, InCommunity},
|
||||||
PostOrComment,
|
PostOrComment,
|
||||||
SendActivity,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
|
@ -12,15 +11,12 @@ use activitypub_federation::{
|
||||||
kinds::activity::FlagType,
|
kinds::activity::FlagType,
|
||||||
traits::{ActivityHandler, Actor},
|
traits::{ActivityHandler, Actor},
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{context::LemmyContext, utils::sanitize_html};
|
||||||
comment::{CommentReportResponse, CreateCommentReport},
|
|
||||||
context::LemmyContext,
|
|
||||||
post::{CreatePostReport, PostReportResponse},
|
|
||||||
utils::{local_user_view_from_jwt, sanitize_html},
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
comment_report::{CommentReport, CommentReportForm},
|
comment_report::{CommentReport, CommentReportForm},
|
||||||
|
community::Community,
|
||||||
|
person::Person,
|
||||||
post_report::{PostReport, PostReportForm},
|
post_report::{PostReport, PostReportForm},
|
||||||
},
|
},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
|
@ -28,58 +24,17 @@ use lemmy_db_schema::{
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for CreatePostReport {
|
|
||||||
type Response = PostReportResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
Report::send(
|
|
||||||
ObjectId::from(response.post_report_view.post.ap_id.clone()),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
ObjectId::from(response.post_report_view.community.actor_id.clone()),
|
|
||||||
request.reason.to_string(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for CreateCommentReport {
|
|
||||||
type Response = CommentReportResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
Report::send(
|
|
||||||
ObjectId::from(response.comment_report_view.comment.ap_id.clone()),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
ObjectId::from(response.comment_report_view.community.actor_id.clone()),
|
|
||||||
request.reason.to_string(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Report {
|
impl Report {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn send(
|
pub(crate) async fn send(
|
||||||
object_id: ObjectId<PostOrComment>,
|
object_id: ObjectId<PostOrComment>,
|
||||||
actor: &ApubPerson,
|
actor: Person,
|
||||||
community_id: ObjectId<ApubCommunity>,
|
community: Community,
|
||||||
reason: String,
|
reason: String,
|
||||||
context: &Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community = community_id.dereference_local(context).await?;
|
let actor: ApubPerson = actor.into();
|
||||||
|
let community: ApubCommunity = community.into();
|
||||||
let kind = FlagType::Flag;
|
let kind = FlagType::Flag;
|
||||||
let id = generate_activity_id(
|
let id = generate_activity_id(
|
||||||
kind.clone(),
|
kind.clone(),
|
||||||
|
@ -96,7 +51,7 @@ impl Report {
|
||||||
};
|
};
|
||||||
|
|
||||||
let inbox = vec![community.shared_inbox_or_inbox()];
|
let inbox = vec![community.shared_inbox_or_inbox()];
|
||||||
send_lemmy_activity(context, report, actor, inbox, false).await
|
send_lemmy_activity(&context, report, &actor, inbox, false).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,44 +10,27 @@ use crate::{
|
||||||
insert_received_activity,
|
insert_received_activity,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
protocol::{activities::community::update::UpdateCommunity, InCommunity},
|
protocol::{activities::community::update::UpdateCommunity, InCommunity},
|
||||||
SendActivity,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
kinds::{activity::UpdateType, public},
|
kinds::{activity::UpdateType, public},
|
||||||
traits::{ActivityHandler, Actor, Object},
|
traits::{ActivityHandler, Actor, Object},
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::context::LemmyContext;
|
||||||
community::{CommunityResponse, EditCommunity, HideCommunity},
|
use lemmy_db_schema::{
|
||||||
context::LemmyContext,
|
source::{community::Community, person::Person},
|
||||||
utils::local_user_view_from_jwt,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
pub(crate) async fn send_update_community(
|
||||||
impl SendActivity for EditCommunity {
|
community: Community,
|
||||||
type Response = CommunityResponse;
|
actor: Person,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
_response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
|
||||||
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UpdateCommunity {
|
|
||||||
#[tracing::instrument(skip_all)]
|
|
||||||
pub async fn send(
|
|
||||||
community: ApubCommunity,
|
|
||||||
actor: &ApubPerson,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
let community: ApubCommunity = community.into();
|
||||||
|
let actor: ApubPerson = actor.into();
|
||||||
let id = generate_activity_id(
|
let id = generate_activity_id(
|
||||||
UpdateType::Update,
|
UpdateType::Update,
|
||||||
&context.settings().get_protocol_and_hostname(),
|
&context.settings().get_protocol_and_hostname(),
|
||||||
|
@ -55,7 +38,7 @@ impl UpdateCommunity {
|
||||||
let update = UpdateCommunity {
|
let update = UpdateCommunity {
|
||||||
actor: actor.id().into(),
|
actor: actor.id().into(),
|
||||||
to: vec![public()],
|
to: vec![public()],
|
||||||
object: Box::new(community.clone().into_json(context).await?),
|
object: Box::new(community.clone().into_json(&context).await?),
|
||||||
cc: vec![community.id()],
|
cc: vec![community.id()],
|
||||||
kind: UpdateType::Update,
|
kind: UpdateType::Update,
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
|
@ -63,8 +46,7 @@ impl UpdateCommunity {
|
||||||
};
|
};
|
||||||
|
|
||||||
let activity = AnnouncableActivities::UpdateCommunity(update);
|
let activity = AnnouncableActivities::UpdateCommunity(update);
|
||||||
send_activity_in_community(activity, actor, &community, vec![], true, context).await
|
send_activity_in_community(activity, &actor, &community, vec![], true, &context).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -101,18 +83,3 @@ impl ActivityHandler for UpdateCommunity {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for HideCommunity {
|
|
||||||
type Response = CommunityResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
_response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
|
||||||
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,75 +6,24 @@ use crate::{
|
||||||
create_or_update::chat_message::CreateOrUpdateChatMessage,
|
create_or_update::chat_message::CreateOrUpdateChatMessage,
|
||||||
CreateOrUpdateType,
|
CreateOrUpdateType,
|
||||||
},
|
},
|
||||||
SendActivity,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
protocol::verification::verify_domains_match,
|
protocol::verification::verify_domains_match,
|
||||||
traits::{ActivityHandler, Actor, Object},
|
traits::{ActivityHandler, Actor, Object},
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::context::LemmyContext;
|
||||||
context::LemmyContext,
|
use lemmy_db_views::structs::PrivateMessageView;
|
||||||
private_message::{CreatePrivateMessage, EditPrivateMessage, PrivateMessageResponse},
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
|
||||||
newtypes::PersonId,
|
|
||||||
source::{person::Person, private_message::PrivateMessage},
|
|
||||||
traits::Crud,
|
|
||||||
};
|
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
pub(crate) async fn send_create_or_update_pm(
|
||||||
impl SendActivity for CreatePrivateMessage {
|
pm_view: PrivateMessageView,
|
||||||
type Response = PrivateMessageResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
_request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
CreateOrUpdateChatMessage::send(
|
|
||||||
&response.private_message_view.private_message,
|
|
||||||
response.private_message_view.creator.id,
|
|
||||||
CreateOrUpdateType::Create,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for EditPrivateMessage {
|
|
||||||
type Response = PrivateMessageResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
_request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
CreateOrUpdateChatMessage::send(
|
|
||||||
&response.private_message_view.private_message,
|
|
||||||
response.private_message_view.creator.id,
|
|
||||||
CreateOrUpdateType::Update,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CreateOrUpdateChatMessage {
|
|
||||||
#[tracing::instrument(skip_all)]
|
|
||||||
async fn send(
|
|
||||||
private_message: &PrivateMessage,
|
|
||||||
sender_id: PersonId,
|
|
||||||
kind: CreateOrUpdateType,
|
kind: CreateOrUpdateType,
|
||||||
context: &Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let recipient_id = private_message.recipient_id;
|
let actor: ApubPerson = pm_view.creator.into();
|
||||||
let sender: ApubPerson = Person::read(&mut context.pool(), sender_id).await?.into();
|
let recipient: ApubPerson = pm_view.recipient.into();
|
||||||
let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id)
|
|
||||||
.await?
|
|
||||||
.into();
|
|
||||||
|
|
||||||
let id = generate_activity_id(
|
let id = generate_activity_id(
|
||||||
kind.clone(),
|
kind.clone(),
|
||||||
|
@ -82,16 +31,15 @@ impl CreateOrUpdateChatMessage {
|
||||||
)?;
|
)?;
|
||||||
let create_or_update = CreateOrUpdateChatMessage {
|
let create_or_update = CreateOrUpdateChatMessage {
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
actor: sender.id().into(),
|
actor: actor.id().into(),
|
||||||
to: [recipient.id().into()],
|
to: [recipient.id().into()],
|
||||||
object: ApubPrivateMessage(private_message.clone())
|
object: ApubPrivateMessage(pm_view.private_message.clone())
|
||||||
.into_json(context)
|
.into_json(&context)
|
||||||
.await?,
|
.await?,
|
||||||
kind,
|
kind,
|
||||||
};
|
};
|
||||||
let inbox = vec![recipient.shared_inbox_or_inbox()];
|
let inbox = vec![recipient.shared_inbox_or_inbox()];
|
||||||
send_lemmy_activity(context, create_or_update, &sender, inbox, true).await
|
send_lemmy_activity(&context, create_or_update, &actor, inbox, true).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::{
|
||||||
insert_received_activity,
|
insert_received_activity,
|
||||||
objects::{instance::remote_instance_inboxes, person::ApubPerson},
|
objects::{instance::remote_instance_inboxes, person::ApubPerson},
|
||||||
protocol::activities::deletion::delete_user::DeleteUser,
|
protocol::activities::deletion::delete_user::DeleteUser,
|
||||||
SendActivity,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
|
@ -11,25 +10,13 @@ use activitypub_federation::{
|
||||||
protocol::verification::verify_urls_match,
|
protocol::verification::verify_urls_match,
|
||||||
traits::{ActivityHandler, Actor},
|
traits::{ActivityHandler, Actor},
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{context::LemmyContext, utils::delete_user_account};
|
||||||
context::LemmyContext,
|
use lemmy_db_schema::source::person::Person;
|
||||||
person::{DeleteAccount, DeleteAccountResponse},
|
|
||||||
utils::{delete_user_account, local_user_view_from_jwt},
|
|
||||||
};
|
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
pub async fn delete_user(person: Person, context: Data<LemmyContext>) -> Result<(), LemmyError> {
|
||||||
impl SendActivity for DeleteAccount {
|
let actor: ApubPerson = person.into();
|
||||||
type Response = DeleteAccountResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
_response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let actor: ApubPerson = local_user_view.person.into();
|
|
||||||
delete_user_account(
|
delete_user_account(
|
||||||
actor.id,
|
actor.id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
|
@ -52,10 +39,9 @@ impl SendActivity for DeleteAccount {
|
||||||
};
|
};
|
||||||
|
|
||||||
let inboxes = remote_instance_inboxes(&mut context.pool()).await?;
|
let inboxes = remote_instance_inboxes(&mut context.pool()).await?;
|
||||||
send_lemmy_activity(context, delete, &actor, inboxes, true).await?;
|
send_lemmy_activity(&context, delete, &actor, inboxes, true).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// This can be separate from Delete activity because it doesn't need to be handled in shared inbox
|
/// This can be separate from Delete activity because it doesn't need to be handled in shared inbox
|
||||||
/// (cause instance actor doesn't have shared inbox).
|
/// (cause instance actor doesn't have shared inbox).
|
||||||
|
|
|
@ -19,7 +19,6 @@ use crate::{
|
||||||
activities::deletion::{delete::Delete, undo_delete::UndoDelete},
|
activities::deletion::{delete::Delete, undo_delete::UndoDelete},
|
||||||
InCommunity,
|
InCommunity,
|
||||||
},
|
},
|
||||||
SendActivity,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
|
@ -28,14 +27,9 @@ use activitypub_federation::{
|
||||||
protocol::verification::verify_domains_match,
|
protocol::verification::verify_domains_match,
|
||||||
traits::{Actor, Object},
|
traits::{Actor, Object},
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::context::LemmyContext;
|
||||||
community::{CommunityResponse, DeleteCommunity, RemoveCommunity},
|
|
||||||
context::LemmyContext,
|
|
||||||
post::{DeletePost, PostResponse, RemovePost},
|
|
||||||
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
|
||||||
utils::local_user_view_from_jwt,
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
newtypes::CommunityId,
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentUpdateForm},
|
comment::{Comment, CommentUpdateForm},
|
||||||
community::{Community, CommunityUpdateForm},
|
community::{Community, CommunityUpdateForm},
|
||||||
|
@ -53,122 +47,6 @@ pub mod delete;
|
||||||
pub mod delete_user;
|
pub mod delete_user;
|
||||||
pub mod undo_delete;
|
pub mod undo_delete;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for DeletePost {
|
|
||||||
type Response = PostResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let community = Community::read(&mut context.pool(), response.post_view.community.id).await?;
|
|
||||||
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
community,
|
|
||||||
deletable,
|
|
||||||
None,
|
|
||||||
request.deleted,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for RemovePost {
|
|
||||||
type Response = PostResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let community = Community::read(&mut context.pool(), response.post_view.community.id).await?;
|
|
||||||
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
community,
|
|
||||||
deletable,
|
|
||||||
request.reason.clone().or_else(|| Some(String::new())),
|
|
||||||
request.removed,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for DeletePrivateMessage {
|
|
||||||
type Response = PrivateMessageResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
send_apub_delete_private_message(
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
response.private_message_view.private_message.clone(),
|
|
||||||
request.deleted,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for DeleteCommunity {
|
|
||||||
type Response = CommunityResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
_response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
|
||||||
let deletable = DeletableObjects::Community(community.clone().into());
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
community,
|
|
||||||
deletable,
|
|
||||||
None,
|
|
||||||
request.deleted,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for RemoveCommunity {
|
|
||||||
type Response = CommunityResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
_response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
|
||||||
let deletable = DeletableObjects::Community(community.clone().into());
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
community,
|
|
||||||
deletable,
|
|
||||||
request.reason.clone().or_else(|| Some(String::new())),
|
|
||||||
request.removed,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parameter `reason` being set indicates that this is a removal by a mod. If its unset, this
|
/// Parameter `reason` being set indicates that this is a removal by a mod. If its unset, this
|
||||||
/// action was done by a normal user.
|
/// action was done by a normal user.
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
|
@ -200,12 +78,44 @@ pub(crate) async fn send_apub_delete_in_community(
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parameter `reason` being set indicates that this is a removal by a mod. If its unset, this
|
||||||
|
/// action was done by a normal user.
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn send_apub_delete_private_message(
|
pub(crate) async fn send_apub_delete_in_community_new(
|
||||||
|
actor: Person,
|
||||||
|
community_id: CommunityId,
|
||||||
|
object: DeletableObjects,
|
||||||
|
reason: Option<String>,
|
||||||
|
deleted: bool,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<(), LemmyError> {
|
||||||
|
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||||
|
let actor = ApubPerson::from(actor);
|
||||||
|
let is_mod_action = reason.is_some();
|
||||||
|
let activity = if deleted {
|
||||||
|
let delete = Delete::new(&actor, object, public(), Some(&community), reason, &context)?;
|
||||||
|
AnnouncableActivities::Delete(delete)
|
||||||
|
} else {
|
||||||
|
let undo = UndoDelete::new(&actor, object, public(), Some(&community), reason, &context)?;
|
||||||
|
AnnouncableActivities::UndoDelete(undo)
|
||||||
|
};
|
||||||
|
send_activity_in_community(
|
||||||
|
activity,
|
||||||
|
&actor,
|
||||||
|
&community.into(),
|
||||||
|
vec![],
|
||||||
|
is_mod_action,
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip_all)]
|
||||||
|
pub(crate) async fn send_apub_delete_private_message(
|
||||||
actor: &ApubPerson,
|
actor: &ApubPerson,
|
||||||
pm: PrivateMessage,
|
pm: PrivateMessage,
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
context: &Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let recipient_id = pm.recipient_id;
|
let recipient_id = pm.recipient_id;
|
||||||
let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id)
|
let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id)
|
||||||
|
@ -215,11 +125,11 @@ async fn send_apub_delete_private_message(
|
||||||
let deletable = DeletableObjects::PrivateMessage(pm.into());
|
let deletable = DeletableObjects::PrivateMessage(pm.into());
|
||||||
let inbox = vec![recipient.shared_inbox_or_inbox()];
|
let inbox = vec![recipient.shared_inbox_or_inbox()];
|
||||||
if deleted {
|
if deleted {
|
||||||
let delete = Delete::new(actor, deletable, recipient.id(), None, None, context)?;
|
let delete = Delete::new(actor, deletable, recipient.id(), None, None, &context)?;
|
||||||
send_lemmy_activity(context, delete, actor, inbox, true).await?;
|
send_lemmy_activity(&context, delete, actor, inbox, true).await?;
|
||||||
} else {
|
} else {
|
||||||
let undo = UndoDelete::new(actor, deletable, recipient.id(), None, None, context)?;
|
let undo = UndoDelete::new(actor, deletable, recipient.id(), None, None, &context)?;
|
||||||
send_lemmy_activity(context, undo, actor, inbox, true).await?;
|
send_lemmy_activity(&context, undo, actor, inbox, true).await?;
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,7 @@ use crate::{
|
||||||
fetcher::user_or_community::UserOrCommunity,
|
fetcher::user_or_community::UserOrCommunity,
|
||||||
insert_received_activity,
|
insert_received_activity,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
protocol::activities::following::{
|
protocol::activities::following::{accept::AcceptFollow, follow::Follow},
|
||||||
accept::AcceptFollow,
|
|
||||||
follow::Follow,
|
|
||||||
undo_follow::UndoFollow,
|
|
||||||
},
|
|
||||||
SendActivity,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
|
@ -21,17 +16,13 @@ use activitypub_federation::{
|
||||||
protocol::verification::verify_urls_match,
|
protocol::verification::verify_urls_match,
|
||||||
traits::{ActivityHandler, Actor},
|
traits::{ActivityHandler, Actor},
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::context::LemmyContext;
|
||||||
community::{BlockCommunity, BlockCommunityResponse},
|
|
||||||
context::LemmyContext,
|
|
||||||
utils::local_user_view_from_jwt,
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityFollower, CommunityFollowerForm},
|
community::{CommunityFollower, CommunityFollowerForm},
|
||||||
person::{PersonFollower, PersonFollowerForm},
|
person::{PersonFollower, PersonFollowerForm},
|
||||||
},
|
},
|
||||||
traits::{Crud, Followable},
|
traits::Followable,
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -128,18 +119,3 @@ impl ActivityHandler for Follow {
|
||||||
AcceptFollow::send(self, context).await
|
AcceptFollow::send(self, context).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for BlockCommunity {
|
|
||||||
type Response = BlockCommunityResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
request: &Self,
|
|
||||||
_response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
|
||||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
|
||||||
UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +1,25 @@
|
||||||
use self::following::send_follow_community;
|
use self::following::send_follow_community;
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::{
|
activities::{
|
||||||
deletion::{send_apub_delete_in_community, DeletableObjects},
|
block::{send_ban_from_community, send_ban_from_site},
|
||||||
|
community::{
|
||||||
|
collection_add::{send_add_mod_to_community, send_feature_post},
|
||||||
|
lock_page::send_lock_post,
|
||||||
|
update::send_update_community,
|
||||||
|
},
|
||||||
|
create_or_update::private_message::send_create_or_update_pm,
|
||||||
|
deletion::{
|
||||||
|
delete_user::delete_user,
|
||||||
|
send_apub_delete_in_community,
|
||||||
|
send_apub_delete_in_community_new,
|
||||||
|
send_apub_delete_private_message,
|
||||||
|
DeletableObjects,
|
||||||
|
},
|
||||||
voting::send_like_activity,
|
voting::send_like_activity,
|
||||||
},
|
},
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
protocol::activities::{
|
protocol::activities::{
|
||||||
|
community::report::Report,
|
||||||
create_or_update::{note::CreateOrUpdateNote, page::CreateOrUpdatePage},
|
create_or_update::{note::CreateOrUpdateNote, page::CreateOrUpdatePage},
|
||||||
CreateOrUpdateType,
|
CreateOrUpdateType,
|
||||||
},
|
},
|
||||||
|
@ -229,14 +243,46 @@ pub async fn match_outgoing_activities(
|
||||||
let fed_task = async {
|
let fed_task = async {
|
||||||
use SendActivityData::*;
|
use SendActivityData::*;
|
||||||
match data {
|
match data {
|
||||||
CreatePost(post) | UpdatePost(post) => {
|
CreatePost(post) => {
|
||||||
let creator_id = post.creator_id;
|
let creator_id = post.creator_id;
|
||||||
CreateOrUpdatePage::send(post, creator_id, CreateOrUpdateType::Create, context).await
|
CreateOrUpdatePage::send(post, creator_id, CreateOrUpdateType::Create, context).await
|
||||||
}
|
}
|
||||||
CreateComment(comment) | UpdateComment(comment) => {
|
UpdatePost(post) => {
|
||||||
|
let creator_id = post.creator_id;
|
||||||
|
CreateOrUpdatePage::send(post, creator_id, CreateOrUpdateType::Update, context).await
|
||||||
|
}
|
||||||
|
DeletePost(post, person, data) => {
|
||||||
|
send_apub_delete_in_community_new(
|
||||||
|
person,
|
||||||
|
post.community_id,
|
||||||
|
DeletableObjects::Post(post.into()),
|
||||||
|
None,
|
||||||
|
data.deleted,
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
RemovePost(post, person, data) => {
|
||||||
|
send_apub_delete_in_community_new(
|
||||||
|
person,
|
||||||
|
post.community_id,
|
||||||
|
DeletableObjects::Post(post.into()),
|
||||||
|
data.reason.or_else(|| Some(String::new())),
|
||||||
|
data.removed,
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
LockPost(post, actor, locked) => send_lock_post(post, actor, locked, context).await,
|
||||||
|
FeaturePost(post, actor, featured) => send_feature_post(post, actor, featured, context).await,
|
||||||
|
CreateComment(comment) => {
|
||||||
let creator_id = comment.creator_id;
|
let creator_id = comment.creator_id;
|
||||||
CreateOrUpdateNote::send(comment, creator_id, CreateOrUpdateType::Create, context).await
|
CreateOrUpdateNote::send(comment, creator_id, CreateOrUpdateType::Create, context).await
|
||||||
}
|
}
|
||||||
|
UpdateComment(comment) => {
|
||||||
|
let creator_id = comment.creator_id;
|
||||||
|
CreateOrUpdateNote::send(comment, creator_id, CreateOrUpdateType::Update, context).await
|
||||||
|
}
|
||||||
DeleteComment(comment, actor, community) => {
|
DeleteComment(comment, actor, community) => {
|
||||||
let is_deleted = comment.deleted;
|
let is_deleted = comment.deleted;
|
||||||
let deletable = DeletableObjects::Comment(comment.into());
|
let deletable = DeletableObjects::Comment(comment.into());
|
||||||
|
@ -251,9 +297,46 @@ pub async fn match_outgoing_activities(
|
||||||
LikePostOrComment(object_id, person, community, score) => {
|
LikePostOrComment(object_id, person, community, score) => {
|
||||||
send_like_activity(object_id, person, community, score, context).await
|
send_like_activity(object_id, person, community, score, context).await
|
||||||
}
|
}
|
||||||
SendActivityData::FollowCommunity(community, person, follow) => {
|
FollowCommunity(community, person, follow) => {
|
||||||
send_follow_community(community, person, follow, &context).await
|
send_follow_community(community, person, follow, &context).await
|
||||||
}
|
}
|
||||||
|
UpdateCommunity(actor, community) => send_update_community(community, actor, context).await,
|
||||||
|
DeleteCommunity(actor, community, removed) => {
|
||||||
|
let deletable = DeletableObjects::Community(community.clone().into());
|
||||||
|
send_apub_delete_in_community(actor, community, deletable, None, removed, &context).await
|
||||||
|
}
|
||||||
|
RemoveCommunity(actor, community, reason, removed) => {
|
||||||
|
let deletable = DeletableObjects::Community(community.clone().into());
|
||||||
|
send_apub_delete_in_community(
|
||||||
|
actor,
|
||||||
|
community,
|
||||||
|
deletable,
|
||||||
|
reason.clone().or_else(|| Some(String::new())),
|
||||||
|
removed,
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
AddModToCommunity(actor, community_id, updated_mod_id, added) => {
|
||||||
|
send_add_mod_to_community(actor, community_id, updated_mod_id, added, context).await
|
||||||
|
}
|
||||||
|
BanFromCommunity(mod_, community_id, target, data) => {
|
||||||
|
send_ban_from_community(mod_, community_id, target, data, context).await
|
||||||
|
}
|
||||||
|
BanFromSite(mod_, target, data) => send_ban_from_site(mod_, target, data, context).await,
|
||||||
|
CreatePrivateMessage(pm) => {
|
||||||
|
send_create_or_update_pm(pm, CreateOrUpdateType::Create, context).await
|
||||||
|
}
|
||||||
|
UpdatePrivateMessage(pm) => {
|
||||||
|
send_create_or_update_pm(pm, CreateOrUpdateType::Update, context).await
|
||||||
|
}
|
||||||
|
DeletePrivateMessage(person, pm, deleted) => {
|
||||||
|
send_apub_delete_private_message(&person.into(), pm, deleted, context).await
|
||||||
|
}
|
||||||
|
DeleteUser(person) => delete_user(person, context).await,
|
||||||
|
CreateReport(url, actor, community, reason) => {
|
||||||
|
Report::send(ObjectId::from(url), actor, community, reason, context).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if *SYNCHRONOUS_FEDERATION {
|
if *SYNCHRONOUS_FEDERATION {
|
||||||
|
|
|
@ -1,33 +1,30 @@
|
||||||
use actix_web::{guard, web, Error, HttpResponse, Result};
|
use actix_web::{guard, web, Error, HttpResponse, Result};
|
||||||
use lemmy_api::{
|
use lemmy_api::{
|
||||||
comment::{distinguish::distinguish_comment, like::like_comment, save::save_comment},
|
comment::{distinguish::distinguish_comment, like::like_comment, save::save_comment},
|
||||||
comment_report::{list::list_comment_reports, resolve::resolve_comment_report},
|
comment_report::{
|
||||||
community::follow::follow_community,
|
create::create_comment_report,
|
||||||
local_user::notifications::mark_reply_read::mark_reply_as_read,
|
list::list_comment_reports,
|
||||||
post::like::like_post,
|
resolve::resolve_comment_report,
|
||||||
|
},
|
||||||
|
community::{
|
||||||
|
add_mod::add_mod_to_community,
|
||||||
|
ban::ban_from_community,
|
||||||
|
block::block_community,
|
||||||
|
follow::follow_community,
|
||||||
|
hide::hide_community,
|
||||||
|
},
|
||||||
|
local_user::{ban_person::ban_from_site, notifications::mark_reply_read::mark_reply_as_read},
|
||||||
|
post::{feature::feature_post, like::like_post, lock::lock_post},
|
||||||
|
post_report::create::create_post_report,
|
||||||
Perform,
|
Perform,
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::CreateCommentReport,
|
community::TransferCommunity,
|
||||||
community::{
|
|
||||||
AddModToCommunity,
|
|
||||||
BanFromCommunity,
|
|
||||||
BlockCommunity,
|
|
||||||
CreateCommunity,
|
|
||||||
DeleteCommunity,
|
|
||||||
EditCommunity,
|
|
||||||
HideCommunity,
|
|
||||||
RemoveCommunity,
|
|
||||||
TransferCommunity,
|
|
||||||
},
|
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
custom_emoji::{CreateCustomEmoji, DeleteCustomEmoji, EditCustomEmoji},
|
|
||||||
person::{
|
person::{
|
||||||
AddAdmin,
|
AddAdmin,
|
||||||
BanPerson,
|
|
||||||
BlockPerson,
|
BlockPerson,
|
||||||
ChangePassword,
|
ChangePassword,
|
||||||
DeleteAccount,
|
|
||||||
GetBannedPersons,
|
GetBannedPersons,
|
||||||
GetCaptcha,
|
GetCaptcha,
|
||||||
GetPersonMentions,
|
GetPersonMentions,
|
||||||
|
@ -39,27 +36,12 @@ use lemmy_api_common::{
|
||||||
MarkPersonMentionAsRead,
|
MarkPersonMentionAsRead,
|
||||||
PasswordChangeAfterReset,
|
PasswordChangeAfterReset,
|
||||||
PasswordReset,
|
PasswordReset,
|
||||||
Register,
|
|
||||||
SaveUserSettings,
|
SaveUserSettings,
|
||||||
VerifyEmail,
|
VerifyEmail,
|
||||||
},
|
},
|
||||||
post::{
|
post::{GetSiteMetadata, ListPostReports, MarkPostAsRead, ResolvePostReport, SavePost},
|
||||||
CreatePostReport,
|
|
||||||
DeletePost,
|
|
||||||
FeaturePost,
|
|
||||||
GetSiteMetadata,
|
|
||||||
ListPostReports,
|
|
||||||
LockPost,
|
|
||||||
MarkPostAsRead,
|
|
||||||
RemovePost,
|
|
||||||
ResolvePostReport,
|
|
||||||
SavePost,
|
|
||||||
},
|
|
||||||
private_message::{
|
private_message::{
|
||||||
CreatePrivateMessage,
|
|
||||||
CreatePrivateMessageReport,
|
CreatePrivateMessageReport,
|
||||||
DeletePrivateMessage,
|
|
||||||
EditPrivateMessage,
|
|
||||||
ListPrivateMessageReports,
|
ListPrivateMessageReports,
|
||||||
MarkPrivateMessageAsRead,
|
MarkPrivateMessageAsRead,
|
||||||
ResolvePrivateMessageReport,
|
ResolvePrivateMessageReport,
|
||||||
|
@ -85,11 +67,33 @@ use lemmy_api_crud::{
|
||||||
remove::remove_comment,
|
remove::remove_comment,
|
||||||
update::update_comment,
|
update::update_comment,
|
||||||
},
|
},
|
||||||
community::list::list_communities,
|
community::{
|
||||||
post::{create::create_post, read::get_post, update::update_post},
|
create::create_community,
|
||||||
private_message::read::get_private_message,
|
delete::delete_community,
|
||||||
|
list::list_communities,
|
||||||
|
remove::remove_community,
|
||||||
|
update::update_community,
|
||||||
|
},
|
||||||
|
custom_emoji::{
|
||||||
|
create::create_custom_emoji,
|
||||||
|
delete::delete_custom_emoji,
|
||||||
|
update::update_custom_emoji,
|
||||||
|
},
|
||||||
|
post::{
|
||||||
|
create::create_post,
|
||||||
|
delete::delete_post,
|
||||||
|
read::get_post,
|
||||||
|
remove::remove_post,
|
||||||
|
update::update_post,
|
||||||
|
},
|
||||||
|
private_message::{
|
||||||
|
create::create_private_message,
|
||||||
|
delete::delete_private_message,
|
||||||
|
read::get_private_message,
|
||||||
|
update::update_private_message,
|
||||||
|
},
|
||||||
site::{create::create_site, read::get_site, update::update_site},
|
site::{create::create_site, read::get_site, update::update_site},
|
||||||
PerformCrud,
|
user::{create::register, delete::delete_account},
|
||||||
};
|
};
|
||||||
use lemmy_apub::{
|
use lemmy_apub::{
|
||||||
api::{
|
api::{
|
||||||
|
@ -137,29 +141,23 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
web::resource("/community")
|
web::resource("/community")
|
||||||
.guard(guard::Post())
|
.guard(guard::Post())
|
||||||
.wrap(rate_limit.register())
|
.wrap(rate_limit.register())
|
||||||
.route(web::post().to(route_post_crud::<CreateCommunity>)),
|
.route(web::post().to(create_community)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::scope("/community")
|
web::scope("/community")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::get().to(get_community))
|
.route("", web::get().to(get_community))
|
||||||
.route("", web::put().to(route_post_crud::<EditCommunity>))
|
.route("", web::put().to(update_community))
|
||||||
.route("/hide", web::put().to(route_post::<HideCommunity>))
|
.route("/hide", web::put().to(hide_community))
|
||||||
.route("/list", web::get().to(list_communities))
|
.route("/list", web::get().to(list_communities))
|
||||||
.route("/follow", web::post().to(follow_community))
|
.route("/follow", web::post().to(follow_community))
|
||||||
.route("/block", web::post().to(route_post::<BlockCommunity>))
|
.route("/block", web::post().to(block_community))
|
||||||
.route(
|
.route("/delete", web::post().to(delete_community))
|
||||||
"/delete",
|
|
||||||
web::post().to(route_post_crud::<DeleteCommunity>),
|
|
||||||
)
|
|
||||||
// Mod Actions
|
// Mod Actions
|
||||||
.route(
|
.route("/remove", web::post().to(remove_community))
|
||||||
"/remove",
|
|
||||||
web::post().to(route_post_crud::<RemoveCommunity>),
|
|
||||||
)
|
|
||||||
.route("/transfer", web::post().to(route_post::<TransferCommunity>))
|
.route("/transfer", web::post().to(route_post::<TransferCommunity>))
|
||||||
.route("/ban_user", web::post().to(route_post::<BanFromCommunity>))
|
.route("/ban_user", web::post().to(ban_from_community))
|
||||||
.route("/mod", web::post().to(route_post::<AddModToCommunity>)),
|
.route("/mod", web::post().to(add_mod_to_community)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::scope("/federated_instances")
|
web::scope("/federated_instances")
|
||||||
|
@ -179,18 +177,18 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::get().to(get_post))
|
.route("", web::get().to(get_post))
|
||||||
.route("", web::put().to(update_post))
|
.route("", web::put().to(update_post))
|
||||||
.route("/delete", web::post().to(route_post_crud::<DeletePost>))
|
.route("/delete", web::post().to(delete_post))
|
||||||
.route("/remove", web::post().to(route_post_crud::<RemovePost>))
|
.route("/remove", web::post().to(remove_post))
|
||||||
.route(
|
.route(
|
||||||
"/mark_as_read",
|
"/mark_as_read",
|
||||||
web::post().to(route_post::<MarkPostAsRead>),
|
web::post().to(route_post::<MarkPostAsRead>),
|
||||||
)
|
)
|
||||||
.route("/lock", web::post().to(route_post::<LockPost>))
|
.route("/lock", web::post().to(lock_post))
|
||||||
.route("/feature", web::post().to(route_post::<FeaturePost>))
|
.route("/feature", web::post().to(feature_post))
|
||||||
.route("/list", web::get().to(list_posts))
|
.route("/list", web::get().to(list_posts))
|
||||||
.route("/like", web::post().to(like_post))
|
.route("/like", web::post().to(like_post))
|
||||||
.route("/save", web::put().to(route_post::<SavePost>))
|
.route("/save", web::put().to(route_post::<SavePost>))
|
||||||
.route("/report", web::post().to(route_post::<CreatePostReport>))
|
.route("/report", web::post().to(create_post_report))
|
||||||
.route(
|
.route(
|
||||||
"/report/resolve",
|
"/report/resolve",
|
||||||
web::put().to(route_post::<ResolvePostReport>),
|
web::put().to(route_post::<ResolvePostReport>),
|
||||||
|
@ -221,7 +219,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.route("/like", web::post().to(like_comment))
|
.route("/like", web::post().to(like_comment))
|
||||||
.route("/save", web::put().to(save_comment))
|
.route("/save", web::put().to(save_comment))
|
||||||
.route("/list", web::get().to(list_comments))
|
.route("/list", web::get().to(list_comments))
|
||||||
.route("/report", web::post().to(route_post::<CreateCommentReport>))
|
.route("/report", web::post().to(create_comment_report))
|
||||||
.route("/report/resolve", web::put().to(resolve_comment_report))
|
.route("/report/resolve", web::put().to(resolve_comment_report))
|
||||||
.route("/report/list", web::get().to(list_comment_reports)),
|
.route("/report/list", web::get().to(list_comment_reports)),
|
||||||
)
|
)
|
||||||
|
@ -230,12 +228,9 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
web::scope("/private_message")
|
web::scope("/private_message")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("/list", web::get().to(get_private_message))
|
.route("/list", web::get().to(get_private_message))
|
||||||
.route("", web::post().to(route_post_crud::<CreatePrivateMessage>))
|
.route("", web::post().to(create_private_message))
|
||||||
.route("", web::put().to(route_post_crud::<EditPrivateMessage>))
|
.route("", web::put().to(update_private_message))
|
||||||
.route(
|
.route("/delete", web::post().to(delete_private_message))
|
||||||
"/delete",
|
|
||||||
web::post().to(route_post_crud::<DeletePrivateMessage>),
|
|
||||||
)
|
|
||||||
.route(
|
.route(
|
||||||
"/mark_as_read",
|
"/mark_as_read",
|
||||||
web::post().to(route_post::<MarkPrivateMessageAsRead>),
|
web::post().to(route_post::<MarkPrivateMessageAsRead>),
|
||||||
|
@ -260,7 +255,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
web::resource("/user/register")
|
web::resource("/user/register")
|
||||||
.guard(guard::Post())
|
.guard(guard::Post())
|
||||||
.wrap(rate_limit.register())
|
.wrap(rate_limit.register())
|
||||||
.route(web::post().to(route_post_crud::<Register>)),
|
.route(web::post().to(register)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
// Handle captcha separately
|
// Handle captcha separately
|
||||||
|
@ -280,15 +275,12 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
)
|
)
|
||||||
.route("/replies", web::get().to(route_get::<GetReplies>))
|
.route("/replies", web::get().to(route_get::<GetReplies>))
|
||||||
// Admin action. I don't like that it's in /user
|
// Admin action. I don't like that it's in /user
|
||||||
.route("/ban", web::post().to(route_post::<BanPerson>))
|
.route("/ban", web::post().to(ban_from_site))
|
||||||
.route("/banned", web::get().to(route_get::<GetBannedPersons>))
|
.route("/banned", web::get().to(route_get::<GetBannedPersons>))
|
||||||
.route("/block", web::post().to(route_post::<BlockPerson>))
|
.route("/block", web::post().to(route_post::<BlockPerson>))
|
||||||
// Account actions. I don't like that they're in /user maybe /accounts
|
// Account actions. I don't like that they're in /user maybe /accounts
|
||||||
.route("/login", web::post().to(route_post::<Login>))
|
.route("/login", web::post().to(route_post::<Login>))
|
||||||
.route(
|
.route("/delete_account", web::post().to(delete_account))
|
||||||
"/delete_account",
|
|
||||||
web::post().to(route_post_crud::<DeleteAccount>),
|
|
||||||
)
|
|
||||||
.route(
|
.route(
|
||||||
"/password_reset",
|
"/password_reset",
|
||||||
web::post().to(route_post::<PasswordReset>),
|
web::post().to(route_post::<PasswordReset>),
|
||||||
|
@ -343,12 +335,9 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.service(
|
.service(
|
||||||
web::scope("/custom_emoji")
|
web::scope("/custom_emoji")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::post().to(route_post_crud::<CreateCustomEmoji>))
|
.route("", web::post().to(create_custom_emoji))
|
||||||
.route("", web::put().to(route_post_crud::<EditCustomEmoji>))
|
.route("", web::put().to(update_custom_emoji))
|
||||||
.route(
|
.route("/delete", web::post().to(delete_custom_emoji)),
|
||||||
"/delete",
|
|
||||||
web::post().to(route_post_crud::<DeleteCustomEmoji>),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -408,43 +397,3 @@ where
|
||||||
{
|
{
|
||||||
perform::<Data>(data.0, context, apub_data).await
|
perform::<Data>(data.0, context, apub_data).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn perform_crud<'a, Data>(
|
|
||||||
data: Data,
|
|
||||||
context: web::Data<LemmyContext>,
|
|
||||||
apub_data: activitypub_federation::config::Data<LemmyContext>,
|
|
||||||
) -> Result<HttpResponse, Error>
|
|
||||||
where
|
|
||||||
Data: PerformCrud
|
|
||||||
+ SendActivity<Response = <Data as PerformCrud>::Response>
|
|
||||||
+ Clone
|
|
||||||
+ Deserialize<'a>
|
|
||||||
+ Send
|
|
||||||
+ 'static,
|
|
||||||
{
|
|
||||||
let res = data.perform(&context).await?;
|
|
||||||
let res_clone = res.clone();
|
|
||||||
let fed_task = async move { SendActivity::send_activity(&data, &res_clone, &apub_data).await };
|
|
||||||
if *SYNCHRONOUS_FEDERATION {
|
|
||||||
fed_task.await?;
|
|
||||||
} else {
|
|
||||||
spawn_try_task(fed_task);
|
|
||||||
}
|
|
||||||
Ok(HttpResponse::Ok().json(&res))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn route_post_crud<'a, Data>(
|
|
||||||
data: web::Json<Data>,
|
|
||||||
context: web::Data<LemmyContext>,
|
|
||||||
apub_data: activitypub_federation::config::Data<LemmyContext>,
|
|
||||||
) -> Result<HttpResponse, Error>
|
|
||||||
where
|
|
||||||
Data: PerformCrud
|
|
||||||
+ SendActivity<Response = <Data as PerformCrud>::Response>
|
|
||||||
+ Clone
|
|
||||||
+ Deserialize<'a>
|
|
||||||
+ Send
|
|
||||||
+ 'static,
|
|
||||||
{
|
|
||||||
perform_crud::<Data>(data.0, context, apub_data).await
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue