Changing recipient to target, adding unfollow to block action.

This commit is contained in:
Dessalines 2021-08-13 12:36:33 -04:00
parent 22c5d81e86
commit 7e45d9a7ac
12 changed files with 47 additions and 32 deletions

View file

@ -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",

View file

@ -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"

View file

@ -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))
})

View file

@ -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??;

View file

@ -9,7 +9,7 @@ pub trait PersonBlock_ {
fn read(
conn: &PgConnection,
person_id: PersonId,
recipient_id: PersonId,
target_id: PersonId,
) -> Result<PersonBlock, Error>;
}
@ -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::<Self>(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::<Self>(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)
}

View file

@ -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));

View file

@ -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,
}

View file

@ -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,
};

View file

@ -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();

View file

@ -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::<Vec<Self>>()
}

View file

@ -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)),
),
)

View file

@ -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 (