2024-12-19 22:22:31 +00:00
|
|
|
use crate::structs::CommentReportView;
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel::{
|
2022-11-19 04:33:54 +00:00
|
|
|
dsl::now,
|
2022-11-09 10:05:00 +00:00
|
|
|
result::Error,
|
|
|
|
BoolExpressionMethods,
|
|
|
|
ExpressionMethods,
|
|
|
|
JoinOnDsl,
|
|
|
|
NullableExpressionMethods,
|
|
|
|
QueryDsl,
|
|
|
|
};
|
|
|
|
use diesel_async::RunQueryDsl;
|
2021-10-16 13:33:38 +00:00
|
|
|
use lemmy_db_schema::{
|
2024-11-11 10:34:10 +00:00
|
|
|
aliases::{self, creator_community_actions},
|
2024-12-19 22:22:31 +00:00
|
|
|
newtypes::{CommentReportId, PersonId},
|
2021-09-28 10:36:17 +00:00
|
|
|
schema::{
|
|
|
|
comment,
|
2024-11-11 10:34:10 +00:00
|
|
|
comment_actions,
|
2021-09-28 10:36:17 +00:00
|
|
|
comment_aggregates,
|
|
|
|
comment_report,
|
|
|
|
community,
|
2024-11-11 10:34:10 +00:00
|
|
|
community_actions,
|
2024-03-13 16:11:24 +00:00
|
|
|
local_user,
|
2021-09-28 10:36:17 +00:00
|
|
|
person,
|
2024-11-11 10:34:10 +00:00
|
|
|
person_actions,
|
2021-09-28 10:36:17 +00:00
|
|
|
post,
|
|
|
|
},
|
2024-11-07 10:49:05 +00:00
|
|
|
source::community::CommunityFollower,
|
2024-12-19 22:22:31 +00:00
|
|
|
utils::{actions, actions_alias, functions::coalesce, get_conn, DbPool},
|
2020-12-18 16:17:21 +00:00
|
|
|
};
|
2020-12-17 03:03:03 +00:00
|
|
|
|
2024-12-19 22:22:31 +00:00
|
|
|
impl CommentReportView {
|
|
|
|
/// returns the CommentReportView for the provided report_id
|
|
|
|
///
|
|
|
|
/// * `report_id` - the report id to obtain
|
|
|
|
pub async fn read(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
report_id: CommentReportId,
|
|
|
|
my_person_id: PersonId,
|
|
|
|
) -> Result<Self, Error> {
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
comment_report::table
|
|
|
|
.find(report_id)
|
2021-09-28 10:36:17 +00:00
|
|
|
.inner_join(comment::table)
|
|
|
|
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
|
|
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
|
|
|
.inner_join(person::table.on(comment_report::creator_id.eq(person::id)))
|
2023-07-28 08:36:50 +00:00
|
|
|
.inner_join(aliases::person1.on(comment::creator_id.eq(aliases::person1.field(person::id))))
|
2021-09-28 10:36:17 +00:00
|
|
|
.inner_join(
|
|
|
|
comment_aggregates::table.on(comment_report::comment_id.eq(comment_aggregates::comment_id)),
|
|
|
|
)
|
2024-11-11 10:34:10 +00:00
|
|
|
.left_join(actions(
|
|
|
|
comment_actions::table,
|
|
|
|
Some(my_person_id),
|
|
|
|
comment_report::comment_id,
|
|
|
|
))
|
2021-09-28 10:36:17 +00:00
|
|
|
.left_join(
|
2023-07-28 08:36:50 +00:00
|
|
|
aliases::person2
|
|
|
|
.on(comment_report::resolver_id.eq(aliases::person2.field(person::id).nullable())),
|
|
|
|
)
|
2024-11-11 10:34:10 +00:00
|
|
|
.left_join(actions_alias(
|
|
|
|
creator_community_actions,
|
|
|
|
comment::creator_id,
|
|
|
|
post::community_id,
|
|
|
|
))
|
2024-03-13 16:11:24 +00:00
|
|
|
.left_join(
|
|
|
|
local_user::table.on(
|
|
|
|
comment::creator_id
|
|
|
|
.eq(local_user::person_id)
|
|
|
|
.and(local_user::admin.eq(true)),
|
|
|
|
),
|
|
|
|
)
|
2024-11-11 10:34:10 +00:00
|
|
|
.left_join(actions(
|
|
|
|
person_actions::table,
|
|
|
|
Some(my_person_id),
|
|
|
|
comment::creator_id,
|
|
|
|
))
|
|
|
|
.left_join(actions(
|
|
|
|
community_actions::table,
|
|
|
|
Some(my_person_id),
|
|
|
|
post::community_id,
|
|
|
|
))
|
2024-02-18 14:12:12 +00:00
|
|
|
.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,
|
2024-11-11 10:34:10 +00:00
|
|
|
coalesce(
|
|
|
|
creator_community_actions
|
|
|
|
.field(community_actions::received_ban)
|
|
|
|
.nullable()
|
|
|
|
.is_not_null()
|
|
|
|
.or(
|
|
|
|
creator_community_actions
|
|
|
|
.field(community_actions::ban_expires)
|
|
|
|
.nullable()
|
|
|
|
.gt(now),
|
|
|
|
),
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
creator_community_actions
|
|
|
|
.field(community_actions::became_moderator)
|
2024-03-13 16:11:24 +00:00
|
|
|
.nullable()
|
|
|
|
.is_not_null(),
|
|
|
|
local_user::admin.nullable().is_not_null(),
|
2024-11-11 10:34:10 +00:00
|
|
|
person_actions::blocked.nullable().is_not_null(),
|
2024-11-07 10:49:05 +00:00
|
|
|
CommunityFollower::select_subscribed_type(),
|
2024-11-11 10:34:10 +00:00
|
|
|
comment_actions::saved.nullable().is_not_null(),
|
|
|
|
comment_actions::like_score.nullable(),
|
2024-02-18 14:12:12 +00:00
|
|
|
aliases::person2.fields(person::all_columns).nullable(),
|
|
|
|
))
|
2024-12-19 22:22:31 +00:00
|
|
|
.first(conn)
|
|
|
|
.await
|
2021-09-28 10:36:17 +00:00
|
|
|
}
|
|
|
|
}
|