Add a vote_display_mode local_user setting. (#4450)

* Add a vote_display_mode local_user setting.

- Fixes #4449

* Changing HideDownvotes to Score.

* Adding ScoreAndDownvote display mode.

* Adding upvote and downvote mode.

* Extracting vote_display_mode to another table.

* Fixing fmt.

* Remove published and updated columns.

---------

Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
This commit is contained in:
Dessalines 2024-03-13 12:10:58 -04:00 committed by GitHub
parent 45c56df4e8
commit 15f02f00a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 211 additions and 5 deletions

View File

@ -14,6 +14,7 @@ use lemmy_db_schema::{
source::{ source::{
actor_language::LocalUserLanguage, actor_language::LocalUserLanguage,
local_user::{LocalUser, LocalUserUpdateForm}, local_user::{LocalUser, LocalUserUpdateForm},
local_user_vote_display_mode::{LocalUserVoteDisplayMode, LocalUserVoteDisplayModeUpdateForm},
person::{Person, PersonUpdateForm}, person::{Person, PersonUpdateForm},
}, },
traits::Crud, traits::Crud,
@ -136,5 +137,15 @@ pub async fn save_user_settings(
.await .await
.ok(); .ok();
// Update the vote display modes
let vote_display_modes_form = LocalUserVoteDisplayModeUpdateForm {
score: data.show_scores,
upvotes: data.show_upvotes,
downvotes: data.show_downvotes,
upvote_percentage: data.show_upvote_percentage,
};
LocalUserVoteDisplayMode::update(&mut context.pool(), local_user_id, &vote_display_modes_form)
.await?;
Ok(Json(SuccessResponse::default())) Ok(Json(SuccessResponse::default()))
} }

View File

@ -86,8 +86,6 @@ pub struct SaveUserSettings {
pub show_nsfw: Option<bool>, pub show_nsfw: Option<bool>,
pub blur_nsfw: Option<bool>, pub blur_nsfw: Option<bool>,
pub auto_expand: Option<bool>, pub auto_expand: Option<bool>,
/// Show post and comment scores.
pub show_scores: Option<bool>,
/// Your user's theme. /// Your user's theme.
pub theme: Option<String>, pub theme: Option<String>,
pub default_sort_type: Option<SortType>, pub default_sort_type: Option<SortType>,
@ -122,6 +120,7 @@ pub struct SaveUserSettings {
pub open_links_in_new_tab: Option<bool>, pub open_links_in_new_tab: Option<bool>,
/// Enable infinite scroll /// Enable infinite scroll
pub infinite_scroll_enabled: Option<bool>, pub infinite_scroll_enabled: Option<bool>,
/// A post-view mode that changes how multiple post listings look.
pub post_listing_mode: Option<PostListingMode>, pub post_listing_mode: Option<PostListingMode>,
/// Whether to allow keyboard navigation (for browsing and interacting with posts and comments). /// Whether to allow keyboard navigation (for browsing and interacting with posts and comments).
pub enable_keyboard_navigation: Option<bool>, pub enable_keyboard_navigation: Option<bool>,
@ -129,6 +128,11 @@ pub struct SaveUserSettings {
pub enable_animated_images: Option<bool>, pub enable_animated_images: Option<bool>,
/// Whether to auto-collapse bot comments. /// Whether to auto-collapse bot comments.
pub collapse_bot_comments: Option<bool>, pub collapse_bot_comments: Option<bool>,
/// Some vote display mode settings
pub show_scores: Option<bool>,
pub show_upvotes: Option<bool>,
pub show_downvotes: Option<bool>,
pub show_upvote_percentage: Option<bool>,
} }
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]

View File

@ -21,6 +21,7 @@ use lemmy_db_schema::{
source::{ source::{
captcha_answer::{CaptchaAnswer, CheckCaptchaAnswer}, captcha_answer::{CaptchaAnswer, CheckCaptchaAnswer},
local_user::{LocalUser, LocalUserInsertForm}, local_user::{LocalUser, LocalUserInsertForm},
local_user_vote_display_mode::LocalUserVoteDisplayMode,
person::{Person, PersonInsertForm}, person::{Person, PersonInsertForm},
registration_application::{RegistrationApplication, RegistrationApplicationInsertForm}, registration_application::{RegistrationApplication, RegistrationApplicationInsertForm},
}, },
@ -183,6 +184,7 @@ pub async fn register(
if local_site.require_email_verification { if local_site.require_email_verification {
let local_user_view = LocalUserView { let local_user_view = LocalUserView {
local_user: inserted_local_user, local_user: inserted_local_user,
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
person: inserted_person, person: inserted_person,
counts: PersonAggregates::default(), counts: PersonAggregates::default(),
}; };

View File

@ -17,6 +17,7 @@ use lemmy_db_schema::{
instance::Instance, instance::Instance,
instance_block::{InstanceBlock, InstanceBlockForm}, instance_block::{InstanceBlock, InstanceBlockForm},
local_user::{LocalUser, LocalUserUpdateForm}, local_user::{LocalUser, LocalUserUpdateForm},
local_user_vote_display_mode::{LocalUserVoteDisplayMode, LocalUserVoteDisplayModeUpdateForm},
person::{Person, PersonUpdateForm}, person::{Person, PersonUpdateForm},
person_block::{PersonBlock, PersonBlockForm}, person_block::{PersonBlock, PersonBlockForm},
post::{PostSaved, PostSavedForm}, post::{PostSaved, PostSavedForm},
@ -50,6 +51,7 @@ pub struct UserSettingsBackup {
// TODO: might be worth making a separate struct for settings backup, to avoid breakage in case // TODO: might be worth making a separate struct for settings backup, to avoid breakage in case
// fields are renamed, and to avoid storing unnecessary fields like person_id or email // fields are renamed, and to avoid storing unnecessary fields like person_id or email
pub settings: Option<LocalUser>, pub settings: Option<LocalUser>,
pub vote_display_mode_settings: Option<LocalUserVoteDisplayMode>,
#[serde(default)] #[serde(default)]
pub followed_communities: Vec<ObjectId<ApubCommunity>>, pub followed_communities: Vec<ObjectId<ApubCommunity>>,
#[serde(default)] #[serde(default)]
@ -80,6 +82,7 @@ pub async fn export_settings(
matrix_id: local_user_view.person.matrix_user_id, matrix_id: local_user_view.person.matrix_user_id,
bot_account: local_user_view.person.bot_account.into(), bot_account: local_user_view.person.bot_account.into(),
settings: Some(local_user_view.local_user), settings: Some(local_user_view.local_user),
vote_display_mode_settings: Some(local_user_view.local_user_vote_display_mode),
followed_communities: vec_into(lists.followed_communities), followed_communities: vec_into(lists.followed_communities),
blocked_communities: vec_into(lists.blocked_communities), blocked_communities: vec_into(lists.blocked_communities),
blocked_instances: lists.blocked_instances, blocked_instances: lists.blocked_instances,
@ -132,6 +135,27 @@ pub async fn import_settings(
) )
.await?; .await?;
// Update the vote display mode settings
let vote_display_mode_form = LocalUserVoteDisplayModeUpdateForm {
score: data.vote_display_mode_settings.as_ref().map(|s| s.score),
upvotes: data.vote_display_mode_settings.as_ref().map(|s| s.upvotes),
downvotes: data
.vote_display_mode_settings
.as_ref()
.map(|s| s.downvotes),
upvote_percentage: data
.vote_display_mode_settings
.as_ref()
.map(|s| s.upvote_percentage),
};
LocalUserVoteDisplayMode::update(
&mut context.pool(),
local_user_view.local_user.id,
&vote_display_mode_form,
)
.await?;
let url_count = data.followed_communities.len() let url_count = data.followed_communities.len()
+ data.blocked_communities.len() + data.blocked_communities.len()
+ data.blocked_users.len() + data.blocked_users.len()

View File

@ -4,6 +4,7 @@ use crate::{
source::{ source::{
actor_language::{LocalUserLanguage, SiteLanguage}, actor_language::{LocalUserLanguage, SiteLanguage},
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm}, local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
local_user_vote_display_mode::{LocalUserVoteDisplayMode, LocalUserVoteDisplayModeInsertForm},
}, },
traits::Crud, traits::Crud,
utils::{ utils::{
@ -211,6 +212,12 @@ impl Crud for LocalUser {
LocalUserLanguage::update(pool, vec![], local_user_.id).await?; LocalUserLanguage::update(pool, vec![], local_user_.id).await?;
} }
// Create their vote_display_modes
let vote_display_mode_form = LocalUserVoteDisplayModeInsertForm::builder()
.local_user_id(local_user_.id)
.build();
LocalUserVoteDisplayMode::create(pool, &vote_display_mode_form).await?;
Ok(local_user_) Ok(local_user_)
} }
async fn update( async fn update(

View File

@ -0,0 +1,57 @@
use crate::{
newtypes::LocalUserId,
schema::local_user_vote_display_mode,
source::local_user_vote_display_mode::{
LocalUserVoteDisplayMode,
LocalUserVoteDisplayModeInsertForm,
LocalUserVoteDisplayModeUpdateForm,
},
utils::{get_conn, DbPool},
};
use diesel::{dsl::insert_into, result::Error, QueryDsl};
use diesel_async::RunQueryDsl;
impl LocalUserVoteDisplayMode {
pub async fn read(pool: &mut DbPool<'_>) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
local_user_vote_display_mode::table
.first::<Self>(conn)
.await
}
pub async fn create(
pool: &mut DbPool<'_>,
form: &LocalUserVoteDisplayModeInsertForm,
) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(local_user_vote_display_mode::table)
.values(form)
.get_result::<Self>(conn)
.await
}
pub async fn update(
pool: &mut DbPool<'_>,
local_user_id: LocalUserId,
form: &LocalUserVoteDisplayModeUpdateForm,
) -> Result<(), Error> {
// avoid error "There are no changes to save. This query cannot be built"
if form.is_empty() {
return Ok(());
}
let conn = &mut get_conn(pool).await?;
diesel::update(local_user_vote_display_mode::table.find(local_user_id))
.set(form)
.get_result::<Self>(conn)
.await?;
Ok(())
}
}
impl LocalUserVoteDisplayModeUpdateForm {
fn is_empty(&self) -> bool {
self.score.is_none()
&& self.upvotes.is_none()
&& self.downvotes.is_none()
&& self.upvote_percentage.is_none()
}
}

View File

@ -18,6 +18,7 @@ pub mod language;
pub mod local_site; pub mod local_site;
pub mod local_site_rate_limit; pub mod local_site_rate_limit;
pub mod local_user; pub mod local_user;
pub mod local_user_vote_display_mode;
pub mod login_token; pub mod login_token;
pub mod moderator; pub mod moderator;
pub mod password_reset_request; pub mod password_reset_request;

View File

@ -454,6 +454,16 @@ diesel::table! {
} }
} }
diesel::table! {
local_user_vote_display_mode (local_user_id) {
local_user_id -> Int4,
score -> Bool,
upvotes -> Bool,
downvotes -> Bool,
upvote_percentage -> Bool,
}
}
diesel::table! { diesel::table! {
login_token (token) { login_token (token) {
token -> Text, token -> Text,
@ -961,6 +971,7 @@ diesel::joinable!(local_site_rate_limit -> local_site (local_site_id));
diesel::joinable!(local_user -> person (person_id)); diesel::joinable!(local_user -> person (person_id));
diesel::joinable!(local_user_language -> language (language_id)); diesel::joinable!(local_user_language -> language (language_id));
diesel::joinable!(local_user_language -> local_user (local_user_id)); diesel::joinable!(local_user_language -> local_user (local_user_id));
diesel::joinable!(local_user_vote_display_mode -> local_user (local_user_id));
diesel::joinable!(login_token -> local_user (user_id)); diesel::joinable!(login_token -> local_user (user_id));
diesel::joinable!(mod_add_community -> community (community_id)); diesel::joinable!(mod_add_community -> community (community_id));
diesel::joinable!(mod_ban_from_community -> community (community_id)); diesel::joinable!(mod_ban_from_community -> community (community_id));
@ -1043,6 +1054,7 @@ diesel::allow_tables_to_appear_in_same_query!(
local_site_rate_limit, local_site_rate_limit,
local_user, local_user,
local_user_language, local_user_language,
local_user_vote_display_mode,
login_token, login_token,
mod_add, mod_add,
mod_add_community, mod_add_community,

View File

@ -36,6 +36,7 @@ pub struct LocalUser {
pub show_avatars: bool, pub show_avatars: bool,
pub send_notifications_to_email: bool, pub send_notifications_to_email: bool,
/// Whether to show comment / post scores. /// Whether to show comment / post scores.
// TODO now that there is a vote_display_mode, this can be gotten rid of in future releases.
pub show_scores: bool, pub show_scores: bool,
/// Whether to show bot accounts. /// Whether to show bot accounts.
pub show_bot_accounts: bool, pub show_bot_accounts: bool,
@ -55,6 +56,7 @@ pub struct LocalUser {
pub infinite_scroll_enabled: bool, pub infinite_scroll_enabled: bool,
/// Whether the person is an admin. /// Whether the person is an admin.
pub admin: bool, pub admin: bool,
/// A post-view mode that changes how multiple post listings look.
pub post_listing_mode: PostListingMode, pub post_listing_mode: PostListingMode,
pub totp_2fa_enabled: bool, pub totp_2fa_enabled: bool,
/// Whether to allow keyboard navigation (for browsing and interacting with posts and comments). /// Whether to allow keyboard navigation (for browsing and interacting with posts and comments).

View File

@ -0,0 +1,51 @@
use crate::newtypes::LocalUserId;
#[cfg(feature = "full")]
use crate::schema::local_user_vote_display_mode;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;
use typed_builder::TypedBuilder;
#[skip_serializing_none]
#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable, TS))]
#[cfg_attr(feature = "full", diesel(table_name = local_user_vote_display_mode))]
#[cfg_attr(feature = "full", diesel(primary_key(local_user_id)))]
#[cfg_attr(
feature = "full",
diesel(belongs_to(crate::source::local_site::LocalUser))
)]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "full", ts(export))]
/// The vote display settings for your user.
pub struct LocalUserVoteDisplayMode {
pub local_user_id: LocalUserId,
pub score: bool,
pub upvotes: bool,
pub downvotes: bool,
pub upvote_percentage: bool,
}
#[derive(Clone, TypedBuilder)]
#[builder(field_defaults(default))]
#[cfg_attr(feature = "full", derive(Insertable))]
#[cfg_attr(feature = "full", diesel(table_name = local_user_vote_display_mode))]
pub struct LocalUserVoteDisplayModeInsertForm {
#[builder(!default)]
pub local_user_id: LocalUserId,
pub score: Option<bool>,
pub upvotes: Option<bool>,
pub downvotes: Option<bool>,
pub upvote_percentage: Option<bool>,
}
#[derive(Clone, Default)]
#[cfg_attr(feature = "full", derive(AsChangeset))]
#[cfg_attr(feature = "full", diesel(table_name = local_user_vote_display_mode))]
pub struct LocalUserVoteDisplayModeUpdateForm {
pub score: Option<bool>,
pub upvotes: Option<bool>,
pub downvotes: Option<bool>,
pub upvote_percentage: Option<bool>,
}

View File

@ -23,6 +23,7 @@ pub mod language;
pub mod local_site; pub mod local_site;
pub mod local_site_rate_limit; pub mod local_site_rate_limit;
pub mod local_user; pub mod local_user;
pub mod local_user_vote_display_mode;
pub mod login_token; pub mod login_token;
pub mod moderator; pub mod moderator;
pub mod password_reset_request; pub mod password_reset_request;

View File

@ -223,6 +223,7 @@ mod tests {
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm}, community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
instance::Instance, instance::Instance,
local_user::{LocalUser, LocalUserInsertForm}, local_user::{LocalUser, LocalUserInsertForm},
local_user_vote_display_mode::LocalUserVoteDisplayMode,
person::{Person, PersonInsertForm}, person::{Person, PersonInsertForm},
post::{Post, PostInsertForm}, post::{Post, PostInsertForm},
}, },
@ -258,6 +259,7 @@ mod tests {
let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap(); let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap();
let timmy_view = LocalUserView { let timmy_view = LocalUserView {
local_user: timmy_local_user, local_user: timmy_local_user,
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
person: inserted_timmy.clone(), person: inserted_timmy.clone(),
counts: Default::default(), counts: Default::default(),
}; };

View File

@ -441,6 +441,7 @@ mod tests {
instance::Instance, instance::Instance,
language::Language, language::Language,
local_user::{LocalUser, LocalUserInsertForm}, local_user::{LocalUser, LocalUserInsertForm},
local_user_vote_display_mode::LocalUserVoteDisplayMode,
person::{Person, PersonInsertForm}, person::{Person, PersonInsertForm},
person_block::{PersonBlock, PersonBlockForm}, person_block::{PersonBlock, PersonBlockForm},
post::{Post, PostInsertForm}, post::{Post, PostInsertForm},
@ -614,6 +615,7 @@ mod tests {
let timmy_local_user_view = LocalUserView { let timmy_local_user_view = LocalUserView {
local_user: inserted_timmy_local_user.clone(), local_user: inserted_timmy_local_user.clone(),
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
person: inserted_timmy_person.clone(), person: inserted_timmy_person.clone(),
counts: Default::default(), counts: Default::default(),
}; };

View File

@ -4,7 +4,7 @@ use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl,
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{LocalUserId, PersonId}, newtypes::{LocalUserId, PersonId},
schema::{local_user, person, person_aggregates}, schema::{local_user, local_user_vote_display_mode, person, person_aggregates},
utils::{ utils::{
functions::{coalesce, lower}, functions::{coalesce, lower},
DbConn, DbConn,
@ -33,6 +33,7 @@ fn queries<'a>(
) -> Queries<impl ReadFn<'a, LocalUserView, ReadBy<'a>>, impl ListFn<'a, LocalUserView, ListMode>> { ) -> Queries<impl ReadFn<'a, LocalUserView, ReadBy<'a>>, impl ListFn<'a, LocalUserView, ListMode>> {
let selection = ( let selection = (
local_user::all_columns, local_user::all_columns,
local_user_vote_display_mode::all_columns,
person::all_columns, person::all_columns,
person_aggregates::all_columns, person_aggregates::all_columns,
); );
@ -58,6 +59,7 @@ fn queries<'a>(
_ => query, _ => query,
}; };
query query
.inner_join(local_user_vote_display_mode::table)
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
.select(selection) .select(selection)
.first::<LocalUserView>(&mut conn) .first::<LocalUserView>(&mut conn)
@ -68,10 +70,11 @@ fn queries<'a>(
match mode { match mode {
ListMode::AdminsWithEmails => { ListMode::AdminsWithEmails => {
local_user::table local_user::table
.filter(local_user::email.is_not_null()) .inner_join(local_user_vote_display_mode::table)
.filter(local_user::admin.eq(true))
.inner_join(person::table) .inner_join(person::table)
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
.filter(local_user::email.is_not_null())
.filter(local_user::admin.eq(true))
.select(selection) .select(selection)
.load::<LocalUserView>(&mut conn) .load::<LocalUserView>(&mut conn)
.await .await

View File

@ -206,6 +206,7 @@ mod tests {
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm}, community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
instance::Instance, instance::Instance,
local_user::{LocalUser, LocalUserInsertForm}, local_user::{LocalUser, LocalUserInsertForm},
local_user_vote_display_mode::LocalUserVoteDisplayMode,
person::{Person, PersonInsertForm}, person::{Person, PersonInsertForm},
post::{Post, PostInsertForm}, post::{Post, PostInsertForm},
post_report::{PostReport, PostReportForm}, post_report::{PostReport, PostReportForm},
@ -241,6 +242,7 @@ mod tests {
let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap(); let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap();
let timmy_view = LocalUserView { let timmy_view = LocalUserView {
local_user: timmy_local_user, local_user: timmy_local_user,
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
person: inserted_timmy.clone(), person: inserted_timmy.clone(),
counts: Default::default(), counts: Default::default(),
}; };

View File

@ -749,6 +749,7 @@ mod tests {
instance_block::{InstanceBlock, InstanceBlockForm}, instance_block::{InstanceBlock, InstanceBlockForm},
language::Language, language::Language,
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm}, local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
local_user_vote_display_mode::LocalUserVoteDisplayMode,
person::{Person, PersonInsertForm}, person::{Person, PersonInsertForm},
person_block::{PersonBlock, PersonBlockForm}, person_block::{PersonBlock, PersonBlockForm},
post::{Post, PostHide, PostInsertForm, PostLike, PostLikeForm, PostRead, PostUpdateForm}, post::{Post, PostHide, PostInsertForm, PostLike, PostLikeForm, PostRead, PostUpdateForm},
@ -871,11 +872,13 @@ mod tests {
let inserted_bot_post = Post::create(pool, &new_bot_post).await?; let inserted_bot_post = Post::create(pool, &new_bot_post).await?;
let local_user_view = LocalUserView { let local_user_view = LocalUserView {
local_user: inserted_local_user, local_user: inserted_local_user,
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
person: inserted_person, person: inserted_person,
counts: Default::default(), counts: Default::default(),
}; };
let blocked_local_user_view = LocalUserView { let blocked_local_user_view = LocalUserView {
local_user: inserted_blocked_local_user, local_user: inserted_blocked_local_user,
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
person: inserted_blocked_person, person: inserted_blocked_person,
counts: Default::default(), counts: Default::default(),
}; };

View File

@ -11,6 +11,7 @@ use lemmy_db_schema::{
local_site::LocalSite, local_site::LocalSite,
local_site_rate_limit::LocalSiteRateLimit, local_site_rate_limit::LocalSiteRateLimit,
local_user::LocalUser, local_user::LocalUser,
local_user_vote_display_mode::LocalUserVoteDisplayMode,
person::Person, person::Person,
post::Post, post::Post,
post_report::PostReport, post_report::PostReport,
@ -73,6 +74,7 @@ pub struct CommentView {
/// A local user view. /// A local user view.
pub struct LocalUserView { pub struct LocalUserView {
pub local_user: LocalUser, pub local_user: LocalUser,
pub local_user_vote_display_mode: LocalUserVoteDisplayMode,
pub person: Person, pub person: Person,
pub counts: PersonAggregates, pub counts: PersonAggregates,
} }

View File

@ -0,0 +1,2 @@
DROP TABLE local_user_vote_display_mode;

View File

@ -0,0 +1,18 @@
-- Create an extra table to hold local user vote display settings
-- Score and Upvote percentage are turned on by default.
CREATE TABLE local_user_vote_display_mode (
local_user_id int REFERENCES local_user ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
score boolean DEFAULT TRUE NOT NULL,
upvotes boolean DEFAULT FALSE NOT NULL,
downvotes boolean DEFAULT FALSE NOT NULL,
upvote_percentage boolean DEFAULT TRUE NOT NULL,
PRIMARY KEY (local_user_id)
);
-- Insert rows for every local user
INSERT INTO local_user_vote_display_mode (local_user_id)
SELECT
id
FROM
local_user;