2024-12-19 22:22:31 +00:00
|
|
|
use crate::structs::PostReportView;
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel::{
|
|
|
|
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::{PersonId, PostReportId},
|
2021-09-28 10:36:17 +00:00
|
|
|
schema::{
|
|
|
|
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-11 10:34:10 +00:00
|
|
|
post_actions,
|
2021-09-28 10:36:17 +00:00
|
|
|
post_aggregates,
|
|
|
|
post_report,
|
2024-03-13 16:11:24 +00:00
|
|
|
},
|
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 17:27:25 +00:00
|
|
|
};
|
2020-12-17 03:03:03 +00:00
|
|
|
|
2024-12-19 22:22:31 +00:00
|
|
|
impl PostReportView {
|
|
|
|
/// returns the PostReportView for the provided report_id
|
|
|
|
///
|
|
|
|
/// * `report_id` - the report id to obtain
|
|
|
|
pub async fn read(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
report_id: PostReportId,
|
|
|
|
my_person_id: PersonId,
|
|
|
|
) -> Result<Self, Error> {
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
|
|
|
|
post_report::table
|
|
|
|
.find(report_id)
|
2020-12-17 03:03:03 +00:00
|
|
|
.inner_join(post::table)
|
|
|
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
2021-03-10 22:33:55 +00:00
|
|
|
.inner_join(person::table.on(post_report::creator_id.eq(person::id)))
|
2023-07-28 08:36:50 +00:00
|
|
|
.inner_join(aliases::person1.on(post::creator_id.eq(aliases::person1.field(person::id))))
|
2024-11-11 10:34:10 +00:00
|
|
|
.left_join(actions_alias(
|
|
|
|
creator_community_actions,
|
|
|
|
post::creator_id,
|
|
|
|
post::community_id,
|
|
|
|
))
|
|
|
|
.left_join(actions(
|
|
|
|
community_actions::table,
|
|
|
|
Some(my_person_id),
|
|
|
|
post::community_id,
|
|
|
|
))
|
2024-03-13 16:11:24 +00:00
|
|
|
.left_join(
|
|
|
|
local_user::table.on(
|
|
|
|
post::creator_id
|
|
|
|
.eq(local_user::person_id)
|
|
|
|
.and(local_user::admin.eq(true)),
|
|
|
|
),
|
|
|
|
)
|
2024-11-11 10:34:10 +00:00
|
|
|
.left_join(actions(post_actions::table, Some(my_person_id), post::id))
|
|
|
|
.left_join(actions(
|
|
|
|
person_actions::table,
|
|
|
|
Some(my_person_id),
|
|
|
|
post::creator_id,
|
|
|
|
))
|
2021-09-28 10:36:17 +00:00
|
|
|
.inner_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id)))
|
2021-03-11 04:43:11 +00:00
|
|
|
.left_join(
|
2023-07-28 08:36:50 +00:00
|
|
|
aliases::person2
|
|
|
|
.on(post_report::resolver_id.eq(aliases::person2.field(person::id).nullable())),
|
2021-03-11 04:43:11 +00:00
|
|
|
)
|
2020-12-17 03:03:03 +00:00
|
|
|
.select((
|
|
|
|
post_report::all_columns,
|
|
|
|
post::all_columns,
|
2023-03-01 17:19:46 +00:00
|
|
|
community::all_columns,
|
|
|
|
person::all_columns,
|
2023-07-28 08:36:50 +00:00
|
|
|
aliases::person1.fields(person::all_columns),
|
2024-11-11 10:34:10 +00:00
|
|
|
creator_community_actions
|
|
|
|
.field(community_actions::received_ban)
|
|
|
|
.nullable()
|
|
|
|
.is_not_null(),
|
|
|
|
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-07 10:49:05 +00:00
|
|
|
CommunityFollower::select_subscribed_type(),
|
2024-11-11 10:34:10 +00:00
|
|
|
post_actions::saved.nullable().is_not_null(),
|
|
|
|
post_actions::read.nullable().is_not_null(),
|
|
|
|
post_actions::hidden.nullable().is_not_null(),
|
|
|
|
person_actions::blocked.nullable().is_not_null(),
|
|
|
|
post_actions::like_score.nullable(),
|
2024-03-13 16:11:24 +00:00
|
|
|
coalesce(
|
2024-11-11 10:34:10 +00:00
|
|
|
post_aggregates::comments.nullable() - post_actions::read_comments_amount.nullable(),
|
2024-03-13 16:11:24 +00:00
|
|
|
post_aggregates::comments,
|
|
|
|
),
|
2021-09-28 10:36:17 +00:00
|
|
|
post_aggregates::all_columns,
|
2023-07-28 08:36:50 +00:00
|
|
|
aliases::person2.fields(person::all_columns.nullable()),
|
2020-12-17 03:03:03 +00:00
|
|
|
))
|
2024-12-19 22:22:31 +00:00
|
|
|
.first(conn)
|
|
|
|
.await
|
2021-09-28 10:36:17 +00:00
|
|
|
}
|
|
|
|
}
|