Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a default_comment_sort_type column for local_site and local_user. #4469

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -85,7 +85,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 @@ -117,7 +118,8 @@ pub async fn save_user_settings(
auto_expand: data.auto_expand,
show_bot_accounts: data.show_bot_accounts,
show_scores: data.show_scores,
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
13 changes: 9 additions & 4 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, PostView};
use lemmy_db_views_actor::structs::{
Expand Down Expand Up @@ -90,8 +90,14 @@ pub struct SaveUserSettings {
pub show_scores: Option<bool>,
/// Your user's theme.
pub theme: Option<String>,
pub default_sort_type: Option<SortType>,
/// The default post listing type, usually "local"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grouped these together.

pub default_listing_type: Option<ListingType>,
/// Default value for listing mode, usually "list"
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 @@ -122,7 +128,6 @@ pub struct SaveUserSettings {
pub open_links_in_new_tab: Option<bool>,
/// Enable infinite scroll
pub infinite_scroll_enabled: Option<bool>,
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 should be paused
Expand Down Expand Up @@ -166,7 +171,7 @@ pub struct GetPersonDetails {
pub person_id: Option<PersonId>,
/// Example: dessalines , or dessalines@xyz.tld
pub username: Option<String>,
pub sort: Option<SortType>,
pub sort: Option<PostSortType>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still debating whether to separate this into post_sort and comment_sort, or to keep the current post_sort_to_comment_sort mapping.

The combined view is still limited by #2444

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mapping is necessary anyway because of search. Its pretty awkward but I dont see any good way to get rid of it.

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 @@ -70,7 +70,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 @@ -8,12 +8,13 @@ use lemmy_db_schema::{
language::Language,
tagline::Tagline,
},
CommentSortType,
ListingType,
ModlogActionType,
PostListingMode,
PostSortType,
RegistrationMode,
SearchType,
SortType,
};
use lemmy_db_views::structs::{
CommentView,
Expand Down Expand Up @@ -65,7 +66,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 @@ -162,7 +163,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 @@ -190,7 +193,6 @@ pub struct CreateSite {
pub taglines: Option<Vec<String>>,
pub registration_mode: Option<RegistrationMode>,
pub content_warning: Option<String>,
pub default_post_listing_mode: Option<PostListingMode>,
}

#[skip_serializing_none]
Expand Down Expand Up @@ -221,9 +223,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 @@ -274,8 +281,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 @@ -93,7 +93,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_option_overwrite(data.legal_information.clone()),
application_email_admins: data.application_email_admins,
hide_modlog_mod_names: data.hide_modlog_mod_names,
Expand Down Expand Up @@ -193,7 +194,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 @@ -215,7 +222,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand All @@ -239,7 +247,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand All @@ -263,7 +272,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 @@ -287,7 +297,8 @@ mod tests {
None::<String>,
None::<String>,
Some(ListingType::Subscribed),
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand All @@ -311,7 +322,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
Some(true),
Some(true),
Expand All @@ -335,7 +347,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
Some(true),
Expand All @@ -359,7 +372,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 @@ -417,7 +431,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
None::<String>,
None::<bool>,
None::<bool>,
Expand All @@ -440,7 +455,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 @@ -463,7 +479,8 @@ mod tests {
None::<String>,
None::<String>,
None::<ListingType>,
None::<SortType>,
None::<PostSortType>,
None::<CommentSortType>,
Some(String::new()),
None::<bool>,
None::<bool>,
Expand All @@ -486,7 +503,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 @@ -536,7 +554,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 @@ -557,7 +576,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