From eeec56c22d8c23bf39a47d12901776c824bed101 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 3 Nov 2023 09:41:00 -0400 Subject: [PATCH] Adding creator_is_moderator to CommentReplyView and PersonMentionView. (#4126) --- crates/db_views_actor/src/comment_reply_view.rs | 9 +++++++++ crates/db_views_actor/src/person_mention_view.rs | 16 ++++++++++++++++ crates/db_views_actor/src/structs.rs | 12 +++++++----- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/crates/db_views_actor/src/comment_reply_view.rs b/crates/db_views_actor/src/comment_reply_view.rs index 6ca4182e8..e5a03eaf6 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -20,6 +20,7 @@ use lemmy_db_schema::{ comment_saved, community, community_follower, + community_moderator, community_person_ban, person, person_block, @@ -80,6 +81,13 @@ fn queries<'a>() -> Queries< .and(comment_like::person_id.eq(person_id_join)), ), ) + .left_join( + community_moderator::table.on( + community::id + .eq(community_moderator::community_id) + .and(community_moderator::person_id.eq(comment::creator_id)), + ), + ) .select(( comment_reply::all_columns, comment::all_columns, @@ -89,6 +97,7 @@ fn queries<'a>() -> Queries< aliases::person1.fields(person::all_columns), comment_aggregates::all_columns, community_person_ban::id.nullable().is_not_null(), + community_moderator::id.nullable().is_not_null(), CommunityFollower::select_subscribed_type(), comment_saved::id.nullable().is_not_null(), person_block::id.nullable().is_not_null(), diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 8d04f9820..c44ee791c 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -20,6 +20,7 @@ use lemmy_db_schema::{ comment_saved, community, community_follower, + community_moderator, community_person_ban, person, person_block, @@ -85,6 +86,7 @@ fn queries<'a>() -> Queries< aliases::person1.fields(person::all_columns), comment_aggregates::all_columns, community_person_ban::id.nullable().is_not_null(), + community_moderator::id.nullable().is_not_null(), CommunityFollower::select_subscribed_type(), comment_saved::id.nullable().is_not_null(), person_block::id.nullable().is_not_null(), @@ -105,6 +107,13 @@ fn queries<'a>() -> Queries< .and(community_person_ban::person_id.eq(comment::creator_id)), ), ) + .left_join( + community_moderator::table.on( + community::id + .eq(community_moderator::community_id) + .and(community_moderator::person_id.eq(comment::creator_id)), + ), + ) .select(selection) .first::(&mut conn) .await @@ -124,6 +133,13 @@ fn queries<'a>() -> Queries< ), ), ) + .left_join( + community_moderator::table.on( + community::id + .eq(community_moderator::community_id) + .and(community_moderator::person_id.eq(comment::creator_id)), + ), + ) .select(selection); if let Some(recipient_id) = options.recipient_id { diff --git a/crates/db_views_actor/src/structs.rs b/crates/db_views_actor/src/structs.rs index bdc9e6bbd..88461701d 100644 --- a/crates/db_views_actor/src/structs.rs +++ b/crates/db_views_actor/src/structs.rs @@ -99,6 +99,7 @@ pub struct PersonMentionView { pub recipient: Person, pub counts: CommentAggregates, pub creator_banned_from_community: bool, + pub creator_is_moderator: bool, pub subscribed: SubscribedType, pub saved: bool, pub creator_blocked: bool, @@ -118,11 +119,12 @@ pub struct CommentReplyView { pub community: Community, pub recipient: Person, pub counts: CommentAggregates, - pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan - pub subscribed: SubscribedType, // Left join to CommunityFollower - pub saved: bool, // Left join to CommentSaved - pub creator_blocked: bool, // Left join to PersonBlock - pub my_vote: Option, // Left join to CommentLike + pub creator_banned_from_community: bool, + pub creator_is_moderator: bool, + pub subscribed: SubscribedType, + pub saved: bool, + pub creator_blocked: bool, + pub my_vote: Option, } #[derive(Debug, Serialize, Deserialize, Clone)]