mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-09 00:49:21 +00:00
2016afc9db
* A first pass at user / community blocking. #426 * Adding unit tests for person and community block. * Moving migration * Fixing creator_blocked for comment queries, added tests. * Don't let a person block themselves * Fix post creator_blocked * Adding creator_blocked to PersonMentionView * Moving blocked and follows to MyUserInfo * Rename to local_user_view * Add moderates to MyUserInfo * Adding BlockCommunityResponse * Fixing name, and check_person_block * Fixing tests. * Using type in Blockable trait. * Changing recipient to target, adding unfollow to block action.
51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use crate::Blockable;
|
|
use diesel::{dsl::*, result::Error, *};
|
|
use lemmy_db_schema::{
|
|
source::person_block::{PersonBlock, PersonBlockForm},
|
|
PersonId,
|
|
};
|
|
|
|
pub trait PersonBlock_ {
|
|
fn read(
|
|
conn: &PgConnection,
|
|
person_id: PersonId,
|
|
target_id: PersonId,
|
|
) -> Result<PersonBlock, Error>;
|
|
}
|
|
|
|
impl PersonBlock_ for PersonBlock {
|
|
fn read(
|
|
conn: &PgConnection,
|
|
for_person_id: PersonId,
|
|
for_recipient_id: PersonId,
|
|
) -> Result<Self, Error> {
|
|
use lemmy_db_schema::schema::person_block::dsl::*;
|
|
person_block
|
|
.filter(person_id.eq(for_person_id))
|
|
.filter(target_id.eq(for_recipient_id))
|
|
.first::<Self>(conn)
|
|
}
|
|
}
|
|
|
|
impl Blockable for PersonBlock {
|
|
type Form = PersonBlockForm;
|
|
fn block(conn: &PgConnection, person_block_form: &PersonBlockForm) -> Result<Self, Error> {
|
|
use lemmy_db_schema::schema::person_block::dsl::*;
|
|
insert_into(person_block)
|
|
.values(person_block_form)
|
|
.on_conflict((person_id, target_id))
|
|
.do_update()
|
|
.set(person_block_form)
|
|
.get_result::<Self>(conn)
|
|
}
|
|
fn unblock(conn: &PgConnection, person_block_form: &Self::Form) -> Result<usize, Error> {
|
|
use lemmy_db_schema::schema::person_block::dsl::*;
|
|
diesel::delete(
|
|
person_block
|
|
.filter(person_id.eq(person_block_form.person_id))
|
|
.filter(target_id.eq(person_block_form.target_id)),
|
|
)
|
|
.execute(conn)
|
|
}
|
|
}
|