Merge branch 'main' into error-expose

This commit is contained in:
SleeplessOne1917 2024-02-18 20:16:58 +00:00 committed by GitHub
commit a15316a94d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 37 deletions

View file

@ -236,7 +236,11 @@ impl<T: LimitDsl> LimitDsl for Commented<T> {
}
pub fn fuzzy_search(q: &str) -> String {
let replaced = q.replace('%', "\\%").replace('_', "\\_").replace(' ', "%");
let replaced = q
.replace('\\', "\\\\")
.replace('%', "\\%")
.replace('_', "\\_")
.replace(' ', "%");
format!("%{replaced}%")
}

View file

@ -52,41 +52,6 @@ fn queries<'a>() -> Queries<
aliases::person2
.on(comment_report::resolver_id.eq(aliases::person2.field(person::id).nullable())),
)
};
let selection = (
comment_report::all_columns,
comment::all_columns,
post::all_columns,
community::all_columns,
person::all_columns,
aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns,
community_person_ban::community_id.nullable().is_not_null(),
comment_like::score.nullable(),
aliases::person2.fields(person::all_columns).nullable(),
);
let read = move |mut conn: DbConn<'a>, (report_id, my_person_id): (CommentReportId, PersonId)| async move {
all_joins(
comment_report::table.find(report_id).into_boxed(),
my_person_id,
)
.left_join(
community_person_ban::table.on(
community::id
.eq(community_person_ban::community_id)
.and(community_person_ban::person_id.eq(comment::creator_id)),
),
)
.select(selection)
.first::<CommentReportView>(&mut conn)
.await
};
let list = move |mut conn: DbConn<'a>,
(options, user): (CommentReportQuery, &'a LocalUserView)| async move {
let mut query = all_joins(comment_report::table.into_boxed(), user.person.id)
.left_join(
community_person_ban::table.on(
community::id
@ -99,7 +64,32 @@ fn queries<'a>() -> Queries<
),
),
)
.select(selection);
.select((
comment_report::all_columns,
comment::all_columns,
post::all_columns,
community::all_columns,
person::all_columns,
aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns,
community_person_ban::community_id.nullable().is_not_null(),
comment_like::score.nullable(),
aliases::person2.fields(person::all_columns).nullable(),
))
};
let read = move |mut conn: DbConn<'a>, (report_id, my_person_id): (CommentReportId, PersonId)| async move {
all_joins(
comment_report::table.find(report_id).into_boxed(),
my_person_id,
)
.first::<CommentReportView>(&mut conn)
.await
};
let list = move |mut conn: DbConn<'a>,
(options, user): (CommentReportQuery, &'a LocalUserView)| async move {
let mut query = all_joins(comment_report::table.into_boxed(), user.person.id);
if let Some(community_id) = options.community_id {
query = query.filter(post::community_id.eq(community_id));

View file

@ -17,6 +17,7 @@ use lemmy_db_schema::{
community_aggregates,
community_block,
community_follower,
community_person_ban,
instance_block,
local_user,
},
@ -58,6 +59,13 @@ fn queries<'a>() -> Queries<
.and(community_block::person_id.eq(person_id_join)),
),
)
.left_join(
community_person_ban::table.on(
community::id
.eq(community_person_ban::community_id)
.and(community_person_ban::person_id.eq(person_id_join)),
),
)
};
let selection = (
@ -65,6 +73,7 @@ fn queries<'a>() -> Queries<
CommunityFollower::select_subscribed_type(),
community_block::community_id.nullable().is_not_null(),
community_aggregates::all_columns,
community_person_ban::person_id.nullable().is_not_null(),
);
let not_removed_or_deleted = community::removed

View file

@ -80,6 +80,7 @@ pub struct CommunityView {
pub subscribed: SubscribedType,
pub blocked: bool,
pub counts: CommunityAggregates,
pub banned_from_community: bool,
}
#[derive(Debug, Serialize, Deserialize, Clone)]