Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding extra fields to PostReport and CommentReport views. #4520

Merged
merged 1 commit into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions crates/db_views/src/comment_report_view.rs
Expand Up @@ -18,10 +18,14 @@ use lemmy_db_schema::{
comment_aggregates,
comment_like,
comment_report,
comment_saved,
community,
community_follower,
community_moderator,
community_person_ban,
local_user,
person,
person_block,
post,
},
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
Expand Down Expand Up @@ -64,6 +68,45 @@ fn queries<'a>() -> Queries<
),
),
)
.left_join(
aliases::community_moderator1.on(
community::id
.eq(aliases::community_moderator1.field(community_moderator::community_id))
.and(
aliases::community_moderator1
.field(community_moderator::person_id)
.eq(comment::creator_id),
),
),
)
.left_join(
local_user::table.on(
comment::creator_id
.eq(local_user::person_id)
.and(local_user::admin.eq(true)),
),
)
.left_join(
person_block::table.on(
comment::creator_id
.eq(person_block::target_id)
.and(person_block::person_id.eq(my_person_id)),
),
)
.left_join(
community_follower::table.on(
post::community_id
.eq(community_follower::community_id)
.and(community_follower::person_id.eq(my_person_id)),
),
)
.left_join(
comment_saved::table.on(
comment::id
.eq(comment_saved::comment_id)
.and(comment_saved::person_id.eq(my_person_id)),
),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we could move this stuff into a helper function but its probably tricky.

.select((
comment_report::all_columns,
comment::all_columns,
Expand All @@ -73,6 +116,14 @@ fn queries<'a>() -> Queries<
aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns,
community_person_ban::community_id.nullable().is_not_null(),
aliases::community_moderator1
.field(community_moderator::community_id)
.nullable()
.is_not_null(),
local_user::admin.nullable().is_not_null(),
person_block::target_id.nullable().is_not_null(),
community_follower::pending.nullable(),
comment_saved::published.nullable().is_not_null(),
comment_like::score.nullable(),
aliases::person2.fields(person::all_columns).nullable(),
))
Expand Down Expand Up @@ -229,6 +280,7 @@ mod tests {
traits::{Crud, Joinable, Reportable},
utils::{build_db_pool_for_tests, RANK_DEFAULT},
CommunityVisibility,
SubscribedType,
};
use pretty_assertions::assert_eq;
use serial_test::serial;
Expand Down Expand Up @@ -350,6 +402,11 @@ mod tests {
comment_report: inserted_jessica_report.clone(),
comment: inserted_comment.clone(),
post: inserted_post,
creator_is_moderator: true,
creator_is_admin: false,
creator_blocked: false,
subscribed: SubscribedType::NotSubscribed,
saved: false,
community: Community {
id: inserted_community.id,
name: inserted_community.name,
Expand Down
93 changes: 92 additions & 1 deletion crates/db_views/src/post_report_view.rs
Expand Up @@ -14,15 +14,31 @@ use lemmy_db_schema::{
newtypes::{CommunityId, PersonId, PostId, PostReportId},
schema::{
community,
community_follower,
community_moderator,
community_person_ban,
local_user,
person,
person_block,
person_post_aggregates,
post,
post_aggregates,
post_hide,
post_like,
post_read,
post_report,
post_saved,
},
utils::{
functions::coalesce,
get_conn,
limit_and_offset,
DbConn,
DbPool,
ListFn,
Queries,
ReadFn,
},
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
};

fn queries<'a>() -> Queries<
Expand All @@ -42,6 +58,67 @@ fn queries<'a>() -> Queries<
.and(community_person_ban::person_id.eq(post::creator_id)),
),
)
.left_join(
aliases::community_moderator1.on(
aliases::community_moderator1
.field(community_moderator::community_id)
.eq(post::community_id)
.and(
aliases::community_moderator1
.field(community_moderator::person_id)
.eq(my_person_id),
),
),
)
.left_join(
local_user::table.on(
post::creator_id
.eq(local_user::person_id)
.and(local_user::admin.eq(true)),
),
)
.left_join(
post_saved::table.on(
post::id
.eq(post_saved::post_id)
.and(post_saved::person_id.eq(my_person_id)),
),
)
.left_join(
post_read::table.on(
post::id
.eq(post_read::post_id)
.and(post_read::person_id.eq(my_person_id)),
),
)
.left_join(
post_hide::table.on(
post::id
.eq(post_hide::post_id)
.and(post_hide::person_id.eq(my_person_id)),
),
)
.left_join(
person_block::table.on(
post::creator_id
.eq(person_block::target_id)
.and(person_block::person_id.eq(my_person_id)),
),
)
.left_join(
person_post_aggregates::table.on(
post::id
.eq(person_post_aggregates::post_id)
.and(person_post_aggregates::person_id.eq(my_person_id)),
),
)
.left_join(
community_follower::table.on(
post::community_id
.eq(community_follower::community_id)
.and(community_follower::person_id.eq(my_person_id)),
),
)
.left_join(
post_like::table.on(
post::id
Expand All @@ -61,7 +138,21 @@ fn queries<'a>() -> Queries<
person::all_columns,
aliases::person1.fields(person::all_columns),
community_person_ban::community_id.nullable().is_not_null(),
aliases::community_moderator1
.field(community_moderator::community_id)
.nullable()
.is_not_null(),
local_user::admin.nullable().is_not_null(),
community_follower::pending.nullable(),
post_saved::post_id.nullable().is_not_null(),
post_read::post_id.nullable().is_not_null(),
post_hide::post_id.nullable().is_not_null(),
person_block::target_id.nullable().is_not_null(),
post_like::score.nullable(),
coalesce(
post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(),
post_aggregates::comments,
),
post_aggregates::all_columns,
aliases::person2.fields(person::all_columns.nullable()),
))
Expand Down
13 changes: 13 additions & 0 deletions crates/db_views/src/structs.rs
Expand Up @@ -41,6 +41,11 @@ pub struct CommentReportView {
pub comment_creator: Person,
pub counts: CommentAggregates,
pub creator_banned_from_community: bool,
pub creator_is_moderator: bool,
pub creator_is_admin: bool,
pub creator_blocked: bool,
pub subscribed: SubscribedType,
pub saved: bool,
pub my_vote: Option<i16>,
pub resolver: Option<Person>,
}
Expand Down Expand Up @@ -90,7 +95,15 @@ pub struct PostReportView {
pub creator: Person,
pub post_creator: Person,
pub creator_banned_from_community: bool,
pub creator_is_moderator: bool,
pub creator_is_admin: bool,
pub subscribed: SubscribedType,
pub saved: bool,
pub read: bool,
pub hidden: bool,
pub creator_blocked: bool,
pub my_vote: Option<i16>,
pub unread_comments: i64,
pub counts: PostAggregates,
pub resolver: Option<Person>,
}
Expand Down