Skip to content

Commit

Permalink
Adding a default_comment_sort_type column for local_site and local_us…
Browse files Browse the repository at this point in the history
…er. (LemmyNet#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 LemmyNet#4128

* Renaming migration to current date.

* Simplifying PostSortType.
  • Loading branch information
dessalines authored and Nutomic committed Sep 20, 2024
1 parent a437030 commit 0246082
Show file tree
Hide file tree
Showing 25 changed files with 286 additions and 150 deletions.
6 changes: 4 additions & 2 deletions crates/api/src/local_user/save_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ pub async fn save_user_settings(
let local_user_id = local_user_view.local_user.id;
let person_id = local_user_view.person.id;
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 {
display_name,
Expand Down Expand Up @@ -133,7 +134,8 @@ pub async fn save_user_settings(
blur_nsfw: data.blur_nsfw,
auto_expand: data.auto_expand,
show_bot_accounts: data.show_bot_accounts,
default_sort_type,
default_post_sort_type,
default_comment_sort_type,
default_listing_type,
theme: data.theme.clone(),
interface_language: data.interface_language.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/api_common/src/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use lemmy_db_schema::{
source::site::Site,
CommunityVisibility,
ListingType,
SortType,
PostSortType,
};
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -74,7 +74,7 @@ pub struct CommunityResponse {
/// Fetches a list of communities.
pub struct ListCommunities {
pub type_: Option<ListingType>,
pub sort: Option<SortType>,
pub sort: Option<PostSortType>,
pub show_nsfw: Option<bool>,
pub page: Option<i64>,
pub limit: Option<i64>,
Expand Down
14 changes: 9 additions & 5 deletions crates/api_common/src/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use lemmy_db_schema::{
CommentSortType,
ListingType,
PostListingMode,
SortType,
PostSortType,
};
use lemmy_db_views::structs::{CommentView, LocalImageView, PostView};
use lemmy_db_views_actor::structs::{
Expand Down Expand Up @@ -88,8 +88,14 @@ pub struct SaveUserSettings {
pub auto_expand: Option<bool>,
/// Your user's theme.
pub theme: Option<String>,
pub default_sort_type: Option<SortType>,
/// The default post listing type, usually "local"
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
pub interface_language: Option<String>,
/// A URL for your avatar.
Expand Down Expand Up @@ -120,8 +126,6 @@ pub struct SaveUserSettings {
pub open_links_in_new_tab: Option<bool>,
/// Enable infinite scroll
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).
pub enable_keyboard_navigation: Option<bool>,
/// Whether user avatars or inline images in the UI that are gifs should be allowed to play or
Expand Down Expand Up @@ -172,7 +176,7 @@ pub struct GetPersonDetails {
pub person_id: Option<PersonId>,
/// Example: dessalines , or [email protected]
pub username: Option<String>,
pub sort: Option<SortType>,
pub sort: Option<PostSortType>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub community_id: Option<CommunityId>,
Expand Down
4 changes: 2 additions & 2 deletions crates/api_common/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use lemmy_db_schema::{
newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId},
ListingType,
PostFeatureType,
SortType,
PostSortType,
};
use lemmy_db_views::structs::{PaginationCursor, PostReportView, PostView, VoteView};
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
Expand Down Expand Up @@ -69,7 +69,7 @@ pub struct GetPostResponse {
/// Get a list of posts.
pub struct GetPosts {
pub type_: Option<ListingType>,
pub sort: Option<SortType>,
pub sort: Option<PostSortType>,
/// DEPRECATED, use page_cursor
pub page: Option<i64>,
pub limit: Option<i64>,
Expand Down
21 changes: 13 additions & 8 deletions crates/api_common/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ use lemmy_db_schema::{
person::Person,
tagline::Tagline,
},
CommentSortType,
ListingType,
ModlogActionType,
PostListingMode,
PostSortType,
RegistrationMode,
SearchType,
SortType,
};
use lemmy_db_views::structs::{
CommentView,
Expand Down Expand Up @@ -74,7 +75,7 @@ pub struct Search {
pub community_name: Option<String>,
pub creator_id: Option<PersonId>,
pub type_: Option<SearchType>,
pub sort: Option<SortType>,
pub sort: Option<PostSortType>,
pub listing_type: Option<ListingType>,
pub page: Option<i64>,
pub limit: Option<i64>,
Expand Down Expand Up @@ -174,7 +175,9 @@ pub struct CreateSite {
pub private_instance: Option<bool>,
pub default_theme: Option<String>,
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 application_email_admins: Option<bool>,
pub hide_modlog_mod_names: Option<bool>,
Expand Down Expand Up @@ -203,7 +206,6 @@ pub struct CreateSite {
pub registration_mode: Option<RegistrationMode>,
pub oauth_registration: Option<bool>,
pub content_warning: Option<String>,
pub default_post_listing_mode: Option<PostListingMode>,
}

#[skip_serializing_none]
Expand Down Expand Up @@ -234,9 +236,14 @@ pub struct EditSite {
pub private_instance: Option<bool>,
/// The default theme. Usually "browser"
pub default_theme: Option<String>,
/// The default post listing type, usually "local"
pub default_post_listing_type: Option<ListingType>,
/// The default sort, usually "active"
pub default_sort_type: Option<SortType>,
/// Default value for listing mode, usually "list"
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
pub legal_information: Option<String>,
/// Whether to email admins when receiving a new application.
Expand Down Expand Up @@ -291,8 +298,6 @@ pub struct EditSite {
/// If present, nsfw content is visible by default. Should be displayed by frontends/clients
/// when the site is first opened by a user.
pub content_warning: Option<String>,
/// Default value for [LocalUser.post_listing_mode]
pub default_post_listing_mode: Option<PostListingMode>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
50 changes: 35 additions & 15 deletions crates/api_crud/src/site/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ pub async fn create_site(
private_instance: data.private_instance,
default_theme: data.default_theme.clone(),
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()),
application_email_admins: data.application_email_admins,
hide_modlog_mod_names: data.hide_modlog_mod_names,
Expand Down Expand Up @@ -200,7 +201,13 @@ mod tests {

use crate::site::create::validate_create_payload;
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;

#[test]
Expand All @@ -222,7 +229,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand All @@ -246,7 +254,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand All @@ -270,7 +279,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
Some(String::from("(zeta|alpha)")),
None::<bool>,
None::<bool>,
Expand All @@ -294,7 +304,8 @@ mod tests {
None::<String>,
None::<String>,
Some(ListingType::Subscribed),
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand All @@ -318,7 +329,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
Some(true),
Some(true),
Expand All @@ -342,7 +354,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
Some(true),
Expand All @@ -366,7 +379,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand Down Expand Up @@ -424,7 +438,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand All @@ -447,7 +462,8 @@ mod tests {
Some(String::new()),
Some(String::new()),
Some(ListingType::All),
Some(SortType::Active),
Some(PostSortType::Active),
Some(CommentSortType::Hot),
Some(String::new()),
Some(false),
Some(true),
Expand All @@ -470,7 +486,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
Some(String::new()),
None::<bool>,
None::<bool>,
Expand All @@ -493,7 +510,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand Down Expand Up @@ -543,7 +561,8 @@ mod tests {
site_description: Option<String>,
site_sidebar: Option<String>,
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_is_private: Option<bool>,
site_is_federated: Option<bool>,
Expand All @@ -564,7 +583,8 @@ mod tests {
private_instance: site_is_private,
default_theme: None,
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,
application_email_admins: None,
hide_modlog_mod_names: None,
Expand Down
Loading

0 comments on commit 0246082

Please sign in to comment.