From 8b57ebff6cd8d2909b6e97cbdb3e5d0bb9b6d084 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 19 Jul 2021 10:05:22 -0400 Subject: [PATCH] Add show_new_posts_notifs setting. Fixes #1664 --- crates/api/src/local_user.rs | 1 + crates/api_common/src/person.rs | 1 + crates/api_crud/src/user/create.rs | 2 ++ crates/db_queries/src/source/local_user.rs | 2 ++ crates/db_schema/src/schema.rs | 1 + crates/db_schema/src/source/local_user.rs | 3 +++ .../down.sql | 1 + .../2021-07-19-130929_add_show_new_post_notifs_setting/up.sql | 1 + 8 files changed, 12 insertions(+) create mode 100644 migrations/2021-07-19-130929_add_show_new_post_notifs_setting/down.sql create mode 100644 migrations/2021-07-19-130929_add_show_new_post_notifs_setting/up.sql diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index 47d87d3f6..4b48a0083 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -241,6 +241,7 @@ impl Perform for SaveUserSettings { lang: data.lang.to_owned(), show_avatars: data.show_avatars, show_read_posts: data.show_read_posts, + show_new_post_notifs: data.show_new_post_notifs, send_notifications_to_email: data.send_notifications_to_email, }; diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index 12cc5deeb..77020ab0b 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -63,6 +63,7 @@ pub struct SaveUserSettings { pub bot_account: Option, pub show_bot_accounts: Option, pub show_read_posts: Option, + pub show_new_post_notifs: Option, pub auth: String, } diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index ec227fefa..82788b6da 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -118,6 +118,7 @@ impl PerformCrud for Register { .map_err(|_| ApiError::err("user_already_exists"))?; // Create the local user + // TODO some of these could probably use the DB defaults let local_user_form = LocalUserForm { person_id: inserted_person.id, email: Some(data.email.to_owned()), @@ -131,6 +132,7 @@ impl PerformCrud for Register { show_avatars: Some(true), show_scores: Some(true), show_read_posts: Some(true), + show_new_post_notifs: Some(false), send_notifications_to_email: Some(false), }; diff --git a/crates/db_queries/src/source/local_user.rs b/crates/db_queries/src/source/local_user.rs index abfc4e0be..b711c82aa 100644 --- a/crates/db_queries/src/source/local_user.rs +++ b/crates/db_queries/src/source/local_user.rs @@ -27,6 +27,7 @@ mod safe_settings_type { show_bot_accounts, show_scores, show_read_posts, + show_new_post_notifs, ); impl ToSafeSettings for LocalUser { @@ -49,6 +50,7 @@ mod safe_settings_type { show_bot_accounts, show_scores, show_read_posts, + show_new_post_notifs, ) } } diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 4a52b310d..8c17b0bd5 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -156,6 +156,7 @@ table! { show_bot_accounts -> Bool, show_scores -> Bool, show_read_posts -> Bool, + show_new_post_notifs -> Bool, } } diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index 77e0c0ceb..df83e268f 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -19,6 +19,7 @@ pub struct LocalUser { pub show_bot_accounts: bool, pub show_scores: bool, pub show_read_posts: bool, + pub show_new_post_notifs: bool, } // TODO redo these, check table defaults @@ -38,6 +39,7 @@ pub struct LocalUserForm { pub show_bot_accounts: Option, pub show_scores: Option, pub show_read_posts: Option, + pub show_new_post_notifs: Option, } /// A local user view that removes password encrypted @@ -58,4 +60,5 @@ pub struct LocalUserSettings { pub show_bot_accounts: bool, pub show_scores: bool, pub show_read_posts: bool, + pub show_new_post_notifs: bool, } diff --git a/migrations/2021-07-19-130929_add_show_new_post_notifs_setting/down.sql b/migrations/2021-07-19-130929_add_show_new_post_notifs_setting/down.sql new file mode 100644 index 000000000..197c36ebc --- /dev/null +++ b/migrations/2021-07-19-130929_add_show_new_post_notifs_setting/down.sql @@ -0,0 +1 @@ +alter table local_user drop column show_new_post_notifs; diff --git a/migrations/2021-07-19-130929_add_show_new_post_notifs_setting/up.sql b/migrations/2021-07-19-130929_add_show_new_post_notifs_setting/up.sql new file mode 100644 index 000000000..7c6960b44 --- /dev/null +++ b/migrations/2021-07-19-130929_add_show_new_post_notifs_setting/up.sql @@ -0,0 +1 @@ +alter table local_user add column show_new_post_notifs boolean default false not null;