diff --git a/crates/api/src/post/block.rs b/crates/api/src/post/block.rs new file mode 100644 index 000000000..2d1baa958 --- /dev/null +++ b/crates/api/src/post/block.rs @@ -0,0 +1,25 @@ +use lemmy_api_common::{post::{BlockKeywordForPost}, context::LemmyContext, SuccessResponse}; +use lemmy_db_views::structs::LocalUserView; +use activitypub_federation::config::Data; +use actix_web::web::Json; +use lemmy_utils::error::LemmyResult; +use lemmy_db_schema::source::post_keyword_block::{PostKeywordBlock, PostKeywordBlockForm}; + +pub async fn user_block_keyword_for_posts( + data: Json, + context: Data, + local_user_view: LocalUserView +) -> LemmyResult>{ + + let person_id = local_user_view.person.id; + let post_block_keyword_form = PostKeywordBlockForm { + person_id, + keyword: data.keyword.clone(), + }; + if(data.block){ + PostKeywordBlock::block_keyword(&mut context.pool(), &post_block_keyword_form).await?; + } else { + PostKeywordBlock::unblock_keyword(&mut context.pool(), &post_block_keyword_form).await?; + } + Ok(Json(SuccessResponse::default())) +} \ No newline at end of file diff --git a/crates/api/src/post/mod.rs b/crates/api/src/post/mod.rs index 97410f097..340dd0401 100644 --- a/crates/api/src/post/mod.rs +++ b/crates/api/src/post/mod.rs @@ -7,3 +7,4 @@ pub mod lock; pub mod mark_many_read; pub mod mark_read; pub mod save; +pub mod block; diff --git a/crates/api_common/src/post.rs b/crates/api_common/src/post.rs index 405de3a92..c53efc4f0 100644 --- a/crates/api_common/src/post.rs +++ b/crates/api_common/src/post.rs @@ -366,3 +366,12 @@ pub struct ListPostLikes { pub struct ListPostLikesResponse { pub post_likes: Vec, } + +#[derive(Debug,Serialize,Deserialize,Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +pub struct BlockKeywordForPost { + pub keyword: String, + pub block : bool, +} + diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 7f1000b14..3df7f5ff5 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -65,6 +65,7 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; +use lemmy_db_schema::source::post_keyword_block::PostKeywordBlock; #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] @@ -479,6 +480,7 @@ pub struct MyUserInfo { pub community_blocks: Vec, pub instance_blocks: Vec, pub person_blocks: Vec, + pub post_keyword_blocks: Vec, pub discussion_languages: Vec, } diff --git a/crates/api_crud/src/user/my_user.rs b/crates/api_crud/src/user/my_user.rs index f7a92eb99..7d12963af 100644 --- a/crates/api_crud/src/user/my_user.rs +++ b/crates/api_crud/src/user/my_user.rs @@ -6,6 +6,7 @@ use lemmy_db_schema::source::{ instance_block::InstanceBlock, person_block::PersonBlock, }; +use lemmy_db_schema::source::post_keyword_block::PostKeywordBlock; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::{CommunityFollowerView, CommunityModeratorView}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; @@ -22,12 +23,13 @@ pub async fn get_my_user( let local_user_id = local_user_view.local_user.id; let pool = &mut context.pool(); - let (follows, community_blocks, instance_blocks, person_blocks, moderates, discussion_languages) = + let (follows, community_blocks, instance_blocks, person_blocks, post_keyword_blocks, moderates, discussion_languages) = lemmy_db_schema::try_join_with_pool!(pool => ( |pool| CommunityFollowerView::for_person(pool, person_id), |pool| CommunityBlock::for_person(pool, person_id), |pool| InstanceBlock::for_person(pool, person_id), |pool| PersonBlock::for_person(pool, person_id), + |pool| PostKeywordBlock::for_person(pool, person_id), |pool| CommunityModeratorView::for_person(pool, person_id, Some(&local_user_view.local_user)), |pool| LocalUserLanguage::read(pool, local_user_id) )) @@ -40,6 +42,7 @@ pub async fn get_my_user( community_blocks, instance_blocks, person_blocks, + post_keyword_blocks, discussion_languages, })) } diff --git a/src/api_routes_v3.rs b/src/api_routes_v3.rs index eefaf5b87..f07a3273c 100644 --- a/src/api_routes_v3.rs +++ b/src/api_routes_v3.rs @@ -89,6 +89,7 @@ use lemmy_api::{ }, sitemap::get_sitemap, }; +use lemmy_api::post::block::user_block_keyword_for_posts; use lemmy_api_crud::{ comment::{ create::create_comment, @@ -223,7 +224,8 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/report", post().to(create_post_report)) .route("/report/resolve", put().to(resolve_post_report)) .route("/report/list", get().to(list_post_reports)) - .route("/site_metadata", get().to(get_link_metadata)), + .route("/site_metadata", get().to(get_link_metadata)) + .route("/block",post().to(user_block_keyword_for_posts)), ) // Comment .service( diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index a9f71c9da..818db28b1 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -98,6 +98,7 @@ use lemmy_api::{ }, sitemap::get_sitemap, }; +use lemmy_api::post::block::user_block_keyword_for_posts; use lemmy_api_crud::{ comment::{ create::create_comment, @@ -320,7 +321,8 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { scope("/block") .route("/person", post().to(user_block_person)) .route("/community", post().to(user_block_community)) - .route("/instance", post().to(user_block_instance)), + .route("/instance", post().to(user_block_instance)) + .route("/post",get().to(user_block_keyword_for_posts)), ), ) // User actions