Skip to main content

lemmy_db_views/
structs.rs

1#[cfg(feature = "full")]
2use diesel::Queryable;
3use lemmy_db_schema::{
4  aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates},
5  source::{
6    comment::Comment,
7    comment_report::CommentReport,
8    community::Community,
9    custom_emoji::CustomEmoji,
10    custom_emoji_keyword::CustomEmojiKeyword,
11    images::{ImageDetails, LocalImage},
12    local_site::LocalSite,
13    local_site_rate_limit::LocalSiteRateLimit,
14    local_user::LocalUser,
15    local_user_vote_display_mode::LocalUserVoteDisplayMode,
16    person::Person,
17    post::Post,
18    post_report::PostReport,
19    private_message::PrivateMessage,
20    private_message_report::PrivateMessageReport,
21    registration_application::RegistrationApplication,
22    site::Site,
23  },
24  SubscribedType,
25};
26use serde::{Deserialize, Serialize};
27use serde_with::skip_serializing_none;
28#[cfg(feature = "full")]
29use ts_rs::TS;
30
31#[skip_serializing_none]
32#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
33#[cfg_attr(feature = "full", derive(TS, Queryable))]
34#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
35#[cfg_attr(feature = "full", ts(export))]
36/// A comment report view.
37pub struct CommentReportView {
38  pub comment_report: CommentReport,
39  pub comment: Comment,
40  pub post: Post,
41  pub community: Community,
42  pub creator: Person,
43  pub comment_creator: Person,
44  pub counts: CommentAggregates,
45  pub creator_banned_from_community: bool,
46  pub creator_is_moderator: bool,
47  pub creator_is_admin: bool,
48  pub creator_blocked: bool,
49  pub subscribed: SubscribedType,
50  pub saved: bool,
51  pub my_vote: Option<i16>,
52  pub resolver: Option<Person>,
53}
54
55#[skip_serializing_none]
56#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
57#[cfg_attr(feature = "full", derive(TS, Queryable))]
58#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
59#[cfg_attr(feature = "full", ts(export))]
60/// A comment view.
61pub struct CommentView {
62  pub comment: Comment,
63  pub creator: Person,
64  pub post: Post,
65  pub community: Community,
66  pub counts: CommentAggregates,
67  pub creator_banned_from_community: bool,
68  pub banned_from_community: bool,
69  pub creator_is_moderator: bool,
70  pub creator_is_admin: bool,
71  pub subscribed: SubscribedType,
72  pub saved: bool,
73  pub creator_blocked: bool,
74  pub my_vote: Option<i16>,
75}
76
77#[derive(Debug, Serialize, Deserialize, Clone)]
78#[cfg_attr(feature = "full", derive(TS, Queryable))]
79#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
80#[cfg_attr(feature = "full", ts(export))]
81/// A local user view.
82pub struct LocalUserView {
83  pub local_user: LocalUser,
84  pub local_user_vote_display_mode: LocalUserVoteDisplayMode,
85  pub person: Person,
86  pub counts: PersonAggregates,
87}
88
89#[skip_serializing_none]
90#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
91#[cfg_attr(feature = "full", derive(TS, Queryable))]
92#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
93#[cfg_attr(feature = "full", ts(export))]
94/// A post report view.
95pub struct PostReportView {
96  pub post_report: PostReport,
97  pub post: Post,
98  pub community: Community,
99  pub creator: Person,
100  pub post_creator: Person,
101  pub creator_banned_from_community: bool,
102  pub creator_is_moderator: bool,
103  pub creator_is_admin: bool,
104  pub subscribed: SubscribedType,
105  pub saved: bool,
106  pub read: bool,
107  pub hidden: bool,
108  pub creator_blocked: bool,
109  pub my_vote: Option<i16>,
110  pub unread_comments: i64,
111  pub counts: PostAggregates,
112  pub resolver: Option<Person>,
113}
114
115/// currently this is just a wrapper around post id, but should be seen as opaque from the client's
116/// perspective. stringified since we might want to use arbitrary info later, with a P prepended to
117/// prevent ossification (api users love to make assumptions (e.g. parse stuff that looks like
118/// numbers as numbers) about apis that aren't part of the spec
119#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
120#[cfg_attr(feature = "full", derive(ts_rs::TS))]
121#[cfg_attr(feature = "full", ts(export))]
122pub struct PaginationCursor(pub String);
123
124#[skip_serializing_none]
125#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
126#[cfg_attr(feature = "full", derive(TS, Queryable))]
127#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
128#[cfg_attr(feature = "full", ts(export))]
129/// A post view.
130pub struct PostView {
131  pub post: Post,
132  pub creator: Person,
133  pub community: Community,
134  pub image_details: Option<ImageDetails>,
135  pub creator_banned_from_community: bool,
136  pub banned_from_community: bool,
137  pub creator_is_moderator: bool,
138  pub creator_is_admin: bool,
139  pub counts: PostAggregates,
140  pub subscribed: SubscribedType,
141  pub saved: bool,
142  pub read: bool,
143  pub hidden: bool,
144  pub creator_blocked: bool,
145  pub my_vote: Option<i16>,
146  pub unread_comments: i64,
147}
148
149#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
150#[cfg_attr(feature = "full", derive(TS, Queryable))]
151#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
152#[cfg_attr(feature = "full", ts(export))]
153/// A private message view.
154pub struct PrivateMessageView {
155  pub private_message: PrivateMessage,
156  pub creator: Person,
157  pub recipient: Person,
158}
159
160#[skip_serializing_none]
161#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
162#[cfg_attr(feature = "full", derive(TS, Queryable))]
163#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
164#[cfg_attr(feature = "full", ts(export))]
165/// A private message report view.
166pub struct PrivateMessageReportView {
167  pub private_message_report: PrivateMessageReport,
168  pub private_message: PrivateMessage,
169  pub private_message_creator: Person,
170  pub creator: Person,
171  pub resolver: Option<Person>,
172}
173
174#[skip_serializing_none]
175#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
176#[cfg_attr(feature = "full", derive(TS, Queryable))]
177#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
178#[cfg_attr(feature = "full", ts(export))]
179/// A registration application view.
180pub struct RegistrationApplicationView {
181  pub registration_application: RegistrationApplication,
182  pub creator_local_user: LocalUser,
183  pub creator: Person,
184  pub admin: Option<Person>,
185}
186
187#[derive(Debug, Serialize, Deserialize, Clone)]
188#[cfg_attr(feature = "full", derive(TS, Queryable))]
189#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
190#[cfg_attr(feature = "full", ts(export))]
191/// A site view.
192pub struct SiteView {
193  pub site: Site,
194  pub local_site: LocalSite,
195  pub local_site_rate_limit: LocalSiteRateLimit,
196  pub counts: SiteAggregates,
197}
198
199#[derive(Debug, Serialize, Deserialize, Clone)]
200#[cfg_attr(feature = "full", derive(TS, Queryable))]
201#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
202#[cfg_attr(feature = "full", ts(export))]
203/// A custom emoji view.
204pub struct CustomEmojiView {
205  pub custom_emoji: CustomEmoji,
206  pub keywords: Vec<CustomEmojiKeyword>,
207}
208
209#[skip_serializing_none]
210#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
211#[cfg_attr(feature = "full", derive(TS, Queryable))]
212#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
213#[cfg_attr(feature = "full", ts(export))]
214/// A vote view for checking a post or comments votes.
215pub struct VoteView {
216  pub creator: Person,
217  pub creator_banned_from_community: bool,
218  pub score: i16,
219}
220
221#[skip_serializing_none]
222#[derive(Debug, Serialize, Deserialize, Clone)]
223#[cfg_attr(feature = "full", derive(TS, Queryable))]
224#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
225#[cfg_attr(feature = "full", ts(export))]
226/// A local image view.
227pub struct LocalImageView {
228  pub local_image: LocalImage,
229  pub person: Person,
230}