1 use crate::structs::{ModRemoveCommentView, ModlogListParams};
8 NullableExpressionMethods,
11 use diesel_async::RunQueryDsl;
12 use lemmy_db_schema::{
14 schema::{comment, community, mod_remove_comment, person, post},
18 moderator::ModRemoveComment,
23 utils::{get_conn, limit_and_offset, DbPool},
26 type ModRemoveCommentViewTuple = (
35 impl ModRemoveCommentView {
36 pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
37 let conn = &mut get_conn(pool).await?;
38 let person_alias_1 = diesel::alias!(lemmy_db_schema::schema::person as person1);
39 let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
40 let show_mod_names = !params.hide_modlog_names;
41 let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
43 let admin_names_join = mod_remove_comment::mod_person_id
45 .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
46 let mut query = mod_remove_comment::table
47 .left_join(person::table.on(admin_names_join))
48 .inner_join(comment::table)
49 .inner_join(person_alias_1.on(comment::creator_id.eq(person_alias_1.field(person::id))))
50 .inner_join(post::table.on(comment::post_id.eq(post::id)))
51 .inner_join(community::table.on(post::community_id.eq(community::id)))
53 mod_remove_comment::all_columns,
54 person::all_columns.nullable(),
56 person_alias_1.fields(person::all_columns),
58 community::all_columns,
62 if let Some(community_id) = params.community_id {
63 query = query.filter(post::community_id.eq(community_id));
66 if let Some(mod_person_id) = params.mod_person_id {
67 query = query.filter(mod_remove_comment::mod_person_id.eq(mod_person_id));
70 if let Some(other_person_id) = params.other_person_id {
71 query = query.filter(person_alias_1.field(person::id).eq(other_person_id));
74 let (limit, offset) = limit_and_offset(params.page, params.limit)?;
79 .order_by(mod_remove_comment::when_.desc())
80 .load::<ModRemoveCommentViewTuple>(conn)
83 let results = res.into_iter().map(Self::from_tuple).collect();
88 impl JoinView for ModRemoveCommentView {
89 type JoinTuple = ModRemoveCommentViewTuple;
90 fn from_tuple(a: Self::JoinTuple) -> Self {
92 mod_remove_comment: a.0,