use crate::federate_retry_sleep_duration; use chrono::{DateTime, Utc}; use lemmy_db_schema::{ newtypes::{ CommentId, CommunityId, InstanceId, LanguageId, PersonId, PostId, RegistrationApplicationId, }, source::{ community::Community, federation_queue_state::FederationQueueState, instance::Instance, language::Language, local_site_url_blocklist::LocalSiteUrlBlocklist, oauth_provider::{OAuthProvider, PublicOAuthProvider}, person::Person, tagline::Tagline, }, CommentSortType, FederationMode, ListingType, ModlogActionType, PostListingMode, PostSortType, RegistrationMode, SearchType, }; use lemmy_db_views::structs::{ CommentView, LocalUserView, PostView, RegistrationApplicationView, SiteView, }; use lemmy_db_views_actor::structs::{ CommunityFollowerView, CommunityModeratorView, CommunityView, PersonView, }; use lemmy_db_views_moderator::structs::{ AdminAllowInstanceView, AdminBlockInstanceView, AdminPurgeCommentView, AdminPurgeCommunityView, AdminPurgePersonView, AdminPurgePostView, ModAddCommunityView, ModAddView, ModBanFromCommunityView, ModBanView, ModFeaturePostView, ModHideCommunityView, ModLockPostView, ModRemoveCommentView, ModRemoveCommunityView, ModRemovePostView, ModTransferCommunityView, }; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Searches the site, given a query string, and some optional filters. pub struct Search { pub q: String, #[cfg_attr(feature = "full", ts(optional))] pub community_id: Option, #[cfg_attr(feature = "full", ts(optional))] pub community_name: Option, #[cfg_attr(feature = "full", ts(optional))] pub creator_id: Option, #[cfg_attr(feature = "full", ts(optional))] pub type_: Option, #[cfg_attr(feature = "full", ts(optional))] pub sort: Option, #[cfg_attr(feature = "full", ts(optional))] pub listing_type: Option, #[cfg_attr(feature = "full", ts(optional))] pub page: Option, #[cfg_attr(feature = "full", ts(optional))] pub limit: Option, #[cfg_attr(feature = "full", ts(optional))] pub title_only: Option, #[cfg_attr(feature = "full", ts(optional))] pub post_url_only: Option, #[cfg_attr(feature = "full", ts(optional))] pub saved_only: Option, #[cfg_attr(feature = "full", ts(optional))] pub liked_only: Option, #[cfg_attr(feature = "full", ts(optional))] pub disliked_only: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The search response, containing lists of the return type possibilities // TODO this should be redone as a list of tagged enums pub struct SearchResponse { pub type_: SearchType, pub comments: Vec, pub posts: Vec, pub communities: Vec, pub users: Vec, } #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Does an apub fetch for an object. pub struct ResolveObject { /// Can be the full url, or a shortened version like: !fediverse@lemmy.ml pub q: String, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] // TODO Change this to an enum /// The response of an apub object fetch. pub struct ResolveObjectResponse { #[cfg_attr(feature = "full", ts(optional))] pub comment: Option, #[cfg_attr(feature = "full", ts(optional))] pub post: Option, #[cfg_attr(feature = "full", ts(optional))] pub community: Option, #[cfg_attr(feature = "full", ts(optional))] pub person: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Fetches the modlog. pub struct GetModlog { #[cfg_attr(feature = "full", ts(optional))] pub mod_person_id: Option, #[cfg_attr(feature = "full", ts(optional))] pub community_id: Option, #[cfg_attr(feature = "full", ts(optional))] pub page: Option, #[cfg_attr(feature = "full", ts(optional))] pub limit: Option, #[cfg_attr(feature = "full", ts(optional))] pub type_: Option, #[cfg_attr(feature = "full", ts(optional))] pub other_person_id: Option, #[cfg_attr(feature = "full", ts(optional))] pub post_id: Option, #[cfg_attr(feature = "full", ts(optional))] pub comment_id: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The modlog fetch response. // TODO this should be redone as a list of tagged enums pub struct GetModlogResponse { pub removed_posts: Vec, pub locked_posts: Vec, pub featured_posts: Vec, pub removed_comments: Vec, pub removed_communities: Vec, pub banned_from_community: Vec, pub banned: Vec, pub added_to_community: Vec, pub transferred_to_community: Vec, pub added: Vec, pub admin_purged_persons: Vec, pub admin_purged_communities: Vec, pub admin_purged_posts: Vec, pub admin_purged_comments: Vec, pub hidden_communities: Vec, pub admin_block_instance: Vec, pub admin_allow_instance: Vec, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Creates a site. Should be done after first running lemmy. pub struct CreateSite { pub name: String, #[cfg_attr(feature = "full", ts(optional))] pub sidebar: Option, #[cfg_attr(feature = "full", ts(optional))] pub description: Option, #[cfg_attr(feature = "full", ts(optional))] pub icon: Option, #[cfg_attr(feature = "full", ts(optional))] pub banner: Option, #[cfg_attr(feature = "full", ts(optional))] pub enable_nsfw: Option, #[cfg_attr(feature = "full", ts(optional))] pub community_creation_admin_only: Option, #[cfg_attr(feature = "full", ts(optional))] pub require_email_verification: Option, #[cfg_attr(feature = "full", ts(optional))] pub application_question: Option, #[cfg_attr(feature = "full", ts(optional))] pub private_instance: Option, #[cfg_attr(feature = "full", ts(optional))] pub default_theme: Option, #[cfg_attr(feature = "full", ts(optional))] pub default_post_listing_type: Option, #[cfg_attr(feature = "full", ts(optional))] pub default_post_listing_mode: Option, #[cfg_attr(feature = "full", ts(optional))] pub default_post_sort_type: Option, #[cfg_attr(feature = "full", ts(optional))] pub default_comment_sort_type: Option, #[cfg_attr(feature = "full", ts(optional))] pub legal_information: Option, #[cfg_attr(feature = "full", ts(optional))] pub application_email_admins: Option, #[cfg_attr(feature = "full", ts(optional))] pub hide_modlog_mod_names: Option, #[cfg_attr(feature = "full", ts(optional))] pub discussion_languages: Option>, #[cfg_attr(feature = "full", ts(optional))] pub slur_filter_regex: Option, #[cfg_attr(feature = "full", ts(optional))] pub actor_name_max_length: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_message: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_message_per_second: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_post: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_post_per_second: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_register: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_register_per_second: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_image: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_image_per_second: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_comment: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_comment_per_second: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_search: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_search_per_second: Option, #[cfg_attr(feature = "full", ts(optional))] pub federation_enabled: Option, #[cfg_attr(feature = "full", ts(optional))] pub federation_debug: Option, #[cfg_attr(feature = "full", ts(optional))] pub captcha_enabled: Option, #[cfg_attr(feature = "full", ts(optional))] pub captcha_difficulty: Option, #[cfg_attr(feature = "full", ts(optional))] pub registration_mode: Option, #[cfg_attr(feature = "full", ts(optional))] pub oauth_registration: Option, #[cfg_attr(feature = "full", ts(optional))] pub content_warning: Option, #[cfg_attr(feature = "full", ts(optional))] pub post_upvotes: Option, #[cfg_attr(feature = "full", ts(optional))] pub post_downvotes: Option, #[cfg_attr(feature = "full", ts(optional))] pub comment_upvotes: Option, #[cfg_attr(feature = "full", ts(optional))] pub comment_downvotes: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Edits a site. pub struct EditSite { #[cfg_attr(feature = "full", ts(optional))] pub name: Option, /// A sidebar for the site, in markdown. #[cfg_attr(feature = "full", ts(optional))] pub sidebar: Option, /// A shorter, one line description of your site. #[cfg_attr(feature = "full", ts(optional))] pub description: Option, /// A url for your site's icon. #[cfg_attr(feature = "full", ts(optional))] pub icon: Option, /// A url for your site's banner. #[cfg_attr(feature = "full", ts(optional))] pub banner: Option, /// Whether to enable NSFW. #[cfg_attr(feature = "full", ts(optional))] pub enable_nsfw: Option, /// Limits community creation to admins only. #[cfg_attr(feature = "full", ts(optional))] pub community_creation_admin_only: Option, /// Whether to require email verification. #[cfg_attr(feature = "full", ts(optional))] pub require_email_verification: Option, /// Your application question form. This is in markdown, and can be many questions. #[cfg_attr(feature = "full", ts(optional))] pub application_question: Option, /// Whether your instance is public, or private. #[cfg_attr(feature = "full", ts(optional))] pub private_instance: Option, /// The default theme. Usually "browser" #[cfg_attr(feature = "full", ts(optional))] pub default_theme: Option, /// The default post listing type, usually "local" #[cfg_attr(feature = "full", ts(optional))] pub default_post_listing_type: Option, /// Default value for listing mode, usually "list" #[cfg_attr(feature = "full", ts(optional))] pub default_post_listing_mode: Option, /// The default post sort, usually "active" #[cfg_attr(feature = "full", ts(optional))] pub default_post_sort_type: Option, /// The default comment sort, usually "hot" #[cfg_attr(feature = "full", ts(optional))] pub default_comment_sort_type: Option, /// An optional page of legal information #[cfg_attr(feature = "full", ts(optional))] pub legal_information: Option, /// Whether to email admins when receiving a new application. #[cfg_attr(feature = "full", ts(optional))] pub application_email_admins: Option, /// Whether to hide moderator names from the modlog. #[cfg_attr(feature = "full", ts(optional))] pub hide_modlog_mod_names: Option, /// A list of allowed discussion languages. #[cfg_attr(feature = "full", ts(optional))] pub discussion_languages: Option>, /// A regex string of items to filter. #[cfg_attr(feature = "full", ts(optional))] pub slur_filter_regex: Option, /// The max length of actor names. #[cfg_attr(feature = "full", ts(optional))] pub actor_name_max_length: Option, /// The number of messages allowed in a given time frame. #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_message: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_message_per_second: Option, /// The number of posts allowed in a given time frame. #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_post: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_post_per_second: Option, /// The number of registrations allowed in a given time frame. #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_register: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_register_per_second: Option, /// The number of image uploads allowed in a given time frame. #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_image: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_image_per_second: Option, /// The number of comments allowed in a given time frame. #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_comment: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_comment_per_second: Option, /// The number of searches allowed in a given time frame. #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_search: Option, #[cfg_attr(feature = "full", ts(optional))] pub rate_limit_search_per_second: Option, /// Whether to enable federation. #[cfg_attr(feature = "full", ts(optional))] pub federation_enabled: Option, /// Enables federation debugging. #[cfg_attr(feature = "full", ts(optional))] pub federation_debug: Option, /// Whether to enable captchas for signups. #[cfg_attr(feature = "full", ts(optional))] pub captcha_enabled: Option, /// The captcha difficulty. Can be easy, medium, or hard #[cfg_attr(feature = "full", ts(optional))] pub captcha_difficulty: Option, /// A list of blocked URLs #[cfg_attr(feature = "full", ts(optional))] pub blocked_urls: Option>, #[cfg_attr(feature = "full", ts(optional))] pub registration_mode: Option, /// Whether to email admins for new reports. #[cfg_attr(feature = "full", ts(optional))] pub reports_email_admins: Option, /// If present, nsfw content is visible by default. Should be displayed by frontends/clients /// when the site is first opened by a user. #[cfg_attr(feature = "full", ts(optional))] pub content_warning: Option, /// Whether or not external auth methods can auto-register users. #[cfg_attr(feature = "full", ts(optional))] pub oauth_registration: Option, /// What kind of post upvotes your site allows. #[cfg_attr(feature = "full", ts(optional))] pub post_upvotes: Option, /// What kind of post downvotes your site allows. #[cfg_attr(feature = "full", ts(optional))] pub post_downvotes: Option, /// What kind of comment upvotes your site allows. #[cfg_attr(feature = "full", ts(optional))] pub comment_upvotes: Option, /// What kind of comment downvotes your site allows. #[cfg_attr(feature = "full", ts(optional))] pub comment_downvotes: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The response for a site. pub struct SiteResponse { pub site_view: SiteView, /// deprecated, use field `tagline` or /api/v4/tagline/list pub taglines: Vec<()>, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// An expanded response for a site. pub struct GetSiteResponse { pub site_view: SiteView, pub admins: Vec, pub version: String, #[cfg_attr(feature = "full", ts(skip))] pub my_user: Option, pub all_languages: Vec, pub discussion_languages: Vec, /// If the site has any taglines, a random one is included here for displaying #[cfg_attr(feature = "full", ts(optional))] pub tagline: Option, /// A list of external auth methods your site supports. #[cfg_attr(feature = "full", ts(optional))] pub oauth_providers: Option>, #[cfg_attr(feature = "full", ts(optional))] pub admin_oauth_providers: Option>, pub blocked_urls: Vec, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// A response of federated instances. pub struct GetFederatedInstancesResponse { /// Optional, because federation may be disabled. #[cfg_attr(feature = "full", ts(optional))] pub federated_instances: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Your user info. pub struct MyUserInfo { pub local_user_view: LocalUserView, pub follows: Vec, pub moderates: Vec, pub community_blocks: Vec, pub instance_blocks: Vec, pub person_blocks: Vec, pub discussion_languages: Vec, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// A list of federated instances. pub struct FederatedInstances { pub linked: Vec, pub allowed: Vec, pub blocked: Vec, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] pub struct ReadableFederationState { #[serde(flatten)] internal_state: FederationQueueState, /// timestamp of the next retry attempt (null if fail count is 0) #[cfg_attr(feature = "full", ts(optional))] next_retry: Option>, } #[allow(clippy::expect_used)] impl From for ReadableFederationState { fn from(internal_state: FederationQueueState) -> Self { ReadableFederationState { next_retry: internal_state.last_retry.map(|r| { r + chrono::Duration::from_std(federate_retry_sleep_duration(internal_state.fail_count)) .expect("sleep duration longer than 2**63 ms (262 million years)") }), internal_state, } } } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] pub struct InstanceWithFederationState { #[serde(flatten)] pub instance: Instance, /// if federation to this instance is or was active, show state of outgoing federation to this /// instance #[cfg_attr(feature = "full", ts(optional))] pub federation_state: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Purges a person from the database. This will delete all content attached to that person. pub struct PurgePerson { pub person_id: PersonId, #[cfg_attr(feature = "full", ts(optional))] pub reason: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Purges a community from the database. This will delete all content attached to that community. pub struct PurgeCommunity { pub community_id: CommunityId, #[cfg_attr(feature = "full", ts(optional))] pub reason: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Purges a post from the database. This will delete all content attached to that post. pub struct PurgePost { pub post_id: PostId, #[cfg_attr(feature = "full", ts(optional))] pub reason: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Purges a comment from the database. This will delete all content attached to that comment. pub struct PurgeComment { pub comment_id: CommentId, #[cfg_attr(feature = "full", ts(optional))] pub reason: Option, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Fetches a list of registration applications. pub struct ListRegistrationApplications { /// Only shows the unread applications (IE those without an admin actor) #[cfg_attr(feature = "full", ts(optional))] pub unread_only: Option, #[cfg_attr(feature = "full", ts(optional))] pub page: Option, #[cfg_attr(feature = "full", ts(optional))] pub limit: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The list of registration applications. pub struct ListRegistrationApplicationsResponse { pub registration_applications: Vec, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Gets a registration application for a person pub struct GetRegistrationApplication { pub person_id: PersonId, } #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Approves a registration application. pub struct ApproveRegistrationApplication { pub id: RegistrationApplicationId, pub approve: bool, #[cfg_attr(feature = "full", ts(optional))] pub deny_reason: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The response of an action done to a registration application. pub struct RegistrationApplicationResponse { pub registration_application: RegistrationApplicationView, } #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// The count of unread registration applications. pub struct GetUnreadRegistrationApplicationCountResponse { pub registration_applications: i64, } #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Block an instance as user pub struct UserBlockInstanceParams { pub instance_id: InstanceId, pub block: bool, } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] pub struct AdminBlockInstanceParams { pub instance: String, pub block: bool, #[cfg_attr(feature = "full", ts(optional))] pub reason: Option, #[cfg_attr(feature = "full", ts(optional))] pub expires: Option>, } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] pub struct AdminAllowInstanceParams { pub instance: String, pub allow: bool, #[cfg_attr(feature = "full", ts(optional))] pub reason: Option, }