mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-09 09:52:10 +00:00
Merge branch 'main' into fix_is_community_mod_check
This commit is contained in:
commit
26b81b62ad
|
@ -240,10 +240,13 @@ steps:
|
|||
|
||||
publish_release_docker:
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
secrets: [docker_username, docker_password]
|
||||
settings:
|
||||
repo: dessalines/lemmy
|
||||
dockerfile: docker/Dockerfile
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
platforms: linux/amd64, linux/arm64
|
||||
build_args:
|
||||
- RUST_RELEASE_MODE=release
|
||||
|
@ -253,10 +256,13 @@ steps:
|
|||
|
||||
nightly_build:
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
secrets: [docker_username, docker_password]
|
||||
settings:
|
||||
repo: dessalines/lemmy
|
||||
dockerfile: docker/Dockerfile
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
platforms: linux/amd64,linux/arm64
|
||||
build_args:
|
||||
- RUST_RELEASE_MODE=release
|
||||
|
|
|
@ -133,7 +133,6 @@ pub async fn save_user_settings(
|
|||
blur_nsfw: data.blur_nsfw,
|
||||
auto_expand: data.auto_expand,
|
||||
show_bot_accounts: data.show_bot_accounts,
|
||||
show_scores: data.show_scores,
|
||||
default_sort_type,
|
||||
default_listing_type,
|
||||
theme: data.theme.clone(),
|
||||
|
|
|
@ -11,10 +11,12 @@ use lemmy_db_schema::{
|
|||
RegistrationApplicationId,
|
||||
},
|
||||
source::{
|
||||
community::Community,
|
||||
federation_queue_state::FederationQueueState,
|
||||
instance::Instance,
|
||||
language::Language,
|
||||
local_site_url_blocklist::LocalSiteUrlBlocklist,
|
||||
person::Person,
|
||||
tagline::Tagline,
|
||||
},
|
||||
ListingType,
|
||||
|
@ -33,12 +35,9 @@ use lemmy_db_views::structs::{
|
|||
SiteView,
|
||||
};
|
||||
use lemmy_db_views_actor::structs::{
|
||||
CommunityBlockView,
|
||||
CommunityFollowerView,
|
||||
CommunityModeratorView,
|
||||
CommunityView,
|
||||
InstanceBlockView,
|
||||
PersonBlockView,
|
||||
PersonView,
|
||||
};
|
||||
use lemmy_db_views_moderator::structs::{
|
||||
|
@ -337,9 +336,9 @@ pub struct MyUserInfo {
|
|||
pub local_user_view: LocalUserView,
|
||||
pub follows: Vec<CommunityFollowerView>,
|
||||
pub moderates: Vec<CommunityModeratorView>,
|
||||
pub community_blocks: Vec<CommunityBlockView>,
|
||||
pub instance_blocks: Vec<InstanceBlockView>,
|
||||
pub person_blocks: Vec<PersonBlockView>,
|
||||
pub community_blocks: Vec<Community>,
|
||||
pub instance_blocks: Vec<Instance>,
|
||||
pub person_blocks: Vec<Person>,
|
||||
pub discussion_languages: Vec<LanguageId>,
|
||||
}
|
||||
|
||||
|
|
|
@ -252,9 +252,9 @@ pub async fn check_person_instance_community_block(
|
|||
community_id: CommunityId,
|
||||
pool: &mut DbPool<'_>,
|
||||
) -> LemmyResult<()> {
|
||||
PersonBlock::check(pool, potential_blocker_id, my_id).await?;
|
||||
InstanceBlock::check(pool, potential_blocker_id, community_instance_id).await?;
|
||||
CommunityBlock::check(pool, potential_blocker_id, community_id).await?;
|
||||
PersonBlock::read(pool, potential_blocker_id, my_id).await?;
|
||||
InstanceBlock::read(pool, potential_blocker_id, community_instance_id).await?;
|
||||
CommunityBlock::read(pool, potential_blocker_id, community_id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ pub async fn create_private_message(
|
|||
let content = process_markdown(&data.content, &slur_regex, &url_blocklist, &context).await?;
|
||||
is_valid_body_field(&content, false)?;
|
||||
|
||||
PersonBlock::check(
|
||||
PersonBlock::read(
|
||||
&mut context.pool(),
|
||||
data.recipient_id,
|
||||
local_user_view.person.id,
|
||||
|
|
|
@ -5,19 +5,15 @@ use lemmy_api_common::{
|
|||
};
|
||||
use lemmy_db_schema::source::{
|
||||
actor_language::{LocalUserLanguage, SiteLanguage},
|
||||
community_block::CommunityBlock,
|
||||
instance_block::InstanceBlock,
|
||||
language::Language,
|
||||
local_site_url_blocklist::LocalSiteUrlBlocklist,
|
||||
person_block::PersonBlock,
|
||||
tagline::Tagline,
|
||||
};
|
||||
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView};
|
||||
use lemmy_db_views_actor::structs::{
|
||||
CommunityBlockView,
|
||||
CommunityFollowerView,
|
||||
CommunityModeratorView,
|
||||
InstanceBlockView,
|
||||
PersonBlockView,
|
||||
PersonView,
|
||||
};
|
||||
use lemmy_db_views_actor::structs::{CommunityFollowerView, CommunityModeratorView, PersonView};
|
||||
use lemmy_utils::{
|
||||
error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult},
|
||||
CACHE_DURATION_API,
|
||||
|
@ -81,9 +77,9 @@ pub async fn get_site(
|
|||
discussion_languages,
|
||||
) = lemmy_db_schema::try_join_with_pool!(pool => (
|
||||
|pool| CommunityFollowerView::for_person(pool, person_id),
|
||||
|pool| CommunityBlockView::for_person(pool, person_id),
|
||||
|pool| InstanceBlockView::for_person(pool, person_id),
|
||||
|pool| PersonBlockView::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| CommunityModeratorView::for_person(pool, person_id, Some(&local_user_view.local_user)),
|
||||
|pool| LocalUserLanguage::read(pool, local_user_id)
|
||||
))
|
||||
|
|
|
@ -122,7 +122,6 @@ pub async fn import_settings(
|
|||
.settings
|
||||
.as_ref()
|
||||
.map(|s| s.send_notifications_to_email),
|
||||
show_scores: data.settings.as_ref().map(|s| s.show_scores),
|
||||
show_bot_accounts: data.settings.as_ref().map(|s| s.show_bot_accounts),
|
||||
show_read_posts: data.settings.as_ref().map(|s| s.show_read_posts),
|
||||
open_links_in_new_tab: data.settings.as_ref().map(|s| s.open_links_in_new_tab),
|
||||
|
|
|
@ -131,7 +131,7 @@ impl Object for ApubPrivateMessage {
|
|||
) -> LemmyResult<ApubPrivateMessage> {
|
||||
let creator = note.attributed_to.dereference(context).await?;
|
||||
let recipient = note.to[0].dereference(context).await?;
|
||||
PersonBlock::check(&mut context.pool(), recipient.id, creator.id).await?;
|
||||
PersonBlock::read(&mut context.pool(), recipient.id, creator.id).await?;
|
||||
|
||||
let local_site = LocalSite::read(&mut context.pool()).await.ok();
|
||||
let slur_regex = &local_site_opt_to_slur_regex(&local_site);
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use crate::{
|
||||
newtypes::{CommunityId, PersonId},
|
||||
schema::community_block::dsl::{community_block, community_id, person_id},
|
||||
source::community_block::{CommunityBlock, CommunityBlockForm},
|
||||
schema::{community, community_block},
|
||||
source::{
|
||||
community::Community,
|
||||
community_block::{CommunityBlock, CommunityBlockForm},
|
||||
},
|
||||
traits::Blockable,
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
@ -9,26 +12,43 @@ use diesel::{
|
|||
dsl::{exists, insert_into, not},
|
||||
result::Error,
|
||||
select,
|
||||
ExpressionMethods,
|
||||
QueryDsl,
|
||||
};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
||||
|
||||
impl CommunityBlock {
|
||||
pub async fn check(
|
||||
pub async fn read(
|
||||
pool: &mut DbPool<'_>,
|
||||
for_person_id: PersonId,
|
||||
for_community_id: CommunityId,
|
||||
) -> LemmyResult<()> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
select(not(exists(
|
||||
community_block.find((for_person_id, for_community_id)),
|
||||
community_block::table.find((for_person_id, for_community_id)),
|
||||
)))
|
||||
.get_result::<bool>(conn)
|
||||
.await?
|
||||
.then_some(())
|
||||
.ok_or(LemmyErrorType::CommunityIsBlocked.into())
|
||||
}
|
||||
|
||||
pub async fn for_person(
|
||||
pool: &mut DbPool<'_>,
|
||||
person_id: PersonId,
|
||||
) -> Result<Vec<Community>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
community_block::table
|
||||
.inner_join(community::table)
|
||||
.select(community::all_columns)
|
||||
.filter(community_block::person_id.eq(person_id))
|
||||
.filter(community::deleted.eq(false))
|
||||
.filter(community::removed.eq(false))
|
||||
.order_by(community_block::published)
|
||||
.load::<Community>(conn)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -36,9 +56,9 @@ impl Blockable for CommunityBlock {
|
|||
type Form = CommunityBlockForm;
|
||||
async fn block(pool: &mut DbPool<'_>, community_block_form: &Self::Form) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(community_block)
|
||||
insert_into(community_block::table)
|
||||
.values(community_block_form)
|
||||
.on_conflict((person_id, community_id))
|
||||
.on_conflict((community_block::person_id, community_block::community_id))
|
||||
.do_update()
|
||||
.set(community_block_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -49,7 +69,7 @@ impl Blockable for CommunityBlock {
|
|||
community_block_form: &Self::Form,
|
||||
) -> Result<usize, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::delete(community_block.find((
|
||||
diesel::delete(community_block::table.find((
|
||||
community_block_form.person_id,
|
||||
community_block_form.community_id,
|
||||
)))
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use crate::{
|
||||
newtypes::{InstanceId, PersonId},
|
||||
schema::instance_block::dsl::{instance_block, instance_id, person_id},
|
||||
source::instance_block::{InstanceBlock, InstanceBlockForm},
|
||||
schema::{instance, instance_block},
|
||||
source::{
|
||||
instance::Instance,
|
||||
instance_block::{InstanceBlock, InstanceBlockForm},
|
||||
},
|
||||
traits::Blockable,
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
@ -9,26 +12,41 @@ use diesel::{
|
|||
dsl::{exists, insert_into, not},
|
||||
result::Error,
|
||||
select,
|
||||
ExpressionMethods,
|
||||
QueryDsl,
|
||||
};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
||||
|
||||
impl InstanceBlock {
|
||||
pub async fn check(
|
||||
pub async fn read(
|
||||
pool: &mut DbPool<'_>,
|
||||
for_person_id: PersonId,
|
||||
for_instance_id: InstanceId,
|
||||
) -> LemmyResult<()> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
select(not(exists(
|
||||
instance_block.find((for_person_id, for_instance_id)),
|
||||
instance_block::table.find((for_person_id, for_instance_id)),
|
||||
)))
|
||||
.get_result::<bool>(conn)
|
||||
.await?
|
||||
.then_some(())
|
||||
.ok_or(LemmyErrorType::InstanceIsBlocked.into())
|
||||
}
|
||||
|
||||
pub async fn for_person(
|
||||
pool: &mut DbPool<'_>,
|
||||
person_id: PersonId,
|
||||
) -> Result<Vec<Instance>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
instance_block::table
|
||||
.inner_join(instance::table)
|
||||
.select(instance::all_columns)
|
||||
.filter(instance_block::person_id.eq(person_id))
|
||||
.order_by(instance_block::published)
|
||||
.load::<Instance>(conn)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -36,9 +54,9 @@ impl Blockable for InstanceBlock {
|
|||
type Form = InstanceBlockForm;
|
||||
async fn block(pool: &mut DbPool<'_>, instance_block_form: &Self::Form) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(instance_block)
|
||||
insert_into(instance_block::table)
|
||||
.values(instance_block_form)
|
||||
.on_conflict((person_id, instance_id))
|
||||
.on_conflict((instance_block::person_id, instance_block::instance_id))
|
||||
.do_update()
|
||||
.set(instance_block_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -49,7 +67,7 @@ impl Blockable for InstanceBlock {
|
|||
instance_block_form: &Self::Form,
|
||||
) -> Result<usize, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::delete(instance_block.find((
|
||||
diesel::delete(instance_block::table.find((
|
||||
instance_block_form.person_id,
|
||||
instance_block_form.instance_id,
|
||||
)))
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use crate::{
|
||||
newtypes::PersonId,
|
||||
schema::person_block::dsl::{person_block, person_id, target_id},
|
||||
source::person_block::{PersonBlock, PersonBlockForm},
|
||||
schema::{person, person_block},
|
||||
source::{
|
||||
person::Person,
|
||||
person_block::{PersonBlock, PersonBlockForm},
|
||||
},
|
||||
traits::Blockable,
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
@ -9,26 +12,48 @@ use diesel::{
|
|||
dsl::{exists, insert_into, not},
|
||||
result::Error,
|
||||
select,
|
||||
ExpressionMethods,
|
||||
JoinOnDsl,
|
||||
QueryDsl,
|
||||
};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
||||
|
||||
impl PersonBlock {
|
||||
pub async fn check(
|
||||
pub async fn read(
|
||||
pool: &mut DbPool<'_>,
|
||||
for_person_id: PersonId,
|
||||
for_recipient_id: PersonId,
|
||||
) -> LemmyResult<()> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
select(not(exists(
|
||||
person_block.find((for_person_id, for_recipient_id)),
|
||||
person_block::table.find((for_person_id, for_recipient_id)),
|
||||
)))
|
||||
.get_result::<bool>(conn)
|
||||
.await?
|
||||
.then_some(())
|
||||
.ok_or(LemmyErrorType::PersonIsBlocked.into())
|
||||
}
|
||||
|
||||
pub async fn for_person(
|
||||
pool: &mut DbPool<'_>,
|
||||
person_id: PersonId,
|
||||
) -> Result<Vec<Person>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
let target_person_alias = diesel::alias!(person as person1);
|
||||
|
||||
person_block::table
|
||||
.inner_join(person::table.on(person_block::person_id.eq(person::id)))
|
||||
.inner_join(
|
||||
target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))),
|
||||
)
|
||||
.select(target_person_alias.fields(person::all_columns))
|
||||
.filter(person_block::person_id.eq(person_id))
|
||||
.filter(target_person_alias.field(person::deleted).eq(false))
|
||||
.order_by(person_block::published)
|
||||
.load::<Person>(conn)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -39,9 +64,9 @@ impl Blockable for PersonBlock {
|
|||
person_block_form: &PersonBlockForm,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(person_block)
|
||||
insert_into(person_block::table)
|
||||
.values(person_block_form)
|
||||
.on_conflict((person_id, target_id))
|
||||
.on_conflict((person_block::person_id, person_block::target_id))
|
||||
.do_update()
|
||||
.set(person_block_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -49,8 +74,10 @@ impl Blockable for PersonBlock {
|
|||
}
|
||||
async fn unblock(pool: &mut DbPool<'_>, person_block_form: &Self::Form) -> Result<usize, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::delete(person_block.find((person_block_form.person_id, person_block_form.target_id)))
|
||||
.execute(conn)
|
||||
.await
|
||||
diesel::delete(
|
||||
person_block::table.find((person_block_form.person_id, person_block_form.target_id)),
|
||||
)
|
||||
.execute(conn)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -446,7 +446,6 @@ diesel::table! {
|
|||
interface_language -> Varchar,
|
||||
show_avatars -> Bool,
|
||||
send_notifications_to_email -> Bool,
|
||||
show_scores -> Bool,
|
||||
show_bot_accounts -> Bool,
|
||||
show_read_posts -> Bool,
|
||||
email_verified -> Bool,
|
||||
|
|
|
@ -35,9 +35,6 @@ pub struct LocalUser {
|
|||
/// Whether to show avatars.
|
||||
pub show_avatars: bool,
|
||||
pub send_notifications_to_email: bool,
|
||||
/// Whether to show comment / post scores.
|
||||
// TODO now that there is a vote_display_mode, this can be gotten rid of in future releases.
|
||||
pub show_scores: bool,
|
||||
/// Whether to show bot accounts.
|
||||
pub show_bot_accounts: bool,
|
||||
/// Whether to show read posts.
|
||||
|
@ -93,8 +90,6 @@ pub struct LocalUserInsertForm {
|
|||
#[new(default)]
|
||||
pub show_bot_accounts: Option<bool>,
|
||||
#[new(default)]
|
||||
pub show_scores: Option<bool>,
|
||||
#[new(default)]
|
||||
pub show_read_posts: Option<bool>,
|
||||
#[new(default)]
|
||||
pub email_verified: Option<bool>,
|
||||
|
@ -138,7 +133,6 @@ pub struct LocalUserUpdateForm {
|
|||
pub show_avatars: Option<bool>,
|
||||
pub send_notifications_to_email: Option<bool>,
|
||||
pub show_bot_accounts: Option<bool>,
|
||||
pub show_scores: Option<bool>,
|
||||
pub show_read_posts: Option<bool>,
|
||||
pub email_verified: Option<bool>,
|
||||
pub accepted_application: Option<bool>,
|
||||
|
|
|
@ -252,7 +252,6 @@ mod tests {
|
|||
show_avatars: inserted_sara_local_user.show_avatars,
|
||||
send_notifications_to_email: inserted_sara_local_user.send_notifications_to_email,
|
||||
show_bot_accounts: inserted_sara_local_user.show_bot_accounts,
|
||||
show_scores: inserted_sara_local_user.show_scores,
|
||||
show_read_posts: inserted_sara_local_user.show_read_posts,
|
||||
email_verified: inserted_sara_local_user.email_verified,
|
||||
accepted_application: inserted_sara_local_user.accepted_application,
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
use crate::structs::CommunityBlockView;
|
||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, community_block, person},
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
||||
impl CommunityBlockView {
|
||||
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
community_block::table
|
||||
.inner_join(person::table)
|
||||
.inner_join(community::table)
|
||||
.select((person::all_columns, community::all_columns))
|
||||
.filter(community_block::person_id.eq(person_id))
|
||||
.filter(community::deleted.eq(false))
|
||||
.filter(community::removed.eq(false))
|
||||
.order_by(community_block::published)
|
||||
.load::<CommunityBlockView>(conn)
|
||||
.await
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
use crate::structs::InstanceBlockView;
|
||||
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{instance, instance_block, person, site},
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
||||
impl InstanceBlockView {
|
||||
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
instance_block::table
|
||||
.inner_join(person::table)
|
||||
.inner_join(instance::table)
|
||||
.left_join(site::table.on(site::instance_id.eq(instance::id)))
|
||||
.select((
|
||||
person::all_columns,
|
||||
instance::all_columns,
|
||||
site::all_columns.nullable(),
|
||||
))
|
||||
.filter(instance_block::person_id.eq(person_id))
|
||||
.order_by(instance_block::published)
|
||||
.load::<InstanceBlockView>(conn)
|
||||
.await
|
||||
}
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
#[cfg(feature = "full")]
|
||||
pub mod comment_reply_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod community_block_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod community_follower_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod community_moderator_view;
|
||||
|
@ -11,10 +9,6 @@ pub mod community_person_ban_view;
|
|||
#[cfg(feature = "full")]
|
||||
pub mod community_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod instance_block_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod person_block_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod person_mention_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod person_view;
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
use crate::structs::PersonBlockView;
|
||||
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{person, person_block},
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
||||
impl PersonBlockView {
|
||||
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
let target_person_alias = diesel::alias!(person as person1);
|
||||
|
||||
person_block::table
|
||||
.inner_join(person::table.on(person_block::person_id.eq(person::id)))
|
||||
.inner_join(
|
||||
target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))),
|
||||
)
|
||||
.select((
|
||||
person::all_columns,
|
||||
target_person_alias.fields(person::all_columns),
|
||||
))
|
||||
.filter(person_block::person_id.eq(person_id))
|
||||
.filter(target_person_alias.field(person::deleted).eq(false))
|
||||
.order_by(person_block::published)
|
||||
.load::<PersonBlockView>(conn)
|
||||
.await
|
||||
}
|
||||
}
|
|
@ -6,11 +6,9 @@ use lemmy_db_schema::{
|
|||
comment::Comment,
|
||||
comment_reply::CommentReply,
|
||||
community::Community,
|
||||
instance::Instance,
|
||||
person::Person,
|
||||
person_mention::PersonMention,
|
||||
post::Post,
|
||||
site::Site,
|
||||
},
|
||||
SubscribedType,
|
||||
};
|
||||
|
@ -19,28 +17,6 @@ use serde_with::skip_serializing_none;
|
|||
#[cfg(feature = "full")]
|
||||
use ts_rs::TS;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
||||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// A community block.
|
||||
pub struct CommunityBlockView {
|
||||
pub person: Person,
|
||||
pub community: Community,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
||||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// An instance block by a user.
|
||||
pub struct InstanceBlockView {
|
||||
pub person: Person,
|
||||
pub instance: Instance,
|
||||
pub site: Option<Site>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
||||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
|
@ -83,16 +59,6 @@ pub struct CommunityView {
|
|||
pub banned_from_community: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
||||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// A person block.
|
||||
pub struct PersonBlockView {
|
||||
pub person: Person,
|
||||
pub target: Person,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE local_user
|
||||
ADD COLUMN show_scores boolean NOT NULL DEFAULT TRUE;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE local_user
|
||||
DROP COLUMN show_scores;
|
||||
|
Loading…
Reference in a new issue