* Add default post listing type (fixes #2195) * review fixes * change column type
This commit is contained in:
parent
24be9f2cd5
commit
00b0b26dfa
13 changed files with 37 additions and 6 deletions
|
@ -109,6 +109,7 @@
|
||||||
application_question: "string"
|
application_question: "string"
|
||||||
private_instance: true
|
private_instance: true
|
||||||
default_theme: "string"
|
default_theme: "string"
|
||||||
|
default_post_listing_type: "string"
|
||||||
}
|
}
|
||||||
# the domain name of your instance (mandatory)
|
# the domain name of your instance (mandatory)
|
||||||
hostname: "unset"
|
hostname: "unset"
|
||||||
|
|
|
@ -107,6 +107,7 @@ pub struct CreateSite {
|
||||||
pub application_question: Option<String>,
|
pub application_question: Option<String>,
|
||||||
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<String>,
|
||||||
pub auth: Sensitive<String>,
|
pub auth: Sensitive<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +127,7 @@ pub struct EditSite {
|
||||||
pub application_question: Option<String>,
|
pub application_question: Option<String>,
|
||||||
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<String>,
|
||||||
pub auth: Sensitive<String>,
|
pub auth: Sensitive<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@ use lemmy_api_common::{
|
||||||
blocking,
|
blocking,
|
||||||
check_private_instance,
|
check_private_instance,
|
||||||
get_local_user_view_from_jwt_opt,
|
get_local_user_view_from_jwt_opt,
|
||||||
post::*,
|
post::{GetPosts, GetPostsResponse},
|
||||||
};
|
};
|
||||||
use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
|
use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
from_opt_str_to_opt_enum,
|
from_opt_str_to_opt_enum,
|
||||||
source::community::Community,
|
source::{community::Community, site::Site},
|
||||||
traits::DeleteableOrRemoveable,
|
traits::DeleteableOrRemoveable,
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
|
@ -17,6 +17,7 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views::post_view::PostQueryBuilder;
|
use lemmy_db_views::post_view::PostQueryBuilder;
|
||||||
use lemmy_utils::{ConnectionId, LemmyError};
|
use lemmy_utils::{ConnectionId, LemmyError};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for GetPosts {
|
impl PerformCrud for GetPosts {
|
||||||
|
@ -46,7 +47,13 @@ impl PerformCrud for GetPosts {
|
||||||
.map(|t| t.local_user.show_read_posts);
|
.map(|t| t.local_user.show_read_posts);
|
||||||
|
|
||||||
let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
|
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 listing_type: ListingType = match from_opt_str_to_opt_enum(&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 page = data.page;
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
check_private_instance,
|
check_private_instance,
|
||||||
get_local_user_view_from_jwt_opt,
|
get_local_user_view_from_jwt_opt,
|
||||||
mark_post_as_read,
|
mark_post_as_read,
|
||||||
post::*,
|
post::{GetPost, GetPostResponse},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::traits::DeleteableOrRemoveable;
|
use lemmy_db_schema::traits::DeleteableOrRemoveable;
|
||||||
use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostView};
|
use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostView};
|
||||||
|
|
|
@ -84,6 +84,7 @@ impl PerformCrud for CreateSite {
|
||||||
private_key: Some(Some(keypair.private_key)),
|
private_key: Some(Some(keypair.private_key)),
|
||||||
public_key: Some(keypair.public_key),
|
public_key: Some(keypair.public_key),
|
||||||
default_theme: data.default_theme.clone(),
|
default_theme: data.default_theme.clone(),
|
||||||
|
default_post_listing_type: data.default_post_listing_type.clone(),
|
||||||
..SiteForm::default()
|
..SiteForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ impl PerformCrud for GetSite {
|
||||||
application_question: setup.application_question.to_owned(),
|
application_question: setup.application_question.to_owned(),
|
||||||
private_instance: setup.private_instance,
|
private_instance: setup.private_instance,
|
||||||
default_theme: setup.default_theme.to_owned(),
|
default_theme: setup.default_theme.to_owned(),
|
||||||
|
default_post_listing_type: setup.default_post_listing_type.to_owned(),
|
||||||
auth: admin_jwt,
|
auth: admin_jwt,
|
||||||
};
|
};
|
||||||
create_site.perform(context, websocket_id).await?;
|
create_site.perform(context, websocket_id).await?;
|
||||||
|
|
|
@ -17,11 +17,12 @@ use lemmy_db_schema::{
|
||||||
site::{Site, SiteForm},
|
site::{Site, SiteForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
|
ListingType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::site_view::SiteView;
|
use lemmy_db_views::site_view::SiteView;
|
||||||
use lemmy_utils::{utils::check_slurs_opt, ConnectionId, LemmyError};
|
use lemmy_utils::{utils::check_slurs_opt, ConnectionId, LemmyError};
|
||||||
use lemmy_websocket::{messages::SendAllMessage, LemmyContext, UserOperationCrud};
|
use lemmy_websocket::{messages::SendAllMessage, LemmyContext, UserOperationCrud};
|
||||||
use std::default::Default;
|
use std::{default::Default, str::FromStr};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for EditSite {
|
impl PerformCrud for EditSite {
|
||||||
|
@ -64,6 +65,16 @@ impl PerformCrud for EditSite {
|
||||||
return Err(LemmyError::from_message("application_question_required"));
|
return Err(LemmyError::from_message("application_question_required"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(default_post_listing_type) = &data.default_post_listing_type {
|
||||||
|
// only allow all or local as default listing types
|
||||||
|
let val = ListingType::from_str(default_post_listing_type);
|
||||||
|
if val != Ok(ListingType::All) && val != Ok(ListingType::Local) {
|
||||||
|
return Err(LemmyError::from_message(
|
||||||
|
"invalid_default_post_listing_type",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let site_form = SiteForm {
|
let site_form = SiteForm {
|
||||||
name: data.name.to_owned().unwrap_or(local_site.name),
|
name: data.name.to_owned().unwrap_or(local_site.name),
|
||||||
sidebar,
|
sidebar,
|
||||||
|
@ -80,6 +91,7 @@ impl PerformCrud for EditSite {
|
||||||
application_question,
|
application_question,
|
||||||
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.clone(),
|
||||||
..SiteForm::default()
|
..SiteForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub enum SortType {
|
||||||
NewComments,
|
NewComments,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
|
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
|
||||||
pub enum ListingType {
|
pub enum ListingType {
|
||||||
All,
|
All,
|
||||||
Local,
|
Local,
|
||||||
|
|
|
@ -461,6 +461,7 @@ table! {
|
||||||
private_key -> Nullable<Text>,
|
private_key -> Nullable<Text>,
|
||||||
public_key -> Text,
|
public_key -> Text,
|
||||||
default_theme -> Text,
|
default_theme -> Text,
|
||||||
|
default_post_listing_type -> Text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ pub struct Site {
|
||||||
pub private_key: Option<String>,
|
pub private_key: Option<String>,
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
pub default_theme: String,
|
pub default_theme: String,
|
||||||
|
pub default_post_listing_type: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset, Default)]
|
#[derive(Insertable, AsChangeset, Default)]
|
||||||
|
@ -52,4 +53,5 @@ pub struct SiteForm {
|
||||||
pub private_key: Option<Option<String>>,
|
pub private_key: Option<Option<String>>,
|
||||||
pub public_key: Option<String>,
|
pub public_key: Option<String>,
|
||||||
pub default_theme: Option<String>,
|
pub default_theme: Option<String>,
|
||||||
|
pub default_post_listing_type: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,4 +217,6 @@ pub struct SetupConfig {
|
||||||
pub private_instance: Option<bool>,
|
pub private_instance: Option<bool>,
|
||||||
#[default(None)]
|
#[default(None)]
|
||||||
pub default_theme: Option<String>,
|
pub default_theme: Option<String>,
|
||||||
|
#[default(None)]
|
||||||
|
pub default_post_listing_type: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
alter table site drop column default_post_listing_type;
|
|
@ -0,0 +1 @@
|
||||||
|
alter table site add column default_post_listing_type text not null default 'Local';
|
Loading…
Reference in a new issue