diff --git a/api_tests/package.json b/api_tests/package.json index 5078112f9..e8e4cc091 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -16,7 +16,7 @@ "eslint": "^7.30.0", "eslint-plugin-jane": "^9.0.3", "jest": "^27.0.6", - "lemmy-js-client": "0.11.4-rc.8", + "lemmy-js-client": "0.11.4-rc.9", "node-fetch": "^2.6.1", "prettier": "^2.3.2", "ts-jest": "^27.0.3", diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index d2f1a2392..370873b1e 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -3076,10 +3076,10 @@ language-tags@^1.0.5: dependencies: language-subtag-registry "~0.3.2" -lemmy-js-client@0.11.4-rc.8: - version "0.11.4-rc.8" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.4-rc.8.tgz#c333fbd5e46fe76b0d029f3effb9e539ad00160f" - integrity sha512-cDOlaX0nUtXFwJoz0SLxbkHXeFb6Uu4jomTBk6drpmJbvmWY4WuUtnZPiIUIsE00U/3KbpgsKc2Qm7XL9bb6Ng== +lemmy-js-client@0.11.4-rc.9: + version "0.11.4-rc.9" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.4-rc.9.tgz#f7b3c73691e4c1600daf3840d22d9cfbddc5f363" + integrity sha512-zP8JxWzQU+yuyE8cMG0GzR8aR3lJ++G5zzbynsXwDevzAZXhOm0ObNNtJiA3Q5msStFVKVYa3GwZxBv4XiYshw== leven@^3.1.0: version "3.1.0" diff --git a/crates/api/src/community.rs b/crates/api/src/community.rs index 69a6530cc..5aefd1443 100644 --- a/crates/api/src/community.rs +++ b/crates/api/src/community.rs @@ -133,6 +133,23 @@ impl Perform for BlockCommunity { if blocking(context.pool(), block).await?.is_err() { return Err(ApiError::err("community_block_already_exists").into()); } + + // Also, unfollow the community, and send a federated unfollow + let community_follower_form = CommunityFollowerForm { + community_id: data.community_id, + person_id, + pending: false, + }; + blocking(context.pool(), move |conn: &'_ _| { + CommunityFollower::unfollow(conn, &community_follower_form) + }) + .await? + .ok(); + let community = blocking(context.pool(), move |conn| { + Community::read(conn, community_id) + }) + .await??; + UndoFollowCommunity::send(&local_user_view.person, &community, context).await?; } else { let unblock = move |conn: &'_ _| CommunityBlock::unblock(conn, &community_block_form); if blocking(context.pool(), unblock).await?.is_err() { @@ -140,8 +157,6 @@ impl Perform for BlockCommunity { } } - // TODO does any federated stuff need to be done here? - let community_view = blocking(context.pool(), move |conn| { CommunityView::read(conn, community_id, Some(person_id)) }) diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index 1bd8ac410..510ef5adb 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -483,17 +483,17 @@ impl Perform for BlockPerson { let data: &BlockPerson = self; let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?; - let recipient_id = data.person_id; + let target_id = data.person_id; let person_id = local_user_view.person.id; // Don't let a person block themselves - if recipient_id == person_id { + if target_id == person_id { return Err(ApiError::err("cant_block_yourself").into()); } let person_block_form = PersonBlockForm { person_id, - recipient_id, + target_id, }; if data.block { @@ -511,7 +511,7 @@ impl Perform for BlockPerson { // TODO does any federated stuff need to be done here? let person_view = blocking(context.pool(), move |conn| { - PersonViewSafe::read(conn, recipient_id) + PersonViewSafe::read(conn, target_id) }) .await??; diff --git a/crates/db_queries/src/source/person_block.rs b/crates/db_queries/src/source/person_block.rs index 50af971b8..d4505519c 100644 --- a/crates/db_queries/src/source/person_block.rs +++ b/crates/db_queries/src/source/person_block.rs @@ -9,7 +9,7 @@ pub trait PersonBlock_ { fn read( conn: &PgConnection, person_id: PersonId, - recipient_id: PersonId, + target_id: PersonId, ) -> Result; } @@ -22,7 +22,7 @@ impl PersonBlock_ for PersonBlock { use lemmy_db_schema::schema::person_block::dsl::*; person_block .filter(person_id.eq(for_person_id)) - .filter(recipient_id.eq(for_recipient_id)) + .filter(target_id.eq(for_recipient_id)) .first::(conn) } } @@ -33,7 +33,7 @@ impl Blockable for PersonBlock { use lemmy_db_schema::schema::person_block::dsl::*; insert_into(person_block) .values(person_block_form) - .on_conflict((person_id, recipient_id)) + .on_conflict((person_id, target_id)) .do_update() .set(person_block_form) .get_result::(conn) @@ -43,7 +43,7 @@ impl Blockable for PersonBlock { diesel::delete( person_block .filter(person_id.eq(person_block_form.person_id)) - .filter(recipient_id.eq(person_block_form.recipient_id)), + .filter(target_id.eq(person_block_form.target_id)), ) .execute(conn) } diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 4da79bd98..4c92fffba 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -469,7 +469,7 @@ table! { person_block (id) { id -> Int4, person_id -> Int4, - recipient_id -> Int4, + target_id -> Int4, published -> Timestamp, } } @@ -561,7 +561,7 @@ joinable!(post_report -> person_alias_2 (resolver_id)); joinable!(comment_report -> person_alias_2 (resolver_id)); joinable!(person_block -> person (person_id)); -joinable!(person_block -> person_alias_1 (recipient_id)); +joinable!(person_block -> person_alias_1 (target_id)); joinable!(comment -> person (creator_id)); joinable!(comment -> post (post_id)); diff --git a/crates/db_schema/src/source/person_block.rs b/crates/db_schema/src/source/person_block.rs index 233581596..cedf7de18 100644 --- a/crates/db_schema/src/source/person_block.rs +++ b/crates/db_schema/src/source/person_block.rs @@ -6,7 +6,7 @@ use serde::Serialize; pub struct PersonBlock { pub id: PersonBlockId, pub person_id: PersonId, - pub recipient_id: PersonId, + pub target_id: PersonId, pub published: chrono::NaiveDateTime, } @@ -14,5 +14,5 @@ pub struct PersonBlock { #[table_name = "person_block"] pub struct PersonBlockForm { pub person_id: PersonId, - pub recipient_id: PersonId, + pub target_id: PersonId, } diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 5df58fe91..2183fa31e 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -126,7 +126,7 @@ impl CommentView { .left_join( person_block::table.on( comment::creator_id - .eq(person_block::recipient_id) + .eq(person_block::target_id) .and(person_block::person_id.eq(person_id_join)), ), ) @@ -333,7 +333,7 @@ impl<'a> CommentQueryBuilder<'a> { .left_join( person_block::table.on( comment::creator_id - .eq(person_block::recipient_id) + .eq(person_block::target_id) .and(person_block::person_id.eq(person_id_join)), ), ) @@ -559,7 +559,7 @@ mod tests { let timmy_blocks_sara_form = PersonBlockForm { person_id: inserted_person.id, - recipient_id: inserted_person_2.id, + target_id: inserted_person_2.id, }; let inserted_block = PersonBlock::block(&conn, &timmy_blocks_sara_form).unwrap(); @@ -567,7 +567,7 @@ mod tests { let expected_block = PersonBlock { id: inserted_block.id, person_id: inserted_person.id, - recipient_id: inserted_person_2.id, + target_id: inserted_person_2.id, published: inserted_block.published, }; diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index e9ee8bbf3..ec537ad94 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -121,7 +121,7 @@ impl PostView { .left_join( person_block::table.on( post::creator_id - .eq(person_block::recipient_id) + .eq(person_block::target_id) .and(person_block::person_id.eq(person_id_join)), ), ) @@ -319,7 +319,7 @@ impl<'a> PostQueryBuilder<'a> { .left_join( person_block::table.on( post::creator_id - .eq(person_block::recipient_id) + .eq(person_block::target_id) .and(person_block::person_id.eq(person_id_join)), ), ) @@ -557,7 +557,7 @@ mod tests { // block that person let person_block = PersonBlockForm { person_id: inserted_person.id, - recipient_id: inserted_blocked_person.id, + target_id: inserted_blocked_person.id, }; PersonBlock::block(&conn, &person_block).unwrap(); diff --git a/crates/db_views_actor/src/person_block_view.rs b/crates/db_views_actor/src/person_block_view.rs index 9cf04e384..5eb18589b 100644 --- a/crates/db_views_actor/src/person_block_view.rs +++ b/crates/db_views_actor/src/person_block_view.rs @@ -10,7 +10,7 @@ use serde::Serialize; #[derive(Debug, Serialize, Clone)] pub struct PersonBlockView { pub person: PersonSafe, - pub recipient: PersonSafeAlias1, + pub target: PersonSafeAlias1, } type PersonBlockViewTuple = (PersonSafe, PersonSafeAlias1); @@ -39,7 +39,7 @@ impl ViewToVec for PersonBlockView { .iter() .map(|a| Self { person: a.0.to_owned(), - recipient: a.1.to_owned(), + target: a.1.to_owned(), }) .collect::>() } diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 45515dbf5..421c60a40 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -121,7 +121,7 @@ impl PersonMentionView { .left_join( person_block::table.on( comment::creator_id - .eq(person_block::recipient_id) + .eq(person_block::target_id) .and(person_block::person_id.eq(person_id_join)), ), ) @@ -255,7 +255,7 @@ impl<'a> PersonMentionQueryBuilder<'a> { .left_join( person_block::table.on( comment::creator_id - .eq(person_block::recipient_id) + .eq(person_block::target_id) .and(person_block::person_id.eq(person_id_join)), ), ) diff --git a/migrations/2021-08-04-223559_create_user_community_block/up.sql b/migrations/2021-08-04-223559_create_user_community_block/up.sql index 282f7d50b..cbcadc284 100644 --- a/migrations/2021-08-04-223559_create_user_community_block/up.sql +++ b/migrations/2021-08-04-223559_create_user_community_block/up.sql @@ -1,9 +1,9 @@ create table person_block ( id serial primary key, person_id int references person on update cascade on delete cascade not null, - recipient_id int references person on update cascade on delete cascade not null, + target_id int references person on update cascade on delete cascade not null, published timestamp not null default now(), - unique(person_id, recipient_id) + unique(person_id, target_id) ); create table community_block (