From f9351b651217cd437801e5f579891f5ad815e05d Mon Sep 17 00:00:00 2001 From: Domenic Horner Date: Wed, 26 Jul 2023 19:53:45 +0800 Subject: [PATCH] UI Settings - Blur NSFW & Auto Expand (#3377) * add new flag to api * add new ui settings for local user * remove extraneous def * add props to application reg. * fix clippy updated these * re-order db schema entries * remove dupe * update lemmy sdk * update lemmy js client --------- Co-authored-by: Nutomic --- api_tests/src/shared.ts | 4 ++++ crates/api/src/local_user/save_settings.rs | 2 ++ crates/api_common/src/person.rs | 2 ++ crates/db_schema/src/schema.rs | 2 ++ crates/db_schema/src/source/local_user.rs | 6 ++++++ crates/db_views/src/registration_application_view.rs | 2 ++ migrations/2023-06-27-065106_add_ui_settings/down.sql | 2 ++ migrations/2023-06-27-065106_add_ui_settings/up.sql | 6 ++++++ 8 files changed, 26 insertions(+) create mode 100644 migrations/2023-06-27-065106_add_ui_settings/down.sql create mode 100644 migrations/2023-06-27-065106_add_ui_settings/up.sql diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index bbd4eaae..e4306c94 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -611,6 +611,8 @@ export async function registerUser( export async function saveUserSettingsBio(api: API): Promise { let form: SaveUserSettings = { show_nsfw: true, + blur_nsfw: false, + auto_expand: true, theme: "darkly", default_sort_type: "Active", default_listing_type: "All", @@ -631,6 +633,8 @@ export async function saveUserSettingsFederated( let bio = "a changed bio"; let form: SaveUserSettings = { show_nsfw: false, + blur_nsfw: true, + auto_expand: false, default_sort_type: "Hot", default_listing_type: "All", interface_language: "", diff --git a/crates/api/src/local_user/save_settings.rs b/crates/api/src/local_user/save_settings.rs index 4176a3f4..c5038eb7 100644 --- a/crates/api/src/local_user/save_settings.rs +++ b/crates/api/src/local_user/save_settings.rs @@ -124,6 +124,8 @@ impl Perform for SaveUserSettings { .show_new_post_notifs(data.show_new_post_notifs) .send_notifications_to_email(data.send_notifications_to_email) .show_nsfw(data.show_nsfw) + .blur_nsfw(data.blur_nsfw) + .auto_expand(data.auto_expand) .show_bot_accounts(data.show_bot_accounts) .show_scores(data.show_scores) .default_sort_type(default_sort_type) diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index 031bc6c7..79a0aa37 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -91,6 +91,8 @@ pub struct CaptchaResponse { pub struct SaveUserSettings { /// Show nsfw posts. pub show_nsfw: Option, + pub blur_nsfw: Option, + pub auto_expand: Option, /// Show post and comment scores. pub show_scores: Option, /// Your user's theme. diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 17a0f99f..faebe999 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -395,6 +395,8 @@ diesel::table! { totp_2fa_secret -> Nullable, totp_2fa_url -> Nullable, open_links_in_new_tab -> Bool, + blur_nsfw -> Bool, + auto_expand -> Bool, infinite_scroll_enabled -> Bool, } } diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index d9e1bde7..0d8db669 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -53,6 +53,8 @@ pub struct LocalUser { pub totp_2fa_url: Option, /// Open links in a new tab. pub open_links_in_new_tab: bool, + pub blur_nsfw: bool, + pub auto_expand: bool, /// Whether infinite scroll is enabled. pub infinite_scroll_enabled: bool, } @@ -83,6 +85,8 @@ pub struct LocalUserInsertForm { pub totp_2fa_secret: Option>, pub totp_2fa_url: Option>, pub open_links_in_new_tab: Option, + pub blur_nsfw: Option, + pub auto_expand: Option, pub infinite_scroll_enabled: Option, } @@ -109,5 +113,7 @@ pub struct LocalUserUpdateForm { pub totp_2fa_secret: Option>, pub totp_2fa_url: Option>, pub open_links_in_new_tab: Option, + pub blur_nsfw: Option, + pub auto_expand: Option, pub infinite_scroll_enabled: Option, } diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index 106e41e4..8e2f5826 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -280,6 +280,8 @@ mod tests { person_id: inserted_sara_local_user.person_id, email: inserted_sara_local_user.email, show_nsfw: inserted_sara_local_user.show_nsfw, + auto_expand: inserted_sara_local_user.auto_expand, + blur_nsfw: inserted_sara_local_user.blur_nsfw, theme: inserted_sara_local_user.theme, default_sort_type: inserted_sara_local_user.default_sort_type, default_listing_type: inserted_sara_local_user.default_listing_type, diff --git a/migrations/2023-06-27-065106_add_ui_settings/down.sql b/migrations/2023-06-27-065106_add_ui_settings/down.sql new file mode 100644 index 00000000..51fa7046 --- /dev/null +++ b/migrations/2023-06-27-065106_add_ui_settings/down.sql @@ -0,0 +1,2 @@ +alter table local_user drop column blur_nsfw; +alter table local_user drop column auto_expand; diff --git a/migrations/2023-06-27-065106_add_ui_settings/up.sql b/migrations/2023-06-27-065106_add_ui_settings/up.sql new file mode 100644 index 00000000..3c66c9c7 --- /dev/null +++ b/migrations/2023-06-27-065106_add_ui_settings/up.sql @@ -0,0 +1,6 @@ + +-- Add the blur_nsfw to the local user table as a setting +alter table local_user add column blur_nsfw boolean not null default true; + +-- Add the auto_expand to the local user table as a setting +alter table local_user add column auto_expand boolean not null default false; -- 2.44.1