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.
25 lines
927 B
Rust
25 lines
927 B
Rust
use crate::Blockable;
|
|
use diesel::{dsl::*, result::Error, *};
|
|
use lemmy_db_schema::source::community_block::{CommunityBlock, CommunityBlockForm};
|
|
|
|
impl Blockable for CommunityBlock {
|
|
type Form = CommunityBlockForm;
|
|
fn block(conn: &PgConnection, community_block_form: &Self::Form) -> Result<Self, Error> {
|
|
use lemmy_db_schema::schema::community_block::dsl::*;
|
|
insert_into(community_block)
|
|
.values(community_block_form)
|
|
.on_conflict((person_id, community_id))
|
|
.do_update()
|
|
.set(community_block_form)
|
|
.get_result::<Self>(conn)
|
|
}
|
|
fn unblock(conn: &PgConnection, community_block_form: &Self::Form) -> Result<usize, Error> {
|
|
use lemmy_db_schema::schema::community_block::dsl::*;
|
|
diesel::delete(
|
|
community_block
|
|
.filter(person_id.eq(community_block_form.person_id))
|
|
.filter(community_id.eq(community_block_form.community_id)),
|
|
)
|
|
.execute(conn)
|
|
}
|
|
}
|