use crate::{
newtypes::{CommunityId, DbUrl, PersonId},
- schema::{community, instance},
+ schema::{community, community_follower, instance},
source::{
actor_language::CommunityLanguage,
community::{
utils::{functions::lower, get_conn, DbPool},
SubscribedType,
};
-use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{
+ deserialize,
+ dsl,
+ dsl::insert_into,
+ pg::Pg,
+ result::Error,
+ sql_types,
+ ExpressionMethods,
+ NullableExpressionMethods,
+ QueryDsl,
+ Queryable,
+};
use diesel_async::RunQueryDsl;
#[async_trait]
None => SubscribedType::NotSubscribed,
}
}
+
+ pub fn select_subscribed_type() -> dsl::Nullable<community_follower::pending> {
+ community_follower::pending.nullable()
+ }
+}
+
+impl Queryable<sql_types::Nullable<sql_types::Bool>, Pg> for SubscribedType {
+ type Row = Option<bool>;
+ fn build(row: Self::Row) -> deserialize::Result<Self> {
+ Ok(match row {
+ Some(true) => SubscribedType::Pending,
+ Some(false) => SubscribedType::Subscribed,
+ None => SubscribedType::NotSubscribed,
+ })
+ }
}
#[async_trait]
source::{
comment::Comment,
comment_report::CommentReport,
- community::{Community, CommunityPersonBan},
+ community::Community,
person::Person,
post::Post,
},
person::all_columns,
aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns,
- community_person_ban::all_columns.nullable(),
+ community_person_ban::id.nullable().is_not_null(),
comment_like::score.nullable(),
aliases::person2.fields(person::all_columns).nullable(),
);
Person,
Person,
CommentAggregates,
- Option<CommunityPersonBan>,
+ bool,
Option<i16>,
Option<Person>,
);
creator: a.4,
comment_creator: a.5,
counts: a.6,
- creator_banned_from_community: a.7.is_some(),
+ creator_banned_from_community: a.7,
my_vote: a.8,
resolver: a.9,
}
post,
},
source::{
- comment::{Comment, CommentSaved},
- community::{Community, CommunityFollower, CommunityPersonBan},
+ comment::Comment,
+ community::{Community, CommunityFollower},
person::Person,
- person_block::PersonBlock,
post::Post,
},
traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType,
ListingType,
+ SubscribedType,
};
type CommentViewTuple = (
Post,
Community,
CommentAggregates,
- Option<CommunityPersonBan>,
- Option<CommunityFollower>,
- Option<CommentSaved>,
- Option<PersonBlock>,
+ bool,
+ SubscribedType,
+ bool,
+ bool,
Option<i16>,
);
post::all_columns,
community::all_columns,
comment_aggregates::all_columns,
- community_person_ban::all_columns.nullable(),
- community_follower::all_columns.nullable(),
- comment_saved::all_columns.nullable(),
- person_block::all_columns.nullable(),
+ community_person_ban::id.nullable().is_not_null(),
+ CommunityFollower::select_subscribed_type(),
+ comment_saved::id.nullable().is_not_null(),
+ person_block::id.nullable().is_not_null(),
comment_like::score.nullable(),
);
if let Some(listing_type) = options.listing_type {
match listing_type {
- ListingType::Subscribed => {
- query = query.filter(community_follower::person_id.is_not_null())
- } // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
+ ListingType::Subscribed => query = query.filter(community_follower::pending.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
ListingType::Local => {
query = query.filter(community::local.eq(true)).filter(
community::hidden
post: a.2,
community: a.3,
counts: a.4,
- creator_banned_from_community: a.5.is_some(),
- subscribed: CommunityFollower::to_subscribed_type(&a.6),
- saved: a.7.is_some(),
- creator_blocked: a.8.is_some(),
+ creator_banned_from_community: a.5,
+ subscribed: a.6,
+ saved: a.7,
+ creator_blocked: a.8,
my_vote: a.9,
}
}
Community,
DbPool,
Person,
- PersonBlock,
Post,
},
structs::LocalUserView,
language::Language,
local_user::{LocalUser, LocalUserInsertForm},
person::PersonInsertForm,
- person_block::PersonBlockForm,
+ person_block::{PersonBlock, PersonBlockForm},
post::PostInsertForm,
},
traits::{Blockable, Crud, Likeable},
post_like,
post_report,
},
- source::{
- community::{Community, CommunityPersonBan},
- person::Person,
- post::Post,
- post_report::PostReport,
- },
+ source::{community::Community, person::Person, post::Post, post_report::PostReport},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
};
Community,
Person,
Person,
- Option<CommunityPersonBan>,
+ bool,
Option<i16>,
PostAggregates,
Option<Person>,
community::all_columns,
person::all_columns,
aliases::person1.fields(person::all_columns),
- community_person_ban::all_columns.nullable(),
+ community_person_ban::id.nullable().is_not_null(),
post_like::score.nullable(),
post_aggregates::all_columns,
aliases::person2.fields(person::all_columns.nullable()),
community: a.2,
creator: a.3,
post_creator: a.4,
- creator_banned_from_community: a.5.is_some(),
+ creator_banned_from_community: a.5,
my_vote: a.6,
counts: a.7,
resolver: a.8,
post_saved,
},
source::{
- community::{Community, CommunityFollower, CommunityPersonBan},
+ community::{Community, CommunityFollower},
person::Person,
- person_block::PersonBlock,
- post::{Post, PostRead, PostSaved},
+ post::Post,
},
traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
ListingType,
SortType,
+ SubscribedType,
};
use tracing::debug;
Post,
Person,
Community,
- Option<CommunityPersonBan>,
+ bool,
PostAggregates,
- Option<CommunityFollower>,
- Option<PostSaved>,
- Option<PostRead>,
- Option<PersonBlock>,
+ SubscribedType,
+ bool,
+ bool,
+ bool,
Option<i16>,
i64,
);
post::all_columns,
person::all_columns,
community::all_columns,
- community_person_ban::all_columns.nullable(),
+ community_person_ban::id.nullable().is_not_null(),
post_aggregates::all_columns,
- community_follower::all_columns.nullable(),
- post_saved::all_columns.nullable(),
- post_read::all_columns.nullable(),
- person_block::all_columns.nullable(),
+ CommunityFollower::select_subscribed_type(),
+ post_saved::id.nullable().is_not_null(),
+ post_read::id.nullable().is_not_null(),
+ person_block::id.nullable().is_not_null(),
post_like::score.nullable(),
coalesce(
post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(),
if let Some(listing_type) = options.listing_type {
match listing_type {
- ListingType::Subscribed => {
- query = query.filter(community_follower::person_id.is_not_null())
- }
+ ListingType::Subscribed => query = query.filter(community_follower::pending.is_not_null()),
ListingType::Local => {
query = query.filter(community::local.eq(true)).filter(
community::hidden
};
if options.saved_only.unwrap_or(false) {
- query = query.filter(post_saved::post_id.is_not_null());
+ query = query.filter(post_saved::id.is_not_null());
}
if options.moderator_view.unwrap_or(false) {
post: a.0,
creator: a.1,
community: a.2,
- creator_banned_from_community: a.3.is_some(),
+ creator_banned_from_community: a.3,
counts: a.4,
- subscribed: CommunityFollower::to_subscribed_type(&a.5),
- saved: a.6.is_some(),
- read: a.7.is_some(),
- creator_blocked: a.8.is_some(),
+ subscribed: a.5,
+ saved: a.6,
+ read: a.7,
+ creator_blocked: a.8,
my_vote: a.9,
unread_comments: a.10,
}
post,
},
source::{
- comment::{Comment, CommentSaved},
+ comment::Comment,
comment_reply::CommentReply,
- community::{Community, CommunityFollower, CommunityPersonBan},
+ community::{Community, CommunityFollower},
person::Person,
- person_block::PersonBlock,
post::Post,
},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType,
+ SubscribedType,
};
type CommentReplyViewTuple = (
Community,
Person,
CommentAggregates,
- Option<CommunityPersonBan>,
- Option<CommunityFollower>,
- Option<CommentSaved>,
- Option<PersonBlock>,
+ bool,
+ SubscribedType,
+ bool,
+ bool,
Option<i16>,
);
community::all_columns,
aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns,
- community_person_ban::all_columns.nullable(),
- community_follower::all_columns.nullable(),
- comment_saved::all_columns.nullable(),
- person_block::all_columns.nullable(),
+ community_person_ban::id.nullable().is_not_null(),
+ CommunityFollower::select_subscribed_type(),
+ comment_saved::id.nullable().is_not_null(),
+ person_block::id.nullable().is_not_null(),
comment_like::score.nullable(),
))
};
community: a.4,
recipient: a.5,
counts: a.6,
- creator_banned_from_community: a.7.is_some(),
- subscribed: CommunityFollower::to_subscribed_type(&a.8),
- saved: a.9.is_some(),
- creator_blocked: a.10.is_some(),
+ creator_banned_from_community: a.7,
+ subscribed: a.8,
+ saved: a.9,
+ creator_blocked: a.10,
my_vote: a.11,
}
}
schema::{community, community_aggregates, community_block, community_follower, local_user},
source::{
community::{Community, CommunityFollower},
- community_block::CommunityBlock,
local_user::LocalUser,
},
traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
ListingType,
SortType,
+ SubscribedType,
};
-type CommunityViewTuple = (
- Community,
- CommunityAggregates,
- Option<CommunityFollower>,
- Option<CommunityBlock>,
-);
+type CommunityViewTuple = (Community, CommunityAggregates, SubscribedType, bool);
fn queries<'a>() -> Queries<
impl ReadFn<'a, CommunityView, (CommunityId, Option<PersonId>, Option<bool>)>,
let selection = (
community::all_columns,
community_aggregates::all_columns,
- community_follower::all_columns.nullable(),
- community_block::all_columns.nullable(),
+ CommunityFollower::select_subscribed_type(),
+ community_block::id.nullable().is_not_null(),
);
let not_removed_or_deleted = community::removed
if let Some(listing_type) = options.listing_type {
query = match listing_type {
- ListingType::Subscribed => query.filter(community_follower::person_id.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
+ ListingType::Subscribed => query.filter(community_follower::pending.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
ListingType::Local => query.filter(community::local.eq(true)),
_ => query,
};
Self {
community: a.0,
counts: a.1,
- subscribed: CommunityFollower::to_subscribed_type(&a.2),
- blocked: a.3.is_some(),
+ subscribed: a.2,
+ blocked: a.3,
}
}
}
post,
},
source::{
- comment::{Comment, CommentSaved},
- community::{Community, CommunityFollower, CommunityPersonBan},
+ comment::Comment,
+ community::{Community, CommunityFollower},
person::Person,
- person_block::PersonBlock,
person_mention::PersonMention,
post::Post,
},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType,
+ SubscribedType,
};
type PersonMentionViewTuple = (
Community,
Person,
CommentAggregates,
- Option<CommunityPersonBan>,
- Option<CommunityFollower>,
- Option<CommentSaved>,
- Option<PersonBlock>,
+ bool,
+ SubscribedType,
+ bool,
+ bool,
Option<i16>,
);
community::all_columns,
aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns,
- community_person_ban::all_columns.nullable(),
- community_follower::all_columns.nullable(),
- comment_saved::all_columns.nullable(),
- person_block::all_columns.nullable(),
+ community_person_ban::id.nullable().is_not_null(),
+ CommunityFollower::select_subscribed_type(),
+ comment_saved::id.nullable().is_not_null(),
+ person_block::id.nullable().is_not_null(),
comment_like::score.nullable(),
);
community: a.4,
recipient: a.5,
counts: a.6,
- creator_banned_from_community: a.7.is_some(),
- subscribed: CommunityFollower::to_subscribed_type(&a.8),
- saved: a.9.is_some(),
- creator_blocked: a.10.is_some(),
+ creator_banned_from_community: a.7,
+ subscribed: a.8,
+ saved: a.9,
+ creator_blocked: a.10,
my_vote: a.11,
}
}