mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 19:01:03 +00:00
Adding a default_comment_sort_type column for local_site and local_user. (#4469)
* Adding a default_comment_sort_type column for local_site and local_user. - Renamed SortType to PostSortType in the DB and code. - Renamed references to default_sort_type to default_post_sort_type. - Fixes #4128 * Renaming migration to current date. * Simplifying PostSortType.
This commit is contained in:
parent
2b3fd70afd
commit
6b6457cc54
25 changed files with 286 additions and 150 deletions
|
@ -102,7 +102,8 @@ pub async fn save_user_settings(
|
||||||
let local_user_id = local_user_view.local_user.id;
|
let local_user_id = local_user_view.local_user.id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let default_listing_type = data.default_listing_type;
|
let default_listing_type = data.default_listing_type;
|
||||||
let default_sort_type = data.default_sort_type;
|
let default_post_sort_type = data.default_post_sort_type;
|
||||||
|
let default_comment_sort_type = data.default_comment_sort_type;
|
||||||
|
|
||||||
let person_form = PersonUpdateForm {
|
let person_form = PersonUpdateForm {
|
||||||
display_name,
|
display_name,
|
||||||
|
@ -133,7 +134,8 @@ pub async fn save_user_settings(
|
||||||
blur_nsfw: data.blur_nsfw,
|
blur_nsfw: data.blur_nsfw,
|
||||||
auto_expand: data.auto_expand,
|
auto_expand: data.auto_expand,
|
||||||
show_bot_accounts: data.show_bot_accounts,
|
show_bot_accounts: data.show_bot_accounts,
|
||||||
default_sort_type,
|
default_post_sort_type,
|
||||||
|
default_comment_sort_type,
|
||||||
default_listing_type,
|
default_listing_type,
|
||||||
theme: data.theme.clone(),
|
theme: data.theme.clone(),
|
||||||
interface_language: data.interface_language.clone(),
|
interface_language: data.interface_language.clone(),
|
||||||
|
|
|
@ -3,7 +3,7 @@ use lemmy_db_schema::{
|
||||||
source::site::Site,
|
source::site::Site,
|
||||||
CommunityVisibility,
|
CommunityVisibility,
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -74,7 +74,7 @@ pub struct CommunityResponse {
|
||||||
/// Fetches a list of communities.
|
/// Fetches a list of communities.
|
||||||
pub struct ListCommunities {
|
pub struct ListCommunities {
|
||||||
pub type_: Option<ListingType>,
|
pub type_: Option<ListingType>,
|
||||||
pub sort: Option<SortType>,
|
pub sort: Option<PostSortType>,
|
||||||
pub show_nsfw: Option<bool>,
|
pub show_nsfw: Option<bool>,
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_db_schema::{
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
PostListingMode,
|
PostListingMode,
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentView, LocalImageView, PostView};
|
use lemmy_db_views::structs::{CommentView, LocalImageView, PostView};
|
||||||
use lemmy_db_views_actor::structs::{
|
use lemmy_db_views_actor::structs::{
|
||||||
|
@ -88,8 +88,14 @@ pub struct SaveUserSettings {
|
||||||
pub auto_expand: Option<bool>,
|
pub auto_expand: Option<bool>,
|
||||||
/// Your user's theme.
|
/// Your user's theme.
|
||||||
pub theme: Option<String>,
|
pub theme: Option<String>,
|
||||||
pub default_sort_type: Option<SortType>,
|
/// The default post listing type, usually "local"
|
||||||
pub default_listing_type: Option<ListingType>,
|
pub default_listing_type: Option<ListingType>,
|
||||||
|
/// A post-view mode that changes how multiple post listings look.
|
||||||
|
pub post_listing_mode: Option<PostListingMode>,
|
||||||
|
/// The default post sort, usually "active"
|
||||||
|
pub default_post_sort_type: Option<PostSortType>,
|
||||||
|
/// The default comment sort, usually "hot"
|
||||||
|
pub default_comment_sort_type: Option<CommentSortType>,
|
||||||
/// The language of the lemmy interface
|
/// The language of the lemmy interface
|
||||||
pub interface_language: Option<String>,
|
pub interface_language: Option<String>,
|
||||||
/// A URL for your avatar.
|
/// A URL for your avatar.
|
||||||
|
@ -120,8 +126,6 @@ pub struct SaveUserSettings {
|
||||||
pub open_links_in_new_tab: Option<bool>,
|
pub open_links_in_new_tab: Option<bool>,
|
||||||
/// Enable infinite scroll
|
/// Enable infinite scroll
|
||||||
pub infinite_scroll_enabled: Option<bool>,
|
pub infinite_scroll_enabled: Option<bool>,
|
||||||
/// A post-view mode that changes how multiple post listings look.
|
|
||||||
pub post_listing_mode: Option<PostListingMode>,
|
|
||||||
/// Whether to allow keyboard navigation (for browsing and interacting with posts and comments).
|
/// Whether to allow keyboard navigation (for browsing and interacting with posts and comments).
|
||||||
pub enable_keyboard_navigation: Option<bool>,
|
pub enable_keyboard_navigation: Option<bool>,
|
||||||
/// Whether user avatars or inline images in the UI that are gifs should be allowed to play or
|
/// Whether user avatars or inline images in the UI that are gifs should be allowed to play or
|
||||||
|
@ -172,7 +176,7 @@ pub struct GetPersonDetails {
|
||||||
pub person_id: Option<PersonId>,
|
pub person_id: Option<PersonId>,
|
||||||
/// Example: dessalines , or dessalines@xyz.tld
|
/// Example: dessalines , or dessalines@xyz.tld
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
pub sort: Option<SortType>,
|
pub sort: Option<PostSortType>,
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
pub community_id: Option<CommunityId>,
|
pub community_id: Option<CommunityId>,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId},
|
newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId},
|
||||||
ListingType,
|
ListingType,
|
||||||
PostFeatureType,
|
PostFeatureType,
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{PaginationCursor, PostReportView, PostView, VoteView};
|
use lemmy_db_views::structs::{PaginationCursor, PostReportView, PostView, VoteView};
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
||||||
|
@ -69,7 +69,7 @@ pub struct GetPostResponse {
|
||||||
/// Get a list of posts.
|
/// Get a list of posts.
|
||||||
pub struct GetPosts {
|
pub struct GetPosts {
|
||||||
pub type_: Option<ListingType>,
|
pub type_: Option<ListingType>,
|
||||||
pub sort: Option<SortType>,
|
pub sort: Option<PostSortType>,
|
||||||
/// DEPRECATED, use page_cursor
|
/// DEPRECATED, use page_cursor
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
|
|
|
@ -20,12 +20,13 @@ use lemmy_db_schema::{
|
||||||
person::Person,
|
person::Person,
|
||||||
tagline::Tagline,
|
tagline::Tagline,
|
||||||
},
|
},
|
||||||
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
ModlogActionType,
|
ModlogActionType,
|
||||||
PostListingMode,
|
PostListingMode,
|
||||||
|
PostSortType,
|
||||||
RegistrationMode,
|
RegistrationMode,
|
||||||
SearchType,
|
SearchType,
|
||||||
SortType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{
|
use lemmy_db_views::structs::{
|
||||||
CommentView,
|
CommentView,
|
||||||
|
@ -74,7 +75,7 @@ pub struct Search {
|
||||||
pub community_name: Option<String>,
|
pub community_name: Option<String>,
|
||||||
pub creator_id: Option<PersonId>,
|
pub creator_id: Option<PersonId>,
|
||||||
pub type_: Option<SearchType>,
|
pub type_: Option<SearchType>,
|
||||||
pub sort: Option<SortType>,
|
pub sort: Option<PostSortType>,
|
||||||
pub listing_type: Option<ListingType>,
|
pub listing_type: Option<ListingType>,
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
|
@ -174,7 +175,9 @@ pub struct CreateSite {
|
||||||
pub private_instance: Option<bool>,
|
pub private_instance: Option<bool>,
|
||||||
pub default_theme: Option<String>,
|
pub default_theme: Option<String>,
|
||||||
pub default_post_listing_type: Option<ListingType>,
|
pub default_post_listing_type: Option<ListingType>,
|
||||||
pub default_sort_type: Option<SortType>,
|
pub default_post_listing_mode: Option<PostListingMode>,
|
||||||
|
pub default_post_sort_type: Option<PostSortType>,
|
||||||
|
pub default_comment_sort_type: Option<CommentSortType>,
|
||||||
pub legal_information: Option<String>,
|
pub legal_information: Option<String>,
|
||||||
pub application_email_admins: Option<bool>,
|
pub application_email_admins: Option<bool>,
|
||||||
pub hide_modlog_mod_names: Option<bool>,
|
pub hide_modlog_mod_names: Option<bool>,
|
||||||
|
@ -203,7 +206,6 @@ pub struct CreateSite {
|
||||||
pub registration_mode: Option<RegistrationMode>,
|
pub registration_mode: Option<RegistrationMode>,
|
||||||
pub oauth_registration: Option<bool>,
|
pub oauth_registration: Option<bool>,
|
||||||
pub content_warning: Option<String>,
|
pub content_warning: Option<String>,
|
||||||
pub default_post_listing_mode: Option<PostListingMode>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
|
@ -234,9 +236,14 @@ pub struct EditSite {
|
||||||
pub private_instance: Option<bool>,
|
pub private_instance: Option<bool>,
|
||||||
/// The default theme. Usually "browser"
|
/// The default theme. Usually "browser"
|
||||||
pub default_theme: Option<String>,
|
pub default_theme: Option<String>,
|
||||||
|
/// The default post listing type, usually "local"
|
||||||
pub default_post_listing_type: Option<ListingType>,
|
pub default_post_listing_type: Option<ListingType>,
|
||||||
/// The default sort, usually "active"
|
/// Default value for listing mode, usually "list"
|
||||||
pub default_sort_type: Option<SortType>,
|
pub default_post_listing_mode: Option<PostListingMode>,
|
||||||
|
/// The default post sort, usually "active"
|
||||||
|
pub default_post_sort_type: Option<PostSortType>,
|
||||||
|
/// The default comment sort, usually "hot"
|
||||||
|
pub default_comment_sort_type: Option<CommentSortType>,
|
||||||
/// An optional page of legal information
|
/// An optional page of legal information
|
||||||
pub legal_information: Option<String>,
|
pub legal_information: Option<String>,
|
||||||
/// Whether to email admins when receiving a new application.
|
/// Whether to email admins when receiving a new application.
|
||||||
|
@ -291,8 +298,6 @@ pub struct EditSite {
|
||||||
/// If present, nsfw content is visible by default. Should be displayed by frontends/clients
|
/// If present, nsfw content is visible by default. Should be displayed by frontends/clients
|
||||||
/// when the site is first opened by a user.
|
/// when the site is first opened by a user.
|
||||||
pub content_warning: Option<String>,
|
pub content_warning: Option<String>,
|
||||||
/// Default value for [LocalUser.post_listing_mode]
|
|
||||||
pub default_post_listing_mode: Option<PostListingMode>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
|
|
@ -98,7 +98,8 @@ pub async fn create_site(
|
||||||
private_instance: data.private_instance,
|
private_instance: data.private_instance,
|
||||||
default_theme: data.default_theme.clone(),
|
default_theme: data.default_theme.clone(),
|
||||||
default_post_listing_type: data.default_post_listing_type,
|
default_post_listing_type: data.default_post_listing_type,
|
||||||
default_sort_type: data.default_sort_type,
|
default_post_sort_type: data.default_post_sort_type,
|
||||||
|
default_comment_sort_type: data.default_comment_sort_type,
|
||||||
legal_information: diesel_string_update(data.legal_information.as_deref()),
|
legal_information: diesel_string_update(data.legal_information.as_deref()),
|
||||||
application_email_admins: data.application_email_admins,
|
application_email_admins: data.application_email_admins,
|
||||||
hide_modlog_mod_names: data.hide_modlog_mod_names,
|
hide_modlog_mod_names: data.hide_modlog_mod_names,
|
||||||
|
@ -200,7 +201,13 @@ mod tests {
|
||||||
|
|
||||||
use crate::site::create::validate_create_payload;
|
use crate::site::create::validate_create_payload;
|
||||||
use lemmy_api_common::site::CreateSite;
|
use lemmy_api_common::site::CreateSite;
|
||||||
use lemmy_db_schema::{source::local_site::LocalSite, ListingType, RegistrationMode, SortType};
|
use lemmy_db_schema::{
|
||||||
|
source::local_site::LocalSite,
|
||||||
|
CommentSortType,
|
||||||
|
ListingType,
|
||||||
|
PostSortType,
|
||||||
|
RegistrationMode,
|
||||||
|
};
|
||||||
use lemmy_utils::error::LemmyErrorType;
|
use lemmy_utils::error::LemmyErrorType;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -222,7 +229,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -246,7 +254,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -270,7 +279,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
Some(String::from("(zeta|alpha)")),
|
Some(String::from("(zeta|alpha)")),
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -294,7 +304,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
Some(ListingType::Subscribed),
|
Some(ListingType::Subscribed),
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -318,7 +329,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
Some(true),
|
Some(true),
|
||||||
Some(true),
|
Some(true),
|
||||||
|
@ -342,7 +354,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
Some(true),
|
Some(true),
|
||||||
|
@ -366,7 +379,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -424,7 +438,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -447,7 +462,8 @@ mod tests {
|
||||||
Some(String::new()),
|
Some(String::new()),
|
||||||
Some(String::new()),
|
Some(String::new()),
|
||||||
Some(ListingType::All),
|
Some(ListingType::All),
|
||||||
Some(SortType::Active),
|
Some(PostSortType::Active),
|
||||||
|
Some(CommentSortType::Hot),
|
||||||
Some(String::new()),
|
Some(String::new()),
|
||||||
Some(false),
|
Some(false),
|
||||||
Some(true),
|
Some(true),
|
||||||
|
@ -470,7 +486,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
Some(String::new()),
|
Some(String::new()),
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -493,7 +510,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -543,7 +561,8 @@ mod tests {
|
||||||
site_description: Option<String>,
|
site_description: Option<String>,
|
||||||
site_sidebar: Option<String>,
|
site_sidebar: Option<String>,
|
||||||
site_listing_type: Option<ListingType>,
|
site_listing_type: Option<ListingType>,
|
||||||
site_sort_type: Option<SortType>,
|
site_post_sort_type: Option<PostSortType>,
|
||||||
|
site_comment_sort_type: Option<CommentSortType>,
|
||||||
site_slur_filter_regex: Option<String>,
|
site_slur_filter_regex: Option<String>,
|
||||||
site_is_private: Option<bool>,
|
site_is_private: Option<bool>,
|
||||||
site_is_federated: Option<bool>,
|
site_is_federated: Option<bool>,
|
||||||
|
@ -564,7 +583,8 @@ mod tests {
|
||||||
private_instance: site_is_private,
|
private_instance: site_is_private,
|
||||||
default_theme: None,
|
default_theme: None,
|
||||||
default_post_listing_type: site_listing_type,
|
default_post_listing_type: site_listing_type,
|
||||||
default_sort_type: site_sort_type,
|
default_post_sort_type: site_post_sort_type,
|
||||||
|
default_comment_sort_type: site_comment_sort_type,
|
||||||
legal_information: None,
|
legal_information: None,
|
||||||
application_email_admins: None,
|
application_email_admins: None,
|
||||||
hide_modlog_mod_names: None,
|
hide_modlog_mod_names: None,
|
||||||
|
|
|
@ -107,7 +107,8 @@ pub async fn update_site(
|
||||||
private_instance: data.private_instance,
|
private_instance: data.private_instance,
|
||||||
default_theme: data.default_theme.clone(),
|
default_theme: data.default_theme.clone(),
|
||||||
default_post_listing_type: data.default_post_listing_type,
|
default_post_listing_type: data.default_post_listing_type,
|
||||||
default_sort_type: data.default_sort_type,
|
default_post_sort_type: data.default_post_sort_type,
|
||||||
|
default_comment_sort_type: data.default_comment_sort_type,
|
||||||
legal_information: diesel_string_update(data.legal_information.as_deref()),
|
legal_information: diesel_string_update(data.legal_information.as_deref()),
|
||||||
application_email_admins: data.application_email_admins,
|
application_email_admins: data.application_email_admins,
|
||||||
hide_modlog_mod_names: data.hide_modlog_mod_names,
|
hide_modlog_mod_names: data.hide_modlog_mod_names,
|
||||||
|
@ -252,7 +253,13 @@ mod tests {
|
||||||
|
|
||||||
use crate::site::update::validate_update_payload;
|
use crate::site::update::validate_update_payload;
|
||||||
use lemmy_api_common::site::EditSite;
|
use lemmy_api_common::site::EditSite;
|
||||||
use lemmy_db_schema::{source::local_site::LocalSite, ListingType, RegistrationMode, SortType};
|
use lemmy_db_schema::{
|
||||||
|
source::local_site::LocalSite,
|
||||||
|
CommentSortType,
|
||||||
|
ListingType,
|
||||||
|
PostSortType,
|
||||||
|
RegistrationMode,
|
||||||
|
};
|
||||||
use lemmy_utils::error::LemmyErrorType;
|
use lemmy_utils::error::LemmyErrorType;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -273,7 +280,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -297,7 +305,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
Some(String::from("(zeta|alpha)")),
|
Some(String::from("(zeta|alpha)")),
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -321,7 +330,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
Some(ListingType::Subscribed),
|
Some(ListingType::Subscribed),
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -345,7 +355,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
Some(true),
|
Some(true),
|
||||||
Some(true),
|
Some(true),
|
||||||
|
@ -369,7 +380,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
Some(true),
|
Some(true),
|
||||||
|
@ -393,7 +405,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -448,7 +461,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -471,7 +485,8 @@ mod tests {
|
||||||
Some(String::new()),
|
Some(String::new()),
|
||||||
Some(String::new()),
|
Some(String::new()),
|
||||||
Some(ListingType::All),
|
Some(ListingType::All),
|
||||||
Some(SortType::Active),
|
Some(PostSortType::Active),
|
||||||
|
Some(CommentSortType::Hot),
|
||||||
Some(String::new()),
|
Some(String::new()),
|
||||||
Some(false),
|
Some(false),
|
||||||
Some(true),
|
Some(true),
|
||||||
|
@ -494,7 +509,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
Some(String::new()),
|
Some(String::new()),
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -517,7 +533,8 @@ mod tests {
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<ListingType>,
|
None::<ListingType>,
|
||||||
None::<SortType>,
|
None::<PostSortType>,
|
||||||
|
None::<CommentSortType>,
|
||||||
None::<String>,
|
None::<String>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
None::<bool>,
|
None::<bool>,
|
||||||
|
@ -566,7 +583,8 @@ mod tests {
|
||||||
site_description: Option<String>,
|
site_description: Option<String>,
|
||||||
site_sidebar: Option<String>,
|
site_sidebar: Option<String>,
|
||||||
site_listing_type: Option<ListingType>,
|
site_listing_type: Option<ListingType>,
|
||||||
site_sort_type: Option<SortType>,
|
site_post_sort_type: Option<PostSortType>,
|
||||||
|
site_comment_sort_type: Option<CommentSortType>,
|
||||||
site_slur_filter_regex: Option<String>,
|
site_slur_filter_regex: Option<String>,
|
||||||
site_is_private: Option<bool>,
|
site_is_private: Option<bool>,
|
||||||
site_is_federated: Option<bool>,
|
site_is_federated: Option<bool>,
|
||||||
|
@ -588,7 +606,8 @@ mod tests {
|
||||||
private_instance: site_is_private,
|
private_instance: site_is_private,
|
||||||
default_theme: None,
|
default_theme: None,
|
||||||
default_post_listing_type: site_listing_type,
|
default_post_listing_type: site_listing_type,
|
||||||
default_sort_type: site_sort_type,
|
default_post_sort_type: site_post_sort_type,
|
||||||
|
default_comment_sort_type: site_comment_sort_type,
|
||||||
legal_information: None,
|
legal_information: None,
|
||||||
application_email_admins: None,
|
application_email_admins: None,
|
||||||
hide_modlog_mod_names: None,
|
hide_modlog_mod_names: None,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use super::comment_sort_type_with_default;
|
||||||
use crate::{
|
use crate::{
|
||||||
api::listing_type_with_default,
|
api::listing_type_with_default,
|
||||||
fetcher::resolve_actor_identifier,
|
fetcher::resolve_actor_identifier,
|
||||||
|
@ -35,7 +36,12 @@ pub async fn list_comments(
|
||||||
} else {
|
} else {
|
||||||
data.community_id
|
data.community_id
|
||||||
};
|
};
|
||||||
let sort = data.sort;
|
let local_user_ref = local_user_view.as_ref().map(|u| &u.local_user);
|
||||||
|
let sort = Some(comment_sort_type_with_default(
|
||||||
|
data.sort,
|
||||||
|
local_user_ref,
|
||||||
|
&local_site,
|
||||||
|
));
|
||||||
let max_depth = data.max_depth;
|
let max_depth = data.max_depth;
|
||||||
let saved_only = data.saved_only;
|
let saved_only = data.saved_only;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{listing_type_with_default, sort_type_with_default},
|
api::{listing_type_with_default, post_sort_type_with_default},
|
||||||
fetcher::resolve_actor_identifier,
|
fetcher::resolve_actor_identifier,
|
||||||
objects::community::ApubCommunity,
|
objects::community::ApubCommunity,
|
||||||
};
|
};
|
||||||
|
@ -57,7 +57,7 @@ pub async fn list_posts(
|
||||||
community_id,
|
community_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
let sort = Some(sort_type_with_default(
|
let sort = Some(post_sort_type_with_default(
|
||||||
data.sort,
|
data.sort,
|
||||||
local_user,
|
local_user,
|
||||||
&local_site.local_site,
|
&local_site.local_site,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::CommunityId,
|
newtypes::CommunityId,
|
||||||
source::{local_site::LocalSite, local_user::LocalUser},
|
source::{local_site::LocalSite, local_user::LocalUser},
|
||||||
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod list_comments;
|
pub mod list_comments;
|
||||||
|
@ -33,16 +34,30 @@ fn listing_type_with_default(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a default instance-level sort type, if none is given by the user.
|
/// Returns a default instance-level post sort type, if none is given by the user.
|
||||||
/// Order is type, local user default, then site default.
|
/// Order is type, local user default, then site default.
|
||||||
fn sort_type_with_default(
|
fn post_sort_type_with_default(
|
||||||
type_: Option<SortType>,
|
type_: Option<PostSortType>,
|
||||||
local_user: Option<&LocalUser>,
|
local_user: Option<&LocalUser>,
|
||||||
local_site: &LocalSite,
|
local_site: &LocalSite,
|
||||||
) -> SortType {
|
) -> PostSortType {
|
||||||
type_.unwrap_or(
|
type_.unwrap_or(
|
||||||
local_user
|
local_user
|
||||||
.map(|u| u.default_sort_type)
|
.map(|u| u.default_post_sort_type)
|
||||||
.unwrap_or(local_site.default_sort_type),
|
.unwrap_or(local_site.default_post_sort_type),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a default instance-level comment sort type, if none is given by the user.
|
||||||
|
/// Order is type, local user default, then site default.
|
||||||
|
fn comment_sort_type_with_default(
|
||||||
|
type_: Option<CommentSortType>,
|
||||||
|
local_user: Option<&LocalUser>,
|
||||||
|
local_site: &LocalSite,
|
||||||
|
) -> CommentSortType {
|
||||||
|
type_.unwrap_or(
|
||||||
|
local_user
|
||||||
|
.map(|u| u.default_comment_sort_type)
|
||||||
|
.unwrap_or(local_site.default_comment_sort_type),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,8 @@ pub async fn import_settings(
|
||||||
let local_user_form = LocalUserUpdateForm {
|
let local_user_form = LocalUserUpdateForm {
|
||||||
show_nsfw: data.settings.as_ref().map(|s| s.show_nsfw),
|
show_nsfw: data.settings.as_ref().map(|s| s.show_nsfw),
|
||||||
theme: data.settings.clone().map(|s| s.theme.clone()),
|
theme: data.settings.clone().map(|s| s.theme.clone()),
|
||||||
default_sort_type: data.settings.as_ref().map(|s| s.default_sort_type),
|
default_post_sort_type: data.settings.as_ref().map(|s| s.default_post_sort_type),
|
||||||
|
default_comment_sort_type: data.settings.as_ref().map(|s| s.default_comment_sort_type),
|
||||||
default_listing_type: data.settings.as_ref().map(|s| s.default_listing_type),
|
default_listing_type: data.settings.as_ref().map(|s| s.default_listing_type),
|
||||||
interface_language: data.settings.clone().map(|s| s.interface_language),
|
interface_language: data.settings.clone().map(|s| s.interface_language),
|
||||||
show_avatars: data.settings.as_ref().map(|s| s.show_avatars),
|
show_avatars: data.settings.as_ref().map(|s| s.show_avatars),
|
||||||
|
|
|
@ -18,7 +18,7 @@ use activitypub_federation::{
|
||||||
};
|
};
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url};
|
use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url};
|
||||||
use lemmy_db_schema::{source::site::Site, utils::FETCH_LIMIT_MAX, SortType};
|
use lemmy_db_schema::{source::site::Site, utils::FETCH_LIMIT_MAX, PostSortType};
|
||||||
use lemmy_db_views::post_view::PostQuery;
|
use lemmy_db_views::post_view::PostQuery;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyResult};
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -39,7 +39,7 @@ impl Collection for ApubCommunityOutbox {
|
||||||
|
|
||||||
let post_views = PostQuery {
|
let post_views = PostQuery {
|
||||||
community_id: Some(owner.id),
|
community_id: Some(owner.id),
|
||||||
sort: Some(SortType::New),
|
sort: Some(PostSortType::New),
|
||||||
limit: Some(FETCH_LIMIT_MAX),
|
limit: Some(FETCH_LIMIT_MAX),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{build_db_pool, get_conn, now},
|
utils::{build_db_pool, get_conn, now},
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::{post_view::PostQuery, structs::PaginationCursor};
|
use lemmy_db_views::{post_view::PostQuery, structs::PaginationCursor};
|
||||||
use lemmy_utils::error::{LemmyErrorExt2, LemmyResult};
|
use lemmy_utils::error::{LemmyErrorExt2, LemmyResult};
|
||||||
|
@ -151,7 +151,7 @@ async fn try_main() -> LemmyResult<()> {
|
||||||
// TODO: include local_user
|
// TODO: include local_user
|
||||||
let post_views = PostQuery {
|
let post_views = PostQuery {
|
||||||
community_id: community_ids.as_slice().first().cloned(),
|
community_id: community_ids.as_slice().first().cloned(),
|
||||||
sort: Some(SortType::New),
|
sort: Some(PostSortType::New),
|
||||||
limit: Some(20),
|
limit: Some(20),
|
||||||
page_after,
|
page_after,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
@ -58,13 +58,13 @@ use ts_rs::TS;
|
||||||
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
|
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "full",
|
feature = "full",
|
||||||
ExistingTypePath = "crate::schema::sql_types::SortTypeEnum"
|
ExistingTypePath = "crate::schema::sql_types::PostSortTypeEnum"
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
|
#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
// TODO add the controversial and scaled rankings to the doc below
|
// TODO add the controversial and scaled rankings to the doc below
|
||||||
/// The post sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
|
/// The post sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
|
||||||
pub enum SortType {
|
pub enum PostSortType {
|
||||||
#[default]
|
#[default]
|
||||||
Active,
|
Active,
|
||||||
Hot,
|
Hot,
|
||||||
|
@ -87,11 +87,19 @@ pub enum SortType {
|
||||||
Scaled,
|
Scaled,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
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")]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
/// The comment sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
|
/// The comment sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
|
||||||
pub enum CommentSortType {
|
pub enum CommentSortType {
|
||||||
|
#[default]
|
||||||
Hot,
|
Hot,
|
||||||
Top,
|
Top,
|
||||||
New,
|
New,
|
||||||
|
|
|
@ -5,6 +5,10 @@ pub mod sql_types {
|
||||||
#[diesel(postgres_type(name = "actor_type_enum"))]
|
#[diesel(postgres_type(name = "actor_type_enum"))]
|
||||||
pub struct ActorTypeEnum;
|
pub struct ActorTypeEnum;
|
||||||
|
|
||||||
|
#[derive(diesel::sql_types::SqlType)]
|
||||||
|
#[diesel(postgres_type(name = "comment_sort_type_enum"))]
|
||||||
|
pub struct CommentSortTypeEnum;
|
||||||
|
|
||||||
#[derive(diesel::sql_types::SqlType)]
|
#[derive(diesel::sql_types::SqlType)]
|
||||||
#[diesel(postgres_type(name = "community_visibility"))]
|
#[diesel(postgres_type(name = "community_visibility"))]
|
||||||
pub struct CommunityVisibility;
|
pub struct CommunityVisibility;
|
||||||
|
@ -22,12 +26,12 @@ pub mod sql_types {
|
||||||
pub struct PostListingModeEnum;
|
pub struct PostListingModeEnum;
|
||||||
|
|
||||||
#[derive(diesel::sql_types::SqlType)]
|
#[derive(diesel::sql_types::SqlType)]
|
||||||
#[diesel(postgres_type(name = "registration_mode_enum"))]
|
#[diesel(postgres_type(name = "post_sort_type_enum"))]
|
||||||
pub struct RegistrationModeEnum;
|
pub struct PostSortTypeEnum;
|
||||||
|
|
||||||
#[derive(diesel::sql_types::SqlType)]
|
#[derive(diesel::sql_types::SqlType)]
|
||||||
#[diesel(postgres_type(name = "sort_type_enum"))]
|
#[diesel(postgres_type(name = "registration_mode_enum"))]
|
||||||
pub struct SortTypeEnum;
|
pub struct RegistrationModeEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
|
@ -363,7 +367,8 @@ diesel::table! {
|
||||||
use super::sql_types::ListingTypeEnum;
|
use super::sql_types::ListingTypeEnum;
|
||||||
use super::sql_types::RegistrationModeEnum;
|
use super::sql_types::RegistrationModeEnum;
|
||||||
use super::sql_types::PostListingModeEnum;
|
use super::sql_types::PostListingModeEnum;
|
||||||
use super::sql_types::SortTypeEnum;
|
use super::sql_types::PostSortTypeEnum;
|
||||||
|
use super::sql_types::CommentSortTypeEnum;
|
||||||
|
|
||||||
local_site (id) {
|
local_site (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
|
@ -391,7 +396,8 @@ diesel::table! {
|
||||||
reports_email_admins -> Bool,
|
reports_email_admins -> Bool,
|
||||||
federation_signed_fetch -> Bool,
|
federation_signed_fetch -> Bool,
|
||||||
default_post_listing_mode -> PostListingModeEnum,
|
default_post_listing_mode -> PostListingModeEnum,
|
||||||
default_sort_type -> SortTypeEnum,
|
default_post_sort_type -> PostSortTypeEnum,
|
||||||
|
default_comment_sort_type -> CommentSortTypeEnum,
|
||||||
oauth_registration -> Bool,
|
oauth_registration -> Bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,9 +435,10 @@ diesel::table! {
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
use diesel::sql_types::*;
|
use diesel::sql_types::*;
|
||||||
use super::sql_types::SortTypeEnum;
|
use super::sql_types::PostSortTypeEnum;
|
||||||
use super::sql_types::ListingTypeEnum;
|
use super::sql_types::ListingTypeEnum;
|
||||||
use super::sql_types::PostListingModeEnum;
|
use super::sql_types::PostListingModeEnum;
|
||||||
|
use super::sql_types::CommentSortTypeEnum;
|
||||||
|
|
||||||
local_user (id) {
|
local_user (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
|
@ -440,7 +447,7 @@ diesel::table! {
|
||||||
email -> Nullable<Text>,
|
email -> Nullable<Text>,
|
||||||
show_nsfw -> Bool,
|
show_nsfw -> Bool,
|
||||||
theme -> Text,
|
theme -> Text,
|
||||||
default_sort_type -> SortTypeEnum,
|
default_post_sort_type -> PostSortTypeEnum,
|
||||||
default_listing_type -> ListingTypeEnum,
|
default_listing_type -> ListingTypeEnum,
|
||||||
#[max_length = 20]
|
#[max_length = 20]
|
||||||
interface_language -> Varchar,
|
interface_language -> Varchar,
|
||||||
|
@ -461,6 +468,7 @@ diesel::table! {
|
||||||
enable_keyboard_navigation -> Bool,
|
enable_keyboard_navigation -> Bool,
|
||||||
enable_animated_images -> Bool,
|
enable_animated_images -> Bool,
|
||||||
collapse_bot_comments -> Bool,
|
collapse_bot_comments -> Bool,
|
||||||
|
default_comment_sort_type -> CommentSortTypeEnum,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
use crate::schema::local_site;
|
use crate::schema::local_site;
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{LocalSiteId, SiteId},
|
newtypes::{LocalSiteId, SiteId},
|
||||||
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
PostListingMode,
|
PostListingMode,
|
||||||
|
PostSortType,
|
||||||
RegistrationMode,
|
RegistrationMode,
|
||||||
SortType,
|
|
||||||
};
|
};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -66,8 +67,10 @@ pub struct LocalSite {
|
||||||
pub federation_signed_fetch: bool,
|
pub federation_signed_fetch: bool,
|
||||||
/// Default value for [LocalSite.post_listing_mode]
|
/// Default value for [LocalSite.post_listing_mode]
|
||||||
pub default_post_listing_mode: PostListingMode,
|
pub default_post_listing_mode: PostListingMode,
|
||||||
/// Default value for [LocalUser.post_listing_mode]
|
/// Default value for [LocalUser.post_sort_type]
|
||||||
pub default_sort_type: SortType,
|
pub default_post_sort_type: PostSortType,
|
||||||
|
/// Default value for [LocalUser.comment_sort_type]
|
||||||
|
pub default_comment_sort_type: CommentSortType,
|
||||||
/// Whether or not external auth methods can auto-register users.
|
/// Whether or not external auth methods can auto-register users.
|
||||||
pub oauth_registration: bool,
|
pub oauth_registration: bool,
|
||||||
}
|
}
|
||||||
|
@ -100,7 +103,8 @@ pub struct LocalSiteInsertForm {
|
||||||
pub reports_email_admins: Option<bool>,
|
pub reports_email_admins: Option<bool>,
|
||||||
pub federation_signed_fetch: Option<bool>,
|
pub federation_signed_fetch: Option<bool>,
|
||||||
pub default_post_listing_mode: Option<PostListingMode>,
|
pub default_post_listing_mode: Option<PostListingMode>,
|
||||||
pub default_sort_type: Option<SortType>,
|
pub default_post_sort_type: Option<PostSortType>,
|
||||||
|
pub default_comment_sort_type: Option<CommentSortType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
|
@ -129,5 +133,6 @@ pub struct LocalSiteUpdateForm {
|
||||||
pub updated: Option<Option<DateTime<Utc>>>,
|
pub updated: Option<Option<DateTime<Utc>>>,
|
||||||
pub federation_signed_fetch: Option<bool>,
|
pub federation_signed_fetch: Option<bool>,
|
||||||
pub default_post_listing_mode: Option<PostListingMode>,
|
pub default_post_listing_mode: Option<PostListingMode>,
|
||||||
pub default_sort_type: Option<SortType>,
|
pub default_post_sort_type: Option<PostSortType>,
|
||||||
|
pub default_comment_sort_type: Option<CommentSortType>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@ use crate::schema::local_user;
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{LocalUserId, PersonId},
|
newtypes::{LocalUserId, PersonId},
|
||||||
sensitive::SensitiveString,
|
sensitive::SensitiveString,
|
||||||
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
PostListingMode,
|
PostListingMode,
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
|
@ -29,7 +30,7 @@ pub struct LocalUser {
|
||||||
/// Whether to show NSFW content.
|
/// Whether to show NSFW content.
|
||||||
pub show_nsfw: bool,
|
pub show_nsfw: bool,
|
||||||
pub theme: String,
|
pub theme: String,
|
||||||
pub default_sort_type: SortType,
|
pub default_post_sort_type: PostSortType,
|
||||||
pub default_listing_type: ListingType,
|
pub default_listing_type: ListingType,
|
||||||
pub interface_language: String,
|
pub interface_language: String,
|
||||||
/// Whether to show avatars.
|
/// Whether to show avatars.
|
||||||
|
@ -63,6 +64,7 @@ pub struct LocalUser {
|
||||||
pub enable_animated_images: bool,
|
pub enable_animated_images: bool,
|
||||||
/// Whether to auto-collapse bot comments.
|
/// Whether to auto-collapse bot comments.
|
||||||
pub collapse_bot_comments: bool,
|
pub collapse_bot_comments: bool,
|
||||||
|
pub default_comment_sort_type: CommentSortType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, derive_new::new)]
|
#[derive(Clone, derive_new::new)]
|
||||||
|
@ -78,7 +80,7 @@ pub struct LocalUserInsertForm {
|
||||||
#[new(default)]
|
#[new(default)]
|
||||||
pub theme: Option<String>,
|
pub theme: Option<String>,
|
||||||
#[new(default)]
|
#[new(default)]
|
||||||
pub default_sort_type: Option<SortType>,
|
pub default_post_sort_type: Option<PostSortType>,
|
||||||
#[new(default)]
|
#[new(default)]
|
||||||
pub default_listing_type: Option<ListingType>,
|
pub default_listing_type: Option<ListingType>,
|
||||||
#[new(default)]
|
#[new(default)]
|
||||||
|
@ -117,6 +119,8 @@ pub struct LocalUserInsertForm {
|
||||||
pub enable_animated_images: Option<bool>,
|
pub enable_animated_images: Option<bool>,
|
||||||
#[new(default)]
|
#[new(default)]
|
||||||
pub collapse_bot_comments: Option<bool>,
|
pub collapse_bot_comments: Option<bool>,
|
||||||
|
#[new(default)]
|
||||||
|
pub default_comment_sort_type: Option<CommentSortType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
|
@ -127,7 +131,7 @@ pub struct LocalUserUpdateForm {
|
||||||
pub email: Option<Option<String>>,
|
pub email: Option<Option<String>>,
|
||||||
pub show_nsfw: Option<bool>,
|
pub show_nsfw: Option<bool>,
|
||||||
pub theme: Option<String>,
|
pub theme: Option<String>,
|
||||||
pub default_sort_type: Option<SortType>,
|
pub default_post_sort_type: Option<PostSortType>,
|
||||||
pub default_listing_type: Option<ListingType>,
|
pub default_listing_type: Option<ListingType>,
|
||||||
pub interface_language: Option<String>,
|
pub interface_language: Option<String>,
|
||||||
pub show_avatars: Option<bool>,
|
pub show_avatars: Option<bool>,
|
||||||
|
@ -147,4 +151,5 @@ pub struct LocalUserUpdateForm {
|
||||||
pub enable_keyboard_navigation: Option<bool>,
|
pub enable_keyboard_navigation: Option<bool>,
|
||||||
pub enable_animated_images: Option<bool>,
|
pub enable_animated_images: Option<bool>,
|
||||||
pub collapse_bot_comments: Option<bool>,
|
pub collapse_bot_comments: Option<bool>,
|
||||||
|
pub default_comment_sort_type: Option<CommentSortType>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{newtypes::DbUrl, CommentSortType, SortType};
|
use crate::{newtypes::DbUrl, CommentSortType, PostSortType};
|
||||||
use chrono::{DateTime, TimeDelta, Utc};
|
use chrono::{DateTime, TimeDelta, Utc};
|
||||||
use deadpool::Runtime;
|
use deadpool::Runtime;
|
||||||
use diesel::{
|
use diesel::{
|
||||||
|
@ -481,23 +481,15 @@ pub fn naive_now() -> DateTime<Utc> {
|
||||||
Utc::now()
|
Utc::now()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn post_to_comment_sort_type(sort: SortType) -> CommentSortType {
|
pub fn post_to_comment_sort_type(sort: PostSortType) -> CommentSortType {
|
||||||
|
use PostSortType::*;
|
||||||
match sort {
|
match sort {
|
||||||
SortType::Active | SortType::Hot | SortType::Scaled => CommentSortType::Hot,
|
Active | Hot | Scaled => CommentSortType::Hot,
|
||||||
SortType::New | SortType::NewComments | SortType::MostComments => CommentSortType::New,
|
New | NewComments | MostComments => CommentSortType::New,
|
||||||
SortType::Old => CommentSortType::Old,
|
Old => CommentSortType::Old,
|
||||||
SortType::Controversial => CommentSortType::Controversial,
|
Controversial => CommentSortType::Controversial,
|
||||||
SortType::TopHour
|
TopHour | TopSixHour | TopTwelveHour | TopDay | TopAll | TopWeek | TopYear | TopMonth
|
||||||
| SortType::TopSixHour
|
| TopThreeMonths | TopSixMonths | TopNineMonths => CommentSortType::Top,
|
||||||
| SortType::TopTwelveHour
|
|
||||||
| SortType::TopDay
|
|
||||||
| SortType::TopAll
|
|
||||||
| SortType::TopWeek
|
|
||||||
| SortType::TopYear
|
|
||||||
| SortType::TopMonth
|
|
||||||
| SortType::TopThreeMonths
|
|
||||||
| SortType::TopSixMonths
|
|
||||||
| SortType::TopNineMonths => CommentSortType::Top,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,10 @@ use lemmy_db_schema::{
|
||||||
ReverseTimestampKey,
|
ReverseTimestampKey,
|
||||||
},
|
},
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
use PostSortType::*;
|
||||||
|
|
||||||
fn queries<'a>() -> Queries<
|
fn queries<'a>() -> Queries<
|
||||||
impl ReadFn<'a, PostView, (PostId, Option<&'a LocalUser>, bool)>,
|
impl ReadFn<'a, PostView, (PostId, Option<&'a LocalUser>, bool)>,
|
||||||
|
@ -510,33 +511,33 @@ fn queries<'a>() -> Queries<
|
||||||
let time = |interval| post_aggregates::published.gt(now() - interval);
|
let time = |interval| post_aggregates::published.gt(now() - interval);
|
||||||
|
|
||||||
// then use the main sort
|
// then use the main sort
|
||||||
query = match options.sort.unwrap_or(SortType::Hot) {
|
query = match options.sort.unwrap_or(Hot) {
|
||||||
SortType::Active => query.then_desc(key::hot_rank_active),
|
Active => query.then_desc(key::hot_rank_active),
|
||||||
SortType::Hot => query.then_desc(key::hot_rank),
|
Hot => query.then_desc(key::hot_rank),
|
||||||
SortType::Scaled => query.then_desc(key::scaled_rank),
|
Scaled => query.then_desc(key::scaled_rank),
|
||||||
SortType::Controversial => query.then_desc(key::controversy_rank),
|
Controversial => query.then_desc(key::controversy_rank),
|
||||||
SortType::New => query.then_desc(key::published),
|
New => query.then_desc(key::published),
|
||||||
SortType::Old => query.then_desc(ReverseTimestampKey(key::published)),
|
Old => query.then_desc(ReverseTimestampKey(key::published)),
|
||||||
SortType::NewComments => query.then_desc(key::newest_comment_time),
|
NewComments => query.then_desc(key::newest_comment_time),
|
||||||
SortType::MostComments => query.then_desc(key::comments),
|
MostComments => query.then_desc(key::comments),
|
||||||
SortType::TopAll => query.then_desc(key::score),
|
TopAll => query.then_desc(key::score),
|
||||||
SortType::TopYear => query.then_desc(key::score).filter(time(1.years())),
|
TopYear => query.then_desc(key::score).filter(time(1.years())),
|
||||||
SortType::TopMonth => query.then_desc(key::score).filter(time(1.months())),
|
TopMonth => query.then_desc(key::score).filter(time(1.months())),
|
||||||
SortType::TopWeek => query.then_desc(key::score).filter(time(1.weeks())),
|
TopWeek => query.then_desc(key::score).filter(time(1.weeks())),
|
||||||
SortType::TopDay => query.then_desc(key::score).filter(time(1.days())),
|
TopDay => query.then_desc(key::score).filter(time(1.days())),
|
||||||
SortType::TopHour => query.then_desc(key::score).filter(time(1.hours())),
|
TopHour => query.then_desc(key::score).filter(time(1.hours())),
|
||||||
SortType::TopSixHour => query.then_desc(key::score).filter(time(6.hours())),
|
TopSixHour => query.then_desc(key::score).filter(time(6.hours())),
|
||||||
SortType::TopTwelveHour => query.then_desc(key::score).filter(time(12.hours())),
|
TopTwelveHour => query.then_desc(key::score).filter(time(12.hours())),
|
||||||
SortType::TopThreeMonths => query.then_desc(key::score).filter(time(3.months())),
|
TopThreeMonths => query.then_desc(key::score).filter(time(3.months())),
|
||||||
SortType::TopSixMonths => query.then_desc(key::score).filter(time(6.months())),
|
TopSixMonths => query.then_desc(key::score).filter(time(6.months())),
|
||||||
SortType::TopNineMonths => query.then_desc(key::score).filter(time(9.months())),
|
TopNineMonths => query.then_desc(key::score).filter(time(9.months())),
|
||||||
};
|
};
|
||||||
|
|
||||||
// use publish as fallback. especially useful for hot rank which reaches zero after some days.
|
// use publish as fallback. especially useful for hot rank which reaches zero after some days.
|
||||||
// necessary because old posts can be fetched over federation and inserted with high post id
|
// necessary because old posts can be fetched over federation and inserted with high post id
|
||||||
query = match options.sort.unwrap_or(SortType::Hot) {
|
query = match options.sort.unwrap_or(Hot) {
|
||||||
// A second time-based sort would not be very useful
|
// A second time-based sort would not be very useful
|
||||||
SortType::New | SortType::Old | SortType::NewComments => query,
|
New | Old | NewComments => query,
|
||||||
_ => query.then_desc(key::published),
|
_ => query.then_desc(key::published),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -608,7 +609,7 @@ pub struct PaginationCursorData(PostAggregates);
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct PostQuery<'a> {
|
pub struct PostQuery<'a> {
|
||||||
pub listing_type: Option<ListingType>,
|
pub listing_type: Option<ListingType>,
|
||||||
pub sort: Option<SortType>,
|
pub sort: Option<PostSortType>,
|
||||||
pub creator_id: Option<PersonId>,
|
pub creator_id: Option<PersonId>,
|
||||||
pub community_id: Option<CommunityId>,
|
pub community_id: Option<CommunityId>,
|
||||||
// if true, the query should be handled as if community_id was not given except adding the
|
// if true, the query should be handled as if community_id was not given except adding the
|
||||||
|
@ -770,7 +771,7 @@ mod tests {
|
||||||
traits::{Bannable, Blockable, Crud, Joinable, Likeable},
|
traits::{Bannable, Blockable, Crud, Joinable, Likeable},
|
||||||
utils::{build_db_pool, build_db_pool_for_tests, DbPool, RANK_DEFAULT},
|
utils::{build_db_pool, build_db_pool_for_tests, DbPool, RANK_DEFAULT},
|
||||||
CommunityVisibility,
|
CommunityVisibility,
|
||||||
SortType,
|
PostSortType,
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
||||||
|
@ -801,7 +802,7 @@ mod tests {
|
||||||
impl Data {
|
impl Data {
|
||||||
fn default_post_query(&self) -> PostQuery<'_> {
|
fn default_post_query(&self) -> PostQuery<'_> {
|
||||||
PostQuery {
|
PostQuery {
|
||||||
sort: Some(SortType::New),
|
sort: Some(PostSortType::New),
|
||||||
local_user: Some(&self.local_user_view.local_user),
|
local_user: Some(&self.local_user_view.local_user),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -1445,7 +1446,7 @@ mod tests {
|
||||||
|
|
||||||
let options = PostQuery {
|
let options = PostQuery {
|
||||||
community_id: Some(inserted_community.id),
|
community_id: Some(inserted_community.id),
|
||||||
sort: Some(SortType::MostComments),
|
sort: Some(PostSortType::MostComments),
|
||||||
limit: Some(10),
|
limit: Some(10),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -1577,7 +1578,7 @@ mod tests {
|
||||||
|
|
||||||
// Make sure it does come back with the show_hidden option
|
// Make sure it does come back with the show_hidden option
|
||||||
let post_listings_show_hidden = PostQuery {
|
let post_listings_show_hidden = PostQuery {
|
||||||
sort: Some(SortType::New),
|
sort: Some(PostSortType::New),
|
||||||
local_user: Some(&data.local_user_view.local_user),
|
local_user: Some(&data.local_user_view.local_user),
|
||||||
show_hidden: Some(true),
|
show_hidden: Some(true),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -1618,7 +1619,7 @@ mod tests {
|
||||||
|
|
||||||
// Make sure it does come back with the show_nsfw option
|
// Make sure it does come back with the show_nsfw option
|
||||||
let post_listings_show_nsfw = PostQuery {
|
let post_listings_show_nsfw = PostQuery {
|
||||||
sort: Some(SortType::New),
|
sort: Some(PostSortType::New),
|
||||||
show_nsfw: Some(true),
|
show_nsfw: Some(true),
|
||||||
local_user: Some(&data.local_user_view.local_user),
|
local_user: Some(&data.local_user_view.local_user),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
@ -246,7 +246,8 @@ mod tests {
|
||||||
auto_expand: inserted_sara_local_user.auto_expand,
|
auto_expand: inserted_sara_local_user.auto_expand,
|
||||||
blur_nsfw: inserted_sara_local_user.blur_nsfw,
|
blur_nsfw: inserted_sara_local_user.blur_nsfw,
|
||||||
theme: inserted_sara_local_user.theme,
|
theme: inserted_sara_local_user.theme,
|
||||||
default_sort_type: inserted_sara_local_user.default_sort_type,
|
default_post_sort_type: inserted_sara_local_user.default_post_sort_type,
|
||||||
|
default_comment_sort_type: inserted_sara_local_user.default_comment_sort_type,
|
||||||
default_listing_type: inserted_sara_local_user.default_listing_type,
|
default_listing_type: inserted_sara_local_user.default_listing_type,
|
||||||
interface_language: inserted_sara_local_user.interface_language,
|
interface_language: inserted_sara_local_user.interface_language,
|
||||||
show_avatars: inserted_sara_local_user.show_avatars,
|
show_avatars: inserted_sara_local_user.show_avatars,
|
||||||
|
|
|
@ -24,7 +24,7 @@ use lemmy_db_schema::{
|
||||||
source::{community::CommunityFollower, local_user::LocalUser, site::Site},
|
source::{community::CommunityFollower, local_user::LocalUser, site::Site},
|
||||||
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn queries<'a>() -> Queries<
|
fn queries<'a>() -> Queries<
|
||||||
|
@ -102,7 +102,7 @@ fn queries<'a>() -> Queries<
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, (options, site): (CommunityQuery<'a>, &'a Site)| async move {
|
let list = move |mut conn: DbConn<'a>, (options, site): (CommunityQuery<'a>, &'a Site)| async move {
|
||||||
use SortType::*;
|
use PostSortType::*;
|
||||||
|
|
||||||
// The left join below will return None in this case
|
// The left join below will return None in this case
|
||||||
let person_id_join = options.local_user.person_id().unwrap_or(PersonId(-1));
|
let person_id_join = options.local_user.person_id().unwrap_or(PersonId(-1));
|
||||||
|
@ -221,7 +221,7 @@ impl CommunityView {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CommunityQuery<'a> {
|
pub struct CommunityQuery<'a> {
|
||||||
pub listing_type: Option<ListingType>,
|
pub listing_type: Option<ListingType>,
|
||||||
pub sort: Option<SortType>,
|
pub sort: Option<PostSortType>,
|
||||||
pub local_user: Option<&'a LocalUser>,
|
pub local_user: Option<&'a LocalUser>,
|
||||||
pub search_term: Option<String>,
|
pub search_term: Option<String>,
|
||||||
pub is_mod_or_admin: bool,
|
pub is_mod_or_admin: bool,
|
||||||
|
|
|
@ -24,7 +24,7 @@ use lemmy_db_schema::{
|
||||||
ReadFn,
|
ReadFn,
|
||||||
},
|
},
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{Display, EnumString};
|
use strum::{Display, EnumString};
|
||||||
|
@ -46,12 +46,13 @@ enum PersonSortType {
|
||||||
PostCount,
|
PostCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn post_to_person_sort_type(sort: SortType) -> PersonSortType {
|
fn post_to_person_sort_type(sort: PostSortType) -> PersonSortType {
|
||||||
|
use PostSortType::*;
|
||||||
match sort {
|
match sort {
|
||||||
SortType::Active | SortType::Hot | SortType::Controversial => PersonSortType::CommentScore,
|
Active | Hot | Controversial => PersonSortType::CommentScore,
|
||||||
SortType::New | SortType::NewComments => PersonSortType::New,
|
New | NewComments => PersonSortType::New,
|
||||||
SortType::MostComments => PersonSortType::MostComments,
|
MostComments => PersonSortType::MostComments,
|
||||||
SortType::Old => PersonSortType::Old,
|
Old => PersonSortType::Old,
|
||||||
_ => PersonSortType::CommentScore,
|
_ => PersonSortType::CommentScore,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +150,7 @@ impl PersonView {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct PersonQuery {
|
pub struct PersonQuery {
|
||||||
pub sort: Option<SortType>,
|
pub sort: Option<PostSortType>,
|
||||||
pub search_term: Option<String>,
|
pub search_term: Option<String>,
|
||||||
pub listing_type: Option<ListingType>,
|
pub listing_type: Option<ListingType>,
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
|
@ -246,7 +247,7 @@ mod tests {
|
||||||
assert!(read.is_none());
|
assert!(read.is_none());
|
||||||
|
|
||||||
let list = PersonQuery {
|
let list = PersonQuery {
|
||||||
sort: Some(SortType::New),
|
sort: Some(PostSortType::New),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool)
|
.list(pool)
|
||||||
|
|
|
@ -9,7 +9,7 @@ use lemmy_db_schema::{
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
CommunityVisibility,
|
CommunityVisibility,
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::{
|
use lemmy_db_views::{
|
||||||
post_view::PostQuery,
|
post_view::PostQuery,
|
||||||
|
@ -45,12 +45,12 @@ struct Params {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Params {
|
impl Params {
|
||||||
fn sort_type(&self) -> Result<SortType, Error> {
|
fn sort_type(&self) -> Result<PostSortType, Error> {
|
||||||
let sort_query = self
|
let sort_query = self
|
||||||
.sort
|
.sort
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| SortType::Hot.to_string());
|
.unwrap_or_else(|| PostSortType::Hot.to_string());
|
||||||
SortType::from_str(&sort_query).map_err(ErrorBadRequest)
|
PostSortType::from_str(&sort_query).map_err(ErrorBadRequest)
|
||||||
}
|
}
|
||||||
fn get_limit(&self) -> i64 {
|
fn get_limit(&self) -> i64 {
|
||||||
self.limit.unwrap_or(RSS_FETCH_LIMIT)
|
self.limit.unwrap_or(RSS_FETCH_LIMIT)
|
||||||
|
@ -147,7 +147,7 @@ async fn get_local_feed(
|
||||||
async fn get_feed_data(
|
async fn get_feed_data(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
listing_type: ListingType,
|
listing_type: ListingType,
|
||||||
sort_type: SortType,
|
sort_type: PostSortType,
|
||||||
limit: i64,
|
limit: i64,
|
||||||
page: i64,
|
page: i64,
|
||||||
) -> LemmyResult<HttpResponse> {
|
) -> LemmyResult<HttpResponse> {
|
||||||
|
@ -251,7 +251,7 @@ async fn get_feed(
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn get_feed_user(
|
async fn get_feed_user(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
sort_type: &SortType,
|
sort_type: &PostSortType,
|
||||||
limit: &i64,
|
limit: &i64,
|
||||||
page: &i64,
|
page: &i64,
|
||||||
user_name: &str,
|
user_name: &str,
|
||||||
|
@ -289,7 +289,7 @@ async fn get_feed_user(
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn get_feed_community(
|
async fn get_feed_community(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
sort_type: &SortType,
|
sort_type: &PostSortType,
|
||||||
limit: &i64,
|
limit: &i64,
|
||||||
page: &i64,
|
page: &i64,
|
||||||
community_name: &str,
|
community_name: &str,
|
||||||
|
@ -334,7 +334,7 @@ async fn get_feed_community(
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn get_feed_front(
|
async fn get_feed_front(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
sort_type: &SortType,
|
sort_type: &PostSortType,
|
||||||
limit: &i64,
|
limit: &i64,
|
||||||
page: &i64,
|
page: &i64,
|
||||||
jwt: &str,
|
jwt: &str,
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
-- This file should undo anything in `up.sql`
|
||||||
|
-- Rename the post sort enum
|
||||||
|
ALTER TYPE post_sort_type_enum RENAME TO sort_type_enum;
|
||||||
|
|
||||||
|
-- Rename the default post sort columns
|
||||||
|
ALTER TABLE local_user RENAME COLUMN default_post_sort_type TO default_sort_type;
|
||||||
|
|
||||||
|
ALTER TABLE local_site RENAME COLUMN default_post_sort_type TO default_sort_type;
|
||||||
|
|
||||||
|
-- Create the comment sort type enum
|
||||||
|
ALTER TABLE local_user
|
||||||
|
DROP COLUMN default_comment_sort_type;
|
||||||
|
|
||||||
|
ALTER TABLE local_site
|
||||||
|
DROP COLUMN default_comment_sort_type;
|
||||||
|
|
||||||
|
-- Drop the comment enum
|
||||||
|
DROP TYPE comment_sort_type_enum;
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
-- Rename the post sort enum
|
||||||
|
ALTER TYPE sort_type_enum RENAME TO post_sort_type_enum;
|
||||||
|
|
||||||
|
-- Rename the default post sort columns
|
||||||
|
ALTER TABLE local_user RENAME COLUMN default_sort_type TO default_post_sort_type;
|
||||||
|
|
||||||
|
ALTER TABLE local_site RENAME COLUMN default_sort_type TO default_post_sort_type;
|
||||||
|
|
||||||
|
-- Create the comment sort type enum
|
||||||
|
CREATE TYPE comment_sort_type_enum AS ENUM (
|
||||||
|
'Hot',
|
||||||
|
'Top',
|
||||||
|
'New',
|
||||||
|
'Old',
|
||||||
|
'Controversial'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Add the new default comment sort columns to local_user and local_site
|
||||||
|
ALTER TABLE local_user
|
||||||
|
ADD COLUMN default_comment_sort_type comment_sort_type_enum NOT NULL DEFAULT 'Hot';
|
||||||
|
|
||||||
|
ALTER TABLE local_site
|
||||||
|
ADD COLUMN default_comment_sort_type comment_sort_type_enum NOT NULL DEFAULT 'Hot';
|
||||||
|
|
Loading…
Reference in a new issue