community_follower,
community_person_ban,
person,
- person_alias_1,
person_block,
post,
},
comment::{Comment, CommentSaved},
comment_reply::CommentReply,
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
- person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
+ person::{Person, PersonSafe},
person_block::PersonBlock,
post::Post,
},
- traits::{MaybeOptional, ToSafe, ViewToVec},
+ traits::{ToSafe, ViewToVec},
utils::{functions::hot_rank, limit_and_offset},
CommentSortType,
};
+use typed_builder::TypedBuilder;
type CommentReplyViewTuple = (
CommentReply,
PersonSafe,
Post,
CommunitySafe,
- PersonSafeAlias1,
+ PersonSafe,
CommentAggregates,
Option<CommunityPersonBan>,
Option<CommunityFollower>,
impl CommentReplyView {
pub fn read(
- conn: &PgConnection,
+ conn: &mut PgConnection,
comment_reply_id: CommentReplyId,
my_person_id: Option<PersonId>,
) -> Result<Self, Error> {
+ let person_alias_1 = diesel::alias!(person as person1);
+
// The left join below will return None in this case
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
.inner_join(person::table.on(comment::creator_id.eq(person::id)))
.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_alias_1::table)
+ .inner_join(person_alias_1)
.inner_join(comment_aggregates::table.on(comment::id.eq(comment_aggregates::comment_id)))
.left_join(
community_person_ban::table.on(
Person::safe_columns_tuple(),
post::all_columns,
Community::safe_columns_tuple(),
- PersonAlias1::safe_columns_tuple(),
+ person_alias_1.fields(Person::safe_columns_tuple()),
comment_aggregates::all_columns,
community_person_ban::all_columns.nullable(),
community_follower::all_columns.nullable(),
}
/// Gets the number of unread replies
- pub fn get_unread_replies(conn: &PgConnection, my_person_id: PersonId) -> Result<i64, Error> {
+ pub fn get_unread_replies(conn: &mut PgConnection, my_person_id: PersonId) -> Result<i64, Error> {
use diesel::dsl::*;
comment_reply::table
}
}
-pub struct CommentReplyQueryBuilder<'a> {
- conn: &'a PgConnection,
+#[derive(TypedBuilder)]
+#[builder(field_defaults(default))]
+pub struct CommentReplyQuery<'a> {
+ #[builder(!default)]
+ conn: &'a mut PgConnection,
my_person_id: Option<PersonId>,
recipient_id: Option<PersonId>,
sort: Option<CommentSortType>,
limit: Option<i64>,
}
-impl<'a> CommentReplyQueryBuilder<'a> {
- pub fn create(conn: &'a PgConnection) -> Self {
- CommentReplyQueryBuilder {
- conn,
- my_person_id: None,
- recipient_id: None,
- sort: None,
- unread_only: None,
- show_bot_accounts: None,
- page: None,
- limit: None,
- }
- }
-
- pub fn sort<T: MaybeOptional<CommentSortType>>(mut self, sort: T) -> Self {
- self.sort = sort.get_optional();
- self
- }
-
- pub fn unread_only<T: MaybeOptional<bool>>(mut self, unread_only: T) -> Self {
- self.unread_only = unread_only.get_optional();
- self
- }
-
- pub fn show_bot_accounts<T: MaybeOptional<bool>>(mut self, show_bot_accounts: T) -> Self {
- self.show_bot_accounts = show_bot_accounts.get_optional();
- self
- }
-
- pub fn recipient_id<T: MaybeOptional<PersonId>>(mut self, recipient_id: T) -> Self {
- self.recipient_id = recipient_id.get_optional();
- self
- }
-
- pub fn my_person_id<T: MaybeOptional<PersonId>>(mut self, my_person_id: T) -> Self {
- self.my_person_id = my_person_id.get_optional();
- self
- }
-
- pub fn page<T: MaybeOptional<i64>>(mut self, page: T) -> Self {
- self.page = page.get_optional();
- self
- }
-
- pub fn limit<T: MaybeOptional<i64>>(mut self, limit: T) -> Self {
- self.limit = limit.get_optional();
- self
- }
-
+impl<'a> CommentReplyQuery<'a> {
pub fn list(self) -> Result<Vec<CommentReplyView>, Error> {
use diesel::dsl::*;
+ let person_alias_1 = diesel::alias!(person as person1);
+
// The left join below will return None in this case
let person_id_join = self.my_person_id.unwrap_or(PersonId(-1));
.inner_join(person::table.on(comment::creator_id.eq(person::id)))
.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_alias_1::table)
+ .inner_join(person_alias_1)
.inner_join(comment_aggregates::table.on(comment::id.eq(comment_aggregates::comment_id)))
.left_join(
community_person_ban::table.on(
Person::safe_columns_tuple(),
post::all_columns,
Community::safe_columns_tuple(),
- PersonAlias1::safe_columns_tuple(),
+ person_alias_1.fields(Person::safe_columns_tuple()),
comment_aggregates::all_columns,
community_person_ban::all_columns.nullable(),
community_follower::all_columns.nullable(),