From cfdc732d3aba160f6221542c74728cc6dec49bfa Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 7 May 2024 22:18:58 +0200 Subject: [PATCH] On registration set show_nsfw based on site.content_warning (#4616) Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> --- crates/api_common/src/person.rs | 2 +- crates/api_crud/src/user/create.rs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index 4f5aea2be..6f020df6d 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -40,7 +40,7 @@ pub struct Register { pub username: String, pub password: Sensitive, pub password_verify: Sensitive, - pub show_nsfw: bool, + pub show_nsfw: Option, /// email is mandatory if email verification is enabled on the server pub email: Option>, /// The UUID of the captcha item. diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index 6640e9e53..206ce241b 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -142,12 +142,17 @@ pub async fn register( .map(|lang_str| lang_str.split('-').next().unwrap_or_default().to_string()) .collect(); + // Show nsfw content if param is true, or if content_warning exists + let show_nsfw = data + .show_nsfw + .unwrap_or(site_view.site.content_warning.is_some()); + // Create the local user let local_user_form = LocalUserInsertForm::builder() .person_id(inserted_person.id) .email(data.email.as_deref().map(str::to_lowercase)) .password_encrypted(data.password.to_string()) - .show_nsfw(Some(data.show_nsfw)) + .show_nsfw(Some(show_nsfw)) .accepted_application(accepted_application) .default_listing_type(Some(local_site.default_post_listing_type)) .post_listing_mode(Some(local_site.default_post_listing_mode))