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]
|
2023-06-26 09:18:29 +00:00
|
|
|
#[allow(clippy::wildcard_imports)]
|
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 {
|
2023-10-24 12:37:03 +00:00
|
|
|
use crate::schema::{community_moderator, person};
|
2023-11-24 12:44:17 +00:00
|
|
|
diesel::alias!(
|
|
|
|
person as person1: Person1,
|
|
|
|
person as person2: Person2,
|
|
|
|
community_moderator as community_moderator1: CommunityModerator1
|
|
|
|
);
|
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};
|
|
|
|
use strum_macros::{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",
|
|
|
|
ExistingTypePath = "crate::schema::sql_types::SortTypeEnum"
|
|
|
|
)]
|
|
|
|
#[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
|
2022-05-06 20:55:07 +00:00
|
|
|
pub enum SortType {
|
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-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 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 {
|
|
|
|
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,
|
|
|
|
Url,
|
|
|
|
}
|
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,
|
|
|
|
}
|
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.
|
|
|
|
///
|
|
|
|
/// TODO: Also use this to define private communities
|
|
|
|
pub enum CommunityVisibility {
|
|
|
|
/// Public community, any local or federated user can interact.
|
|
|
|
#[default]
|
|
|
|
Public,
|
|
|
|
/// Unfederated community, only local users can interact.
|
|
|
|
LocalOnly,
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}};
|
|
|
|
}
|