2022-10-27 09:24:07 +00:00
|
|
|
#![recursion_limit = "256"]
|
|
|
|
|
2022-05-03 17:44:13 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
#[macro_use]
|
2020-12-18 16:17:21 +00:00
|
|
|
extern crate diesel;
|
2022-05-03 17:44:13 +00:00
|
|
|
#[cfg(feature = "full")]
|
2021-03-18 20:25:21 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel_derive_newtype;
|
2023-04-17 19:19:51 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "full")]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel_derive_enum;
|
|
|
|
|
2021-10-16 13:33:38 +00:00
|
|
|
// this is used in tests
|
2022-05-03 17:44:13 +00:00
|
|
|
#[cfg(feature = "full")]
|
2021-10-16 13:33:38 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel_migrations;
|
2021-03-18 20:25:21 +00:00
|
|
|
|
2022-11-17 15:23:01 +00:00
|
|
|
#[cfg(feature = "full")]
|
2022-11-09 10:05:00 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate async_trait;
|
|
|
|
|
2021-10-16 13:33:38 +00:00
|
|
|
pub mod aggregates;
|
2022-05-03 17:44:13 +00:00
|
|
|
#[cfg(feature = "full")]
|
2021-10-16 13:33:38 +00:00
|
|
|
pub mod impls;
|
|
|
|
pub mod newtypes;
|
2024-05-17 00:41:57 +00:00
|
|
|
pub mod sensitive;
|
2022-05-03 17:44:13 +00:00
|
|
|
#[cfg(feature = "full")]
|
2023-04-17 19:19:51 +00:00
|
|
|
#[rustfmt::skip]
|
2021-10-16 13:33:38 +00:00
|
|
|
pub mod schema;
|
2023-07-28 08:36:50 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
pub mod aliases {
|
2024-11-11 10:34:10 +00:00
|
|
|
use crate::schema::{community_actions, person};
|
2023-11-24 12:44:17 +00:00
|
|
|
diesel::alias!(
|
2024-11-11 10:34:10 +00:00
|
|
|
community_actions as creator_community_actions: CreatorCommunityActions,
|
2023-11-24 12:44:17 +00:00
|
|
|
person as person1: Person1,
|
|
|
|
person as person2: Person2,
|
|
|
|
);
|
2023-07-28 08:36:50 +00:00
|
|
|
}
|
2021-10-16 13:33:38 +00:00
|
|
|
pub mod source;
|
2022-05-03 17:44:13 +00:00
|
|
|
#[cfg(feature = "full")]
|
2021-10-16 13:33:38 +00:00
|
|
|
pub mod traits;
|
2022-05-03 17:44:13 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
pub mod utils;
|
2022-05-06 20:55:07 +00:00
|
|
|
|
2024-04-18 00:58:44 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
mod schema_setup;
|
|
|
|
|
2022-05-06 20:55:07 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2024-07-23 15:05:19 +00:00
|
|
|
use strum::{Display, EnumString};
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
use ts_rs::TS;
|
2022-05-06 20:55:07 +00:00
|
|
|
|
2023-08-31 11:07:45 +00:00
|
|
|
#[derive(
|
2024-02-11 05:32:14 +00:00
|
|
|
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
|
2023-08-31 11:07:45 +00:00
|
|
|
)]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
|
2023-04-17 19:19:51 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "full",
|
2024-09-19 08:03:58 +00:00
|
|
|
ExistingTypePath = "crate::schema::sql_types::PostSortTypeEnum"
|
2023-04-17 19:19:51 +00:00
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
2023-09-06 17:43:27 +00:00
|
|
|
// TODO add the controversial and scaled rankings to the doc below
|
2023-05-10 19:20:39 +00:00
|
|
|
/// The post sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
|
2024-09-19 08:03:58 +00:00
|
|
|
pub enum PostSortType {
|
2023-08-31 11:07:45 +00:00
|
|
|
#[default]
|
2022-05-06 20:55:07 +00:00
|
|
|
Active,
|
|
|
|
Hot,
|
|
|
|
New,
|
2022-07-30 03:55:59 +00:00
|
|
|
Old,
|
2022-05-06 20:55:07 +00:00
|
|
|
TopDay,
|
|
|
|
TopWeek,
|
|
|
|
TopMonth,
|
|
|
|
TopYear,
|
|
|
|
TopAll,
|
|
|
|
MostComments,
|
|
|
|
NewComments,
|
2023-06-20 14:05:43 +00:00
|
|
|
TopHour,
|
|
|
|
TopSixHour,
|
|
|
|
TopTwelveHour,
|
2023-06-26 19:03:35 +00:00
|
|
|
TopThreeMonths,
|
|
|
|
TopSixMonths,
|
|
|
|
TopNineMonths,
|
2023-07-26 17:07:05 +00:00
|
|
|
Controversial,
|
2023-09-06 17:43:27 +00:00
|
|
|
Scaled,
|
2022-05-06 20:55:07 +00:00
|
|
|
}
|
|
|
|
|
2024-09-19 08:03:58 +00:00
|
|
|
#[derive(
|
|
|
|
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
|
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "full",
|
|
|
|
ExistingTypePath = "crate::schema::sql_types::CommentSortTypeEnum"
|
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
2023-05-10 19:20:39 +00:00
|
|
|
/// The comment sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
|
2022-07-30 03:55:59 +00:00
|
|
|
pub enum CommentSortType {
|
2024-09-19 08:03:58 +00:00
|
|
|
#[default]
|
2022-07-30 03:55:59 +00:00
|
|
|
Hot,
|
|
|
|
Top,
|
|
|
|
New,
|
|
|
|
Old,
|
2023-07-26 17:07:05 +00:00
|
|
|
Controversial,
|
|
|
|
}
|
|
|
|
|
2023-08-31 11:07:45 +00:00
|
|
|
#[derive(
|
2024-02-11 05:32:14 +00:00
|
|
|
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
|
2023-08-31 11:07:45 +00:00
|
|
|
)]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
|
2023-04-17 19:19:51 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "full",
|
|
|
|
ExistingTypePath = "crate::schema::sql_types::ListingTypeEnum"
|
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
2023-05-10 19:20:39 +00:00
|
|
|
/// A listing type for post and comment list fetches.
|
2022-05-06 20:55:07 +00:00
|
|
|
pub enum ListingType {
|
2023-05-10 19:20:39 +00:00
|
|
|
/// Content from your own site, as well as all connected / federated sites.
|
2022-05-06 20:55:07 +00:00
|
|
|
All,
|
2023-05-10 19:20:39 +00:00
|
|
|
/// Content from your site only.
|
2023-08-31 11:07:45 +00:00
|
|
|
#[default]
|
2022-05-06 20:55:07 +00:00
|
|
|
Local,
|
2023-05-10 19:20:39 +00:00
|
|
|
/// Content only from communities you've subscribed to.
|
2022-05-06 20:55:07 +00:00
|
|
|
Subscribed,
|
2023-08-31 11:07:45 +00:00
|
|
|
/// Content that you can moderate (because you are a moderator of the community it is posted to)
|
|
|
|
ModeratorView,
|
2022-05-06 20:55:07 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 21:02:01 +00:00
|
|
|
#[derive(
|
2024-02-11 05:32:14 +00:00
|
|
|
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
|
2023-11-06 21:02:01 +00:00
|
|
|
)]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
|
2023-04-17 19:19:51 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "full",
|
|
|
|
ExistingTypePath = "crate::schema::sql_types::RegistrationModeEnum"
|
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
2023-05-10 19:20:39 +00:00
|
|
|
/// The registration mode for your site. Determines what happens after a user signs up.
|
2023-04-17 19:19:51 +00:00
|
|
|
pub enum RegistrationMode {
|
2023-05-10 19:20:39 +00:00
|
|
|
/// Closed to public.
|
2023-04-17 19:19:51 +00:00
|
|
|
Closed,
|
2023-05-10 19:20:39 +00:00
|
|
|
/// Open, but pending approval of a registration application.
|
2023-04-17 19:19:51 +00:00
|
|
|
RequireApplication,
|
2023-05-10 19:20:39 +00:00
|
|
|
/// Open to all.
|
2023-11-06 21:02:01 +00:00
|
|
|
#[default]
|
2023-04-17 19:19:51 +00:00
|
|
|
Open,
|
|
|
|
}
|
|
|
|
|
2024-02-16 12:24:35 +00:00
|
|
|
#[derive(
|
|
|
|
EnumString, Display, Debug, Serialize, Deserialize, Default, Clone, Copy, PartialEq, Eq, Hash,
|
|
|
|
)]
|
2023-08-31 13:01:08 +00:00
|
|
|
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "full",
|
|
|
|
ExistingTypePath = "crate::schema::sql_types::PostListingModeEnum"
|
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
|
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
|
|
|
/// A post-view mode that changes how multiple post listings look.
|
|
|
|
pub enum PostListingMode {
|
|
|
|
/// A compact, list-type view.
|
2024-02-16 12:24:35 +00:00
|
|
|
#[default]
|
2023-08-31 13:01:08 +00:00
|
|
|
List,
|
|
|
|
/// A larger card-type view.
|
|
|
|
Card,
|
|
|
|
/// A smaller card-type view, usually with images as thumbnails
|
|
|
|
SmallCard,
|
|
|
|
}
|
|
|
|
|
2024-02-11 05:32:14 +00:00
|
|
|
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", derive(TS))]
|
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
2023-05-10 19:20:39 +00:00
|
|
|
/// The type of content returned from a search.
|
2022-05-06 20:55:07 +00:00
|
|
|
pub enum SearchType {
|
|
|
|
All,
|
|
|
|
Comments,
|
|
|
|
Posts,
|
|
|
|
Communities,
|
|
|
|
Users,
|
|
|
|
}
|
2022-06-22 12:05:41 +00:00
|
|
|
|
2024-02-11 05:32:14 +00:00
|
|
|
#[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy, Hash)]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", derive(TS))]
|
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
2023-05-10 19:20:39 +00:00
|
|
|
/// A type / status for a community subscribe.
|
2022-06-22 12:05:41 +00:00
|
|
|
pub enum SubscribedType {
|
|
|
|
Subscribed,
|
|
|
|
NotSubscribed,
|
|
|
|
Pending,
|
2024-11-07 10:49:05 +00:00
|
|
|
ApprovalRequired,
|
2022-06-22 12:05:41 +00:00
|
|
|
}
|
2022-08-16 11:52:04 +00:00
|
|
|
|
2024-02-11 05:32:14 +00:00
|
|
|
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", derive(TS))]
|
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
2023-05-10 19:20:39 +00:00
|
|
|
/// A list of possible types for the various modlog actions.
|
2022-08-16 11:52:04 +00:00
|
|
|
pub enum ModlogActionType {
|
|
|
|
All,
|
|
|
|
ModRemovePost,
|
|
|
|
ModLockPost,
|
2022-12-12 11:17:10 +00:00
|
|
|
ModFeaturePost,
|
2022-08-16 11:52:04 +00:00
|
|
|
ModRemoveComment,
|
|
|
|
ModRemoveCommunity,
|
|
|
|
ModBanFromCommunity,
|
|
|
|
ModAddCommunity,
|
|
|
|
ModTransferCommunity,
|
|
|
|
ModAdd,
|
|
|
|
ModBan,
|
|
|
|
ModHideCommunity,
|
|
|
|
AdminPurgePerson,
|
|
|
|
AdminPurgeCommunity,
|
|
|
|
AdminPurgePost,
|
|
|
|
AdminPurgeComment,
|
|
|
|
}
|
2022-12-12 11:17:10 +00:00
|
|
|
|
|
|
|
#[derive(
|
2024-02-11 05:32:14 +00:00
|
|
|
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash,
|
2022-12-12 11:17:10 +00:00
|
|
|
)]
|
2023-04-26 04:26:10 +00:00
|
|
|
#[cfg_attr(feature = "full", derive(TS))]
|
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
2023-05-10 19:20:39 +00:00
|
|
|
/// The feature type for a post.
|
2022-12-12 11:17:10 +00:00
|
|
|
pub enum PostFeatureType {
|
|
|
|
#[default]
|
2023-05-10 19:20:39 +00:00
|
|
|
/// Features to the top of your site.
|
2022-12-12 11:17:10 +00:00
|
|
|
Local,
|
2023-05-10 19:20:39 +00:00
|
|
|
/// Features to the top of the community.
|
2022-12-12 11:17:10 +00:00
|
|
|
Community,
|
|
|
|
}
|
2024-01-04 16:51:55 +00:00
|
|
|
|
2024-01-25 16:04:25 +00:00
|
|
|
#[derive(
|
2024-02-11 05:32:14 +00:00
|
|
|
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
|
2024-01-25 16:04:25 +00:00
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "full",
|
|
|
|
ExistingTypePath = "crate::schema::sql_types::CommunityVisibility"
|
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
|
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
|
|
|
/// Defines who can browse and interact with content in a community.
|
|
|
|
pub enum CommunityVisibility {
|
|
|
|
/// Public community, any local or federated user can interact.
|
|
|
|
#[default]
|
|
|
|
Public,
|
|
|
|
/// Unfederated community, only local users can interact.
|
|
|
|
LocalOnly,
|
2024-11-07 10:49:05 +00:00
|
|
|
/// Users need to be approved by mods before they are able to browse or post.
|
|
|
|
Private,
|
2024-01-25 16:04:25 +00:00
|
|
|
}
|
|
|
|
|
2024-10-02 10:55:37 +00:00
|
|
|
#[derive(
|
|
|
|
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
|
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "full",
|
|
|
|
ExistingTypePath = "crate::schema::sql_types::FederationModeEnum"
|
|
|
|
)]
|
|
|
|
#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
|
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
|
|
|
/// The federation mode for an item
|
|
|
|
pub enum FederationMode {
|
|
|
|
#[default]
|
|
|
|
/// Allows all
|
|
|
|
All,
|
|
|
|
/// Allows only local
|
|
|
|
Local,
|
|
|
|
/// Disables
|
|
|
|
Disable,
|
|
|
|
}
|
|
|
|
|
2024-01-04 16:51:55 +00:00
|
|
|
/// Wrapper for assert_eq! macro. Checks that vec matches the given length, and prints the
|
|
|
|
/// vec on failure.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! assert_length {
|
|
|
|
($len:expr, $vec:expr) => {{
|
|
|
|
assert_eq!($len, $vec.len(), "Vec has wrong length: {:?}", $vec)
|
|
|
|
}};
|
|
|
|
}
|