mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-10 19:11:47 +00:00
Include local_site.content_warning setting for showing nsfw by default
This commit is contained in:
parent
e78fe5a34c
commit
5a3a4d9fad
7 changed files with 30 additions and 5 deletions
|
@ -371,6 +371,7 @@ diesel::table! {
|
|||
registration_mode -> RegistrationModeEnum,
|
||||
reports_email_admins -> Bool,
|
||||
federation_signed_fetch -> Bool,
|
||||
content_warning -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,9 @@ pub struct LocalSite {
|
|||
/// Whether to sign outgoing Activitypub fetches with private key of local instance. Some
|
||||
/// Fediverse instances and platforms require this.
|
||||
pub federation_signed_fetch: bool,
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[derive(Clone, TypedBuilder)]
|
||||
|
@ -93,6 +96,7 @@ pub struct LocalSiteInsertForm {
|
|||
pub registration_mode: Option<RegistrationMode>,
|
||||
pub reports_email_admins: Option<bool>,
|
||||
pub federation_signed_fetch: Option<bool>,
|
||||
pub content_warning: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
|
@ -120,4 +124,5 @@ pub struct LocalSiteUpdateForm {
|
|||
pub reports_email_admins: Option<bool>,
|
||||
pub updated: Option<Option<DateTime<Utc>>>,
|
||||
pub federation_signed_fetch: Option<bool>,
|
||||
pub content_warning: Option<String>,
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ use lemmy_db_schema::{
|
|||
community_moderator,
|
||||
community_person_ban,
|
||||
instance_block,
|
||||
local_site::dsl::local_site,
|
||||
local_user,
|
||||
local_user_language,
|
||||
person,
|
||||
|
@ -37,6 +38,7 @@ use lemmy_db_schema::{
|
|||
post_read,
|
||||
post_saved,
|
||||
},
|
||||
source::local_site::LocalSite,
|
||||
utils::{
|
||||
functions::coalesce,
|
||||
fuzzy_search,
|
||||
|
@ -383,10 +385,17 @@ fn queries<'a>() -> Queries<
|
|||
);
|
||||
}
|
||||
|
||||
// If there is a content warning, show nsfw content by default.
|
||||
// TODO: inefficient
|
||||
let has_content_warning = local_site
|
||||
.first::<LocalSite>(&mut conn)
|
||||
.await?
|
||||
.content_warning
|
||||
.is_some();
|
||||
if !options
|
||||
.local_user
|
||||
.map(|l| l.local_user.show_nsfw)
|
||||
.unwrap_or(false)
|
||||
.unwrap_or(has_content_warning)
|
||||
{
|
||||
query = query
|
||||
.filter(post::nsfw.eq(false))
|
||||
|
|
|
@ -18,9 +18,10 @@ use lemmy_db_schema::{
|
|||
community_block,
|
||||
community_follower,
|
||||
instance_block,
|
||||
local_site::dsl::local_site,
|
||||
local_user,
|
||||
},
|
||||
source::{community::CommunityFollower, local_user::LocalUser},
|
||||
source::{community::CommunityFollower, local_site::LocalSite, local_user::LocalUser},
|
||||
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
||||
ListingType,
|
||||
SortType,
|
||||
|
@ -152,8 +153,15 @@ fn queries<'a>() -> Queries<
|
|||
query = query.filter(community_block::person_id.is_null());
|
||||
query = query.filter(community::nsfw.eq(false).or(local_user::show_nsfw.eq(true)));
|
||||
} else {
|
||||
// No person in request, only show nsfw communities if show_nsfw is passed into request
|
||||
if !options.show_nsfw {
|
||||
// No person in request, only show nsfw communities if show_nsfw is passed into request or if
|
||||
// site has content warning.
|
||||
// TODO: inefficient
|
||||
let has_content_warning = local_site
|
||||
.first::<LocalSite>(&mut conn)
|
||||
.await?
|
||||
.content_warning
|
||||
.is_some();
|
||||
if !options.show_nsfw && !has_content_warning {
|
||||
query = query.filter(community::nsfw.eq(false));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 3c217c609aa8826fc725f708221c8b3eb825f41a
|
||||
Subproject commit 2139975ef383077e4709a4f2cae42922fd63b860
|
|
@ -0,0 +1 @@
|
|||
alter table local_site drop column content_warning;
|
|
@ -0,0 +1 @@
|
|||
alter table local_site add column content_warning text;
|
Loading…
Reference in a new issue