use chrono::{DateTime, Utc};
use lemmy_db_schema::source::{
comment::{Comment, CommentActions},
community::{Community, CommunityActions},
community_tag::CommunityTagsView,
person::{Person, PersonActions},
post::Post,
};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use {
diesel::{Queryable, Selectable},
lemmy_db_schema::utils::queries::selects::{
CreatorLocalHomeCommunityBanExpiresType,
comment_creator_is_admin,
comment_select_remove_deletes,
creator_ban_expires_from_community,
creator_banned_from_community,
creator_is_moderator,
creator_local_home_community_ban_expires,
creator_local_home_community_banned,
local_user_can_mod_comment,
post_community_tags_fragment,
},
};
pub mod api;
#[cfg(feature = "full")]
pub mod impls;
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Selectable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(optional_fields, export))]
pub struct CommentView {
#[cfg_attr(feature = "full",
diesel(
select_expression = comment_select_remove_deletes()
)
)]
pub comment: Comment,
#[cfg_attr(feature = "full", diesel(embed))]
pub creator: Person,
#[cfg_attr(feature = "full", diesel(embed))]
pub post: Post,
#[cfg_attr(feature = "full", diesel(embed))]
pub community: Community,
#[cfg_attr(feature = "full", diesel(embed))]
pub community_actions: Option<CommunityActions>,
#[cfg_attr(feature = "full", diesel(embed))]
pub comment_actions: Option<CommentActions>,
#[cfg_attr(feature = "full", diesel(embed))]
pub person_actions: Option<PersonActions>,
#[cfg_attr(feature = "full",
diesel(
select_expression = comment_creator_is_admin()
)
)]
pub creator_is_admin: bool,
#[cfg_attr(feature = "full",
diesel(
select_expression = post_community_tags_fragment()
)
)]
pub tags: CommunityTagsView,
#[cfg_attr(feature = "full",
diesel(
select_expression = local_user_can_mod_comment()
)
)]
pub can_mod: bool,
#[cfg_attr(feature = "full",
diesel(
select_expression = creator_local_home_community_banned()
)
)]
pub creator_banned: bool,
#[cfg_attr(feature = "full",
diesel(
select_expression_type = CreatorLocalHomeCommunityBanExpiresType,
select_expression = creator_local_home_community_ban_expires()
)
)]
pub creator_ban_expires_at: Option<DateTime<Utc>>,
#[cfg_attr(feature = "full",
diesel(
select_expression = creator_is_moderator()
)
)]
pub creator_is_moderator: bool,
#[cfg_attr(feature = "full",
diesel(
select_expression = creator_banned_from_community()
)
)]
pub creator_banned_from_community: bool,
#[cfg_attr(feature = "full",
diesel(
select_expression = creator_ban_expires_from_community()
)
)]
pub creator_community_ban_expires_at: Option<DateTime<Utc>>,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(optional_fields, export))]
pub struct CommentSlimView {
pub comment: Comment,
pub creator: Person,
pub comment_actions: Option<CommentActions>,
pub person_actions: Option<PersonActions>,
pub creator_is_admin: bool,
pub can_mod: bool,
pub creator_banned: bool,
pub creator_is_moderator: bool,
pub creator_banned_from_community: bool,
}