person::{GetPersonMentions, GetPersonMentionsResponse},
utils::{blocking, get_local_user_view_from_jwt},
};
-use lemmy_db_schema::utils::{from_opt_str_to_opt_enum, SortType};
use lemmy_db_views_actor::person_mention_view::PersonMentionQueryBuilder;
use lemmy_utils::{ConnectionId, LemmyError};
use lemmy_websocket::LemmyContext;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
- let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
-
+ let sort = data.sort;
let page = data.page;
let limit = data.limit;
let unread_only = data.unread_only;
person::{GetReplies, GetRepliesResponse},
utils::{blocking, get_local_user_view_from_jwt},
};
-use lemmy_db_schema::utils::{from_opt_str_to_opt_enum, SortType};
use lemmy_db_views::comment_view::CommentQueryBuilder;
use lemmy_utils::{ConnectionId, LemmyError};
use lemmy_websocket::LemmyContext;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
- let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
-
+ let sort = data.sort;
let page = data.page;
let limit = data.limit;
let unread_only = data.unread_only;
utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
};
use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
-use lemmy_db_schema::{
- source::community::Community,
- traits::DeleteableOrRemoveable,
- utils::{from_opt_str_to_opt_enum, ListingType, SearchType, SortType},
-};
+use lemmy_db_schema::{source::community::Community, traits::DeleteableOrRemoveable, SearchType};
use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
use lemmy_db_views_actor::{
community_view::CommunityQueryBuilder,
let q = data.q.to_owned();
let page = data.page;
let limit = data.limit;
- let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
- let listing_type: Option<ListingType> = from_opt_str_to_opt_enum(&data.listing_type);
- let search_type: SearchType = from_opt_str_to_opt_enum(&data.type_).unwrap_or(SearchType::All);
+ let sort = data.sort;
+ let listing_type = data.listing_type;
+ let search_type = data.type_.unwrap_or(SearchType::All);
let community_id = data.community_id;
let community_actor_id = if let Some(name) = &data.community_name {
resolve_actor_identifier::<ApubCommunity, Community>(name, context)
use crate::sensitive::Sensitive;
-use lemmy_db_schema::newtypes::{CommentId, CommentReportId, CommunityId, LocalUserId, PostId};
+use lemmy_db_schema::{
+ newtypes::{CommentId, CommentReportId, CommunityId, LocalUserId, PostId},
+ ListingType,
+ SortType,
+};
use lemmy_db_views::structs::{CommentReportView, CommentView};
use serde::{Deserialize, Serialize};
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct CreateComment {
pub content: String,
pub post_id: PostId,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetComment {
pub id: CommentId,
pub auth: Option<Sensitive<String>>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct EditComment {
pub content: String,
pub comment_id: CommentId,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct DeleteComment {
pub comment_id: CommentId,
pub deleted: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct RemoveComment {
pub comment_id: CommentId,
pub removed: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct MarkCommentAsRead {
pub comment_id: CommentId,
pub read: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct SaveComment {
pub comment_id: CommentId,
pub save: bool,
pub form_id: Option<String>, // An optional front end ID, to tell which is coming back
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct CreateCommentLike {
pub comment_id: CommentId,
pub score: i16,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetComments {
- pub type_: Option<String>,
- pub sort: Option<String>,
+ pub type_: Option<ListingType>,
+ pub sort: Option<SortType>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub community_id: Option<CommunityId>,
pub auth: Option<Sensitive<String>>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetCommentsResponse {
pub comments: Vec<CommentView>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct CreateCommentReport {
pub comment_id: CommentId,
pub reason: String,
pub comment_report_view: CommentReportView,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ResolveCommentReport {
pub report_id: CommentReportId,
pub resolved: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ListCommentReports {
pub page: Option<i64>,
pub limit: Option<i64>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ListCommentReportsResponse {
pub comment_reports: Vec<CommentReportView>,
}
use lemmy_db_schema::{
newtypes::{CommunityId, PersonId},
source::site::Site,
+ ListingType,
+ SortType,
};
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonViewSafe};
use serde::{Deserialize, Serialize};
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetCommunity {
pub id: Option<CommunityId>,
/// Example: star_trek , or star_trek@xyz.tld
pub auth: Option<Sensitive<String>>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetCommunityResponse {
pub community_view: CommunityView,
pub site: Option<Site>,
pub online: usize,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct CreateCommunity {
pub name: String,
pub title: String,
pub community_view: CommunityView,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ListCommunities {
- pub type_: Option<String>,
- pub sort: Option<String>,
+ pub type_: Option<ListingType>,
+ pub sort: Option<SortType>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub auth: Option<Sensitive<String>>,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ListCommunitiesResponse {
pub communities: Vec<CommunityView>,
}
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct BanFromCommunity {
pub community_id: CommunityId,
pub person_id: PersonId,
pub banned: bool,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct AddModToCommunity {
pub community_id: CommunityId,
pub person_id: PersonId,
pub moderators: Vec<CommunityModeratorView>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct EditCommunity {
pub community_id: CommunityId,
pub title: Option<String>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct HideCommunity {
pub community_id: CommunityId,
pub hidden: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct DeleteCommunity {
pub community_id: CommunityId,
pub deleted: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct RemoveCommunity {
pub community_id: CommunityId,
pub removed: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct FollowCommunity {
pub community_id: CommunityId,
pub follow: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct BlockCommunity {
pub community_id: CommunityId,
pub block: bool,
pub blocked: bool,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct TransferCommunity {
pub community_id: CommunityId,
pub person_id: PersonId,
pub mod post;
#[cfg(feature = "full")]
pub mod request;
-mod sensitive;
+pub mod sensitive;
pub mod site;
#[cfg(feature = "full")]
pub mod utils;
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonMentionView, PersonViewSafe};
use serde::{Deserialize, Serialize};
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Login {
pub username_or_email: Sensitive<String>,
pub password: Sensitive<String>,
}
-use lemmy_db_schema::newtypes::{CommunityId, PersonId, PersonMentionId, PrivateMessageId};
+use lemmy_db_schema::{
+ newtypes::{CommunityId, PersonId, PersonMentionId, PrivateMessageId},
+ SortType,
+};
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Register {
pub username: String,
pub password: Sensitive<String>,
pub answer: Option<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetCaptcha {}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetCaptchaResponse {
pub ok: Option<CaptchaResponse>, // Will be None if captchas are disabled
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CaptchaResponse {
pub png: String, // A Base64 encoded png
pub wav: String, // A Base64 encoded wav audio
pub uuid: String,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct SaveUserSettings {
pub show_nsfw: Option<bool>,
pub show_scores: Option<bool>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ChangePassword {
pub new_password: Sensitive<String>,
pub new_password_verify: Sensitive<String>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct LoginResponse {
/// This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
pub jwt: Option<Sensitive<String>>,
pub verify_email_sent: bool,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetPersonDetails {
pub person_id: Option<PersonId>, // One of these two are required
/// Example: dessalines , or dessalines@xyz.tld
pub username: Option<String>,
- pub sort: Option<String>,
+ pub sort: Option<SortType>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub community_id: Option<CommunityId>,
pub auth: Option<Sensitive<String>>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetPersonDetailsResponse {
pub person_view: PersonViewSafe,
pub comments: Vec<CommentView>,
pub moderates: Vec<CommunityModeratorView>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetRepliesResponse {
pub replies: Vec<CommentView>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetPersonMentionsResponse {
pub mentions: Vec<PersonMentionView>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct MarkAllAsRead {
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct AddAdmin {
pub person_id: PersonId,
pub added: bool,
pub admins: Vec<PersonViewSafe>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct BanPerson {
pub person_id: PersonId,
pub ban: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetBannedPersons {
pub auth: String,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BannedPersonsResponse {
pub banned: Vec<PersonViewSafe>,
}
pub banned: bool,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct BlockPerson {
pub person_id: PersonId,
pub block: bool,
pub blocked: bool,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetReplies {
- pub sort: Option<String>,
+ pub sort: Option<SortType>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub unread_only: Option<bool>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetPersonMentions {
- pub sort: Option<String>,
+ pub sort: Option<SortType>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub unread_only: Option<bool>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct MarkPersonMentionAsRead {
pub person_mention_id: PersonMentionId,
pub read: bool,
pub person_mention_view: PersonMentionView,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct DeleteAccount {
pub password: Sensitive<String>,
pub auth: Sensitive<String>,
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DeleteAccountResponse {}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct PasswordReset {
pub email: Sensitive<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PasswordResetResponse {}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct PasswordChangeAfterReset {
pub token: Sensitive<String>,
pub password: Sensitive<String>,
pub password_verify: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct CreatePrivateMessage {
pub content: String,
pub recipient_id: PersonId,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct EditPrivateMessage {
pub private_message_id: PrivateMessageId,
pub content: String,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct DeletePrivateMessage {
pub private_message_id: PrivateMessageId,
pub deleted: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct MarkPrivateMessageAsRead {
pub private_message_id: PrivateMessageId,
pub read: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetPrivateMessages {
pub unread_only: Option<bool>,
pub page: Option<i64>,
pub private_message_view: PrivateMessageView,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetReportCount {
pub community_id: Option<CommunityId>,
pub auth: Sensitive<String>,
pub post_reports: i64,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetUnreadCount {
pub auth: Sensitive<String>,
}
pub private_messages: i64,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Clone, Default)]
pub struct VerifyEmail {
pub token: String,
}
use crate::sensitive::Sensitive;
-use lemmy_db_schema::newtypes::{CommunityId, PostId, PostReportId};
+use lemmy_db_schema::{
+ newtypes::{CommunityId, PostId, PostReportId},
+ ListingType,
+ SortType,
+};
use lemmy_db_views::structs::{CommentView, PostReportView, PostView};
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
use serde::{Deserialize, Serialize};
use url::Url;
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct CreatePost {
pub name: String,
pub community_id: CommunityId,
pub post_view: PostView,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetPost {
pub id: PostId,
pub auth: Option<Sensitive<String>>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetPostResponse {
pub post_view: PostView,
pub community_view: CommunityView,
pub online: usize,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct GetPosts {
- pub type_: Option<String>,
- pub sort: Option<String>,
+ pub type_: Option<ListingType>,
+ pub sort: Option<SortType>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub community_id: Option<CommunityId>,
pub auth: Option<Sensitive<String>>,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetPostsResponse {
pub posts: Vec<PostView>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct CreatePostLike {
pub post_id: PostId,
pub score: i16,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct EditPost {
pub post_id: PostId,
pub name: Option<String>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct DeletePost {
pub post_id: PostId,
pub deleted: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct RemovePost {
pub post_id: PostId,
pub removed: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct MarkPostAsRead {
pub post_id: PostId,
pub read: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct LockPost {
pub post_id: PostId,
pub locked: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct StickyPost {
pub post_id: PostId,
pub stickied: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct SavePost {
pub post_id: PostId,
pub save: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct CreatePostReport {
pub post_id: PostId,
pub reason: String,
pub post_report_view: PostReportView,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ResolvePostReport {
pub report_id: PostReportId,
pub resolved: bool,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ListPostReports {
pub page: Option<i64>,
pub limit: Option<i64>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ListPostReportsResponse {
pub post_reports: Vec<PostReportView>,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetSiteMetadata {
pub url: Url,
}
-#[derive(Serialize, Deserialize, Clone, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetSiteMetadataResponse {
pub metadata: SiteMetadata,
}
-#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
+#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
pub struct SiteMetadata {
pub title: Option<String>,
pub description: Option<String>,
ops::{Deref, DerefMut},
};
-#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
+#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize, Default)]
#[serde(transparent)]
pub struct Sensitive<T>(T);
use crate::sensitive::Sensitive;
-use lemmy_db_schema::newtypes::{CommunityId, PersonId};
+use lemmy_db_schema::{
+ newtypes::{CommunityId, PersonId},
+ ListingType,
+ SearchType,
+ SortType,
+};
use lemmy_db_views::structs::{
CommentView,
LocalUserSettingsView,
};
use serde::{Deserialize, Serialize};
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Search {
pub q: String,
pub community_id: Option<CommunityId>,
pub community_name: Option<String>,
pub creator_id: Option<PersonId>,
- pub type_: Option<String>,
- pub sort: Option<String>,
- pub listing_type: Option<String>,
+ pub type_: Option<SearchType>,
+ pub sort: Option<SortType>,
+ pub listing_type: Option<ListingType>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub auth: Option<Sensitive<String>>,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SearchResponse {
pub type_: String,
pub comments: Vec<CommentView>,
pub users: Vec<PersonViewSafe>,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ResolveObject {
pub q: String,
pub auth: Option<Sensitive<String>>,
pub person: Option<PersonViewSafe>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetModlog {
pub mod_person_id: Option<PersonId>,
pub community_id: Option<CommunityId>,
pub auth: Option<Sensitive<String>>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetModlogResponse {
pub removed_posts: Vec<ModRemovePostView>,
pub locked_posts: Vec<ModLockPostView>,
pub hidden_communities: Vec<ModHideCommunityView>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct CreateSite {
pub name: String,
pub sidebar: Option<String>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct EditSite {
pub name: Option<String>,
pub sidebar: Option<String>,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct GetSite {
pub auth: Option<Sensitive<String>>,
}
pub site_view: SiteView,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetSiteResponse {
pub site_view: Option<SiteView>, // Because the site might not be set up yet
pub admins: Vec<PersonViewSafe>,
pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct MyUserInfo {
pub local_user_view: LocalUserSettingsView,
pub follows: Vec<CommunityFollowerView>,
pub person_blocks: Vec<PersonBlockView>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct LeaveAdmin {
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetSiteConfig {
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetSiteConfigResponse {
pub config_hjson: String,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SaveSiteConfig {
pub config_hjson: String,
pub auth: Sensitive<String>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct FederatedInstances {
pub linked: Vec<String>,
pub allowed: Option<Vec<String>>,
pub blocked: Option<Vec<String>>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ListRegistrationApplications {
/// Only shows the unread applications (IE those without an admin actor)
pub unread_only: Option<bool>,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ListRegistrationApplicationsResponse {
pub registration_applications: Vec<RegistrationApplicationView>,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ApproveRegistrationApplication {
pub id: i32,
pub approve: bool,
pub auth: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RegistrationApplicationResponse {
pub registration_application: RegistrationApplicationView,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetUnreadRegistrationApplicationCount {
pub auth: String,
}
-#[derive(Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetUnreadRegistrationApplicationCountResponse {
pub registration_applications: i64,
}
use lemmy_db_schema::newtypes::{CommunityId, PostId};
use serde::{Deserialize, Serialize};
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct UserJoin {
pub auth: Sensitive<String>,
}
pub joined: bool,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CommunityJoin {
pub community_id: CommunityId,
}
pub joined: bool,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ModJoin {
pub community_id: CommunityId,
}
pub joined: bool,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PostJoin {
pub post_id: PostId,
}
utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
};
use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
-use lemmy_db_schema::{
- source::community::Community,
- traits::DeleteableOrRemoveable,
- utils::{from_opt_str_to_opt_enum, ListingType, SortType},
-};
+use lemmy_db_schema::{source::community::Community, traits::DeleteableOrRemoveable};
use lemmy_db_views::comment_view::CommentQueryBuilder;
use lemmy_utils::{ConnectionId, LemmyError};
use lemmy_websocket::LemmyContext;
.map(|t| t.local_user.show_bot_accounts);
let person_id = local_user_view.map(|u| u.person.id);
- let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
- let listing_type: Option<ListingType> = from_opt_str_to_opt_enum(&data.type_);
-
let community_id = data.community_id;
let community_actor_id = if let Some(name) = &data.community_name {
resolve_actor_identifier::<ApubCommunity, Community>(name, context)
} else {
None
};
+ let sort = data.sort;
+ let listing_type = data.type_;
let saved_only = data.saved_only;
let page = data.page;
let limit = data.limit;
community::{ListCommunities, ListCommunitiesResponse},
utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
};
-use lemmy_db_schema::{
- traits::DeleteableOrRemoveable,
- utils::{from_opt_str_to_opt_enum, ListingType, SortType},
-};
+use lemmy_db_schema::traits::DeleteableOrRemoveable;
use lemmy_db_views_actor::community_view::CommunityQueryBuilder;
use lemmy_utils::{ConnectionId, LemmyError};
use lemmy_websocket::LemmyContext;
None => false,
};
- let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
- let listing_type: Option<ListingType> = from_opt_str_to_opt_enum(&data.type_);
-
+ let sort = data.sort;
+ let listing_type = data.type_;
let page = data.page;
let limit = data.limit;
let mut communities = blocking(context.pool(), move |conn| {
use lemmy_db_schema::{
source::{community::Community, site::Site},
traits::DeleteableOrRemoveable,
- utils::{from_opt_str_to_opt_enum, ListingType, SortType},
+ ListingType,
};
use lemmy_db_views::post_view::PostQueryBuilder;
use lemmy_utils::{ConnectionId, LemmyError};
.as_ref()
.map(|t| t.local_user.show_read_posts);
- let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
- let listing_type: ListingType = match from_opt_str_to_opt_enum(&data.type_) {
+ let sort = data.sort;
+ let listing_type: ListingType = match data.type_ {
Some(l) => l,
None => {
let site = blocking(context.pool(), Site::read_local_site).await??;
ListingType::from_str(&site.default_post_listing_type)?
}
};
-
let page = data.page;
let limit = data.limit;
let community_id = data.community_id;
site::{Site, SiteForm},
},
traits::Crud,
- utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now, ListingType},
+ utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now},
+ ListingType,
};
use lemmy_db_views::structs::SiteView;
use lemmy_utils::{utils::check_slurs_opt, ConnectionId, LemmyError};
utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
};
use lemmy_apub::{fetcher::resolve_actor_identifier, objects::person::ApubPerson};
-use lemmy_db_schema::{
- source::person::Person,
- utils::{from_opt_str_to_opt_enum, SortType},
-};
+use lemmy_db_schema::source::person::Person;
use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonViewSafe};
use lemmy_utils::{ConnectionId, LemmyError};
.as_ref()
.map(|t| t.local_user.show_read_posts);
- let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
-
let person_details_id = match data.person_id {
Some(id) => id,
None => {
})
.await??;
+ let sort = data.sort;
let page = data.page;
let limit = data.limit;
let saved_only = data.saved_only;
[features]
full = ["diesel", "diesel-derive-newtype", "diesel_migrations", "bcrypt", "lemmy_utils",
- "lemmy_apub_lib", "strum", "strum_macros", "sha2", "regex", "once_cell", "serde_json"]
+ "lemmy_apub_lib", "sha2", "regex", "once_cell", "serde_json"]
[dependencies]
chrono = { version = "0.4.19", features = ["serde"], default-features = false }
serde = { version = "1.0.136", features = ["derive"] }
url = { version = "2.2.2", features = ["serde"] }
+strum = "0.24.0"
+strum_macros = "0.24.0"
serde_json = { version = "1.0.79", features = ["preserve_order"], optional = true }
lemmy_apub_lib = { version = "=0.16.3", path = "../apub_lib", optional = true }
lemmy_utils = { version = "=0.16.3", path = "../utils", optional = true }
diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"], optional = true }
diesel-derive-newtype = { version = "0.1.2", optional = true }
diesel_migrations = { version = "1.4.0", optional = true }
-strum = { version = "0.24.0", optional = true }
-strum_macros = { version = "0.24.0", optional = true }
sha2 = { version = "0.10.2", optional = true }
regex = { version = "1.5.5", optional = true }
once_cell = { version = "1.10.0", optional = true }
#[cfg(feature = "full")]
#[macro_use]
-extern crate strum_macros;
-#[cfg(feature = "full")]
-#[macro_use]
extern crate diesel;
#[cfg(feature = "full")]
#[macro_use]
pub mod traits;
#[cfg(feature = "full")]
pub mod utils;
+
+use serde::{Deserialize, Serialize};
+use strum_macros::{Display, EnumString};
+
+#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
+pub enum SortType {
+ Active,
+ Hot,
+ New,
+ TopDay,
+ TopWeek,
+ TopMonth,
+ TopYear,
+ TopAll,
+ MostComments,
+ NewComments,
+}
+
+#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
+pub enum ListingType {
+ All,
+ Local,
+ Subscribed,
+ Community,
+}
+
+#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
+pub enum SearchType {
+ All,
+ Comments,
+ Posts,
+ Communities,
+ Users,
+ Url,
+}
#[cfg_attr(feature = "full", derive(DieselNewType))]
pub struct PersonId(pub i32);
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "full", derive(DieselNewType))]
pub struct CommentId(pub i32);
#[cfg_attr(feature = "full", derive(DieselNewType))]
pub struct LocalUserId(pub i32);
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "full", derive(DieselNewType))]
pub struct PrivateMessageId(i32);
}
}
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "full", derive(DieselNewType))]
pub struct PersonMentionId(i32);
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "full", derive(DieselNewType))]
pub struct PersonBlockId(i32);
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "full", derive(DieselNewType))]
pub struct CommunityBlockId(i32);
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "full", derive(DieselNewType))]
pub struct CommentReportId(i32);
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "full", derive(DieselNewType))]
pub struct PostReportId(i32);
use lemmy_utils::LemmyError;
use once_cell::sync::Lazy;
use regex::Regex;
-use serde::{Deserialize, Serialize};
use std::{env, env::VarError, io::Write};
use url::Url;
env::var("LEMMY_DATABASE_URL")
}
-#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
-pub enum SortType {
- Active,
- Hot,
- New,
- TopDay,
- TopWeek,
- TopMonth,
- TopYear,
- TopAll,
- MostComments,
- NewComments,
-}
-
-#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
-pub enum ListingType {
- All,
- Local,
- Subscribed,
- Community,
-}
-
-#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
-pub enum SearchType {
- All,
- Comments,
- Posts,
- Communities,
- Users,
- Url,
-}
-
-pub fn from_opt_str_to_opt_enum<T: std::str::FromStr>(opt: &Option<String>) -> Option<T> {
- opt.as_ref().and_then(|t| T::from_str(t).ok())
-}
-
pub fn fuzzy_search(q: &str) -> String {
let replaced = q.replace('%', "\\%").replace('_', "\\_").replace(' ', "%");
format!("%{}%", replaced)
post::Post,
},
traits::{MaybeOptional, ToSafe, ViewToVec},
- utils::{functions::hot_rank, fuzzy_search, limit_and_offset, ListingType, SortType},
+ utils::{functions::hot_rank, fuzzy_search, limit_and_offset},
+ ListingType,
+ SortType,
};
type CommentViewTuple = (
post::{Post, PostRead, PostSaved},
},
traits::{MaybeOptional, ToSafe, ViewToVec},
- utils::{functions::hot_rank, fuzzy_search, limit_and_offset, ListingType, SortType},
+ utils::{functions::hot_rank, fuzzy_search, limit_and_offset},
+ ListingType,
+ SortType,
};
use tracing::debug;
post::*,
},
traits::{Blockable, Crud, Likeable},
- utils::{establish_unpooled_connection, ListingType, SortType},
+ utils::establish_unpooled_connection,
+ ListingType,
+ SortType,
};
use serial_test::serial;
community_block::CommunityBlock,
},
traits::{MaybeOptional, ToSafe, ViewToVec},
- utils::{functions::hot_rank, fuzzy_search, limit_and_offset, ListingType, SortType},
+ utils::{functions::hot_rank, fuzzy_search, limit_and_offset},
+ ListingType,
+ SortType,
};
type CommunityViewTuple = (
post::Post,
},
traits::{MaybeOptional, ToSafe, ViewToVec},
- utils::{functions::hot_rank, limit_and_offset, SortType},
+ utils::{functions::hot_rank, limit_and_offset},
+ SortType,
};
type PersonMentionViewTuple = (
schema::{person, person_aggregates},
source::person::{Person, PersonSafe},
traits::{MaybeOptional, ToSafe, ViewToVec},
- utils::{fuzzy_search, limit_and_offset, SortType},
+ utils::{fuzzy_search, limit_and_offset},
+ SortType,
};
type PersonViewSafeTuple = (PersonSafe, PersonAggregates);
newtypes::LocalUserId,
source::{community::Community, local_user::LocalUser, person::Person},
traits::{ApubActor, Crud},
- utils::{ListingType, SortType},
+ ListingType,
+ SortType,
};
use lemmy_db_views::{
comment_view::CommentQueryBuilder,