fix compilation, move user languages to separate table

feature/language-tags
Felix Ableitner 2021-04-22 14:38:04 +02:00
parent 12c632d2dd
commit fb8c05d6ba
10 changed files with 42 additions and 16 deletions

View File

@ -1,3 +1,10 @@
use lemmy_db_schema::{
CommunityId,
PersonId,
PersonMentionId,
PrimaryLanguageTag,
PrivateMessageId,
};
use lemmy_db_views::{ use lemmy_db_views::{
comment_view::CommentView, comment_view::CommentView,
post_view::PostView, post_view::PostView,
@ -16,7 +23,6 @@ pub struct Login {
pub username_or_email: String, pub username_or_email: String,
pub password: String, pub password: String,
} }
use lemmy_db_schema::{CommunityId, DbLanguage, PersonId, PersonMentionId, PrivateMessageId};
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Register { pub struct Register {
@ -27,7 +33,7 @@ pub struct Register {
pub show_nsfw: bool, pub show_nsfw: bool,
pub captcha_uuid: Option<String>, pub captcha_uuid: Option<String>,
pub captcha_answer: Option<String>, pub captcha_answer: Option<String>,
pub discussion_languages: Vec<DbLanguage>, pub discussion_languages: Vec<PrimaryLanguageTag>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -62,7 +68,7 @@ pub struct SaveUserSettings {
pub show_avatars: Option<bool>, pub show_avatars: Option<bool>,
pub send_notifications_to_email: Option<bool>, pub send_notifications_to_email: Option<bool>,
pub auth: String, pub auth: String,
pub discussion_languages: Option<Vec<DbLanguage>>, pub discussion_languages: Option<Vec<PrimaryLanguageTag>>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View File

@ -1,6 +1,6 @@
use activitystreams::unparsed::UnparsedMutExt; use activitystreams::unparsed::UnparsedMutExt;
use activitystreams_ext::UnparsedExtension; use activitystreams_ext::UnparsedExtension;
use lemmy_db_schema::DbLanguage; use lemmy_db_schema::PrimaryLanguageTag;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -10,11 +10,11 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct NoteExtension { pub struct NoteExtension {
pub language: Option<DbLanguage>, pub language: Option<PrimaryLanguageTag>,
} }
impl NoteExtension { impl NoteExtension {
pub fn new(language: DbLanguage) -> Result<NoteExtension, LemmyError> { pub fn new(language: PrimaryLanguageTag) -> Result<NoteExtension, LemmyError> {
Ok(NoteExtension { Ok(NoteExtension {
language: Some(language), language: Some(language),
}) })

View File

@ -1,6 +1,6 @@
use activitystreams::unparsed::UnparsedMutExt; use activitystreams::unparsed::UnparsedMutExt;
use activitystreams_ext::UnparsedExtension; use activitystreams_ext::UnparsedExtension;
use lemmy_db_schema::DbLanguage; use lemmy_db_schema::PrimaryLanguageTag;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -13,7 +13,7 @@ pub struct PageExtension {
pub comments_enabled: Option<bool>, pub comments_enabled: Option<bool>,
pub sensitive: Option<bool>, pub sensitive: Option<bool>,
pub stickied: Option<bool>, pub stickied: Option<bool>,
pub language: Option<DbLanguage>, pub language: Option<PrimaryLanguageTag>,
} }
impl PageExtension { impl PageExtension {
@ -21,7 +21,7 @@ impl PageExtension {
comments_enabled: bool, comments_enabled: bool,
sensitive: bool, sensitive: bool,
stickied: bool, stickied: bool,
language: DbLanguage, language: PrimaryLanguageTag,
) -> Result<PageExtension, LemmyError> { ) -> Result<PageExtension, LemmyError> {
Ok(PageExtension { Ok(PageExtension {
comments_enabled: Some(comments_enabled), comments_enabled: Some(comments_enabled),

View File

@ -123,8 +123,7 @@ pub fn naive_now() -> NaiveDateTime {
} }
#[repr(transparent)] #[repr(transparent)]
#[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, Queryable)] #[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
#[sql_type = "Text"]
pub struct PrimaryLanguageTag(String); pub struct PrimaryLanguageTag(String);
impl TryFrom<LanguageTag> for PrimaryLanguageTag { impl TryFrom<LanguageTag> for PrimaryLanguageTag {

View File

@ -519,6 +519,14 @@ table! {
} }
} }
table! {
user_languages (id) {
id -> Int4,
local_user_id -> Int4,
language -> Text,
}
}
joinable!(comment_alias_1 -> person_alias_1 (creator_id)); joinable!(comment_alias_1 -> person_alias_1 (creator_id));
joinable!(comment -> comment_alias_1 (parent_id)); joinable!(comment -> comment_alias_1 (parent_id));
joinable!(person_mention -> person_alias_1 (recipient_id)); joinable!(person_mention -> person_alias_1 (recipient_id));
@ -574,6 +582,7 @@ joinable!(post_saved -> person (person_id));
joinable!(post_saved -> post (post_id)); joinable!(post_saved -> post (post_id));
joinable!(site -> person (creator_id)); joinable!(site -> person (creator_id));
joinable!(site_aggregates -> site (site_id)); joinable!(site_aggregates -> site (site_id));
joinable!(user_languages -> local_user (local_user_id));
allow_tables_to_appear_in_same_query!( allow_tables_to_appear_in_same_query!(
activity, activity,
@ -587,6 +596,7 @@ allow_tables_to_appear_in_same_query!(
community_follower, community_follower,
community_moderator, community_moderator,
community_person_ban, community_person_ban,
user_languages,
local_user, local_user,
mod_add, mod_add,
mod_add_community, mod_add_community,

View File

@ -0,0 +1,10 @@
use crate::{schema::user_languages, LocalUserId, PrimaryLanguageTag};
use serde::Serialize;
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "user_languages"]
pub struct UserLanguages {
pub id: i32,
pub local_user_id: LocalUserId,
pub language: PrimaryLanguageTag,
}

View File

@ -2,6 +2,7 @@ pub mod activity;
pub mod comment; pub mod comment;
pub mod comment_report; pub mod comment_report;
pub mod community; pub mod community;
pub mod languages;
pub mod local_user; pub mod local_user;
pub mod moderator; pub mod moderator;
pub mod password_reset_request; pub mod password_reset_request;

View File

@ -28,9 +28,9 @@ use lemmy_db_schema::{
post::{Post, PostRead, PostSaved}, post::{Post, PostRead, PostSaved},
}, },
CommunityId, CommunityId,
DbLanguage,
PersonId, PersonId,
PostId, PostId,
PrimaryLanguageTag,
}; };
use log::debug; use log::debug;
use serde::Serialize; use serde::Serialize;
@ -169,7 +169,7 @@ pub struct PostQueryBuilder<'a> {
unread_only: bool, unread_only: bool,
page: Option<i64>, page: Option<i64>,
limit: Option<i64>, limit: Option<i64>,
languages: Option<Vec<DbLanguage>>, languages: Option<Vec<PrimaryLanguageTag>>,
} }
impl<'a> PostQueryBuilder<'a> { impl<'a> PostQueryBuilder<'a> {
@ -253,7 +253,7 @@ impl<'a> PostQueryBuilder<'a> {
self self
} }
pub fn languages<T: MaybeOptional<Vec<DbLanguage>>>(mut self, languages: T) -> Self { pub fn languages<T: MaybeOptional<Vec<PrimaryLanguageTag>>>(mut self, languages: T) -> Self {
self.languages = languages.get_optional(); self.languages = languages.get_optional();
self self
} }

View File

@ -2,5 +2,5 @@ ALTER TABLE comment DROP COLUMN language;
ALTER TABLE post DROP COLUMN language; ALTER TABLE post DROP COLUMN language;
ALTER TABLE private_message DROP COLUMN language; ALTER TABLE private_message DROP COLUMN language;
ALTER TABLE local_user DROP COLUMN discussion_languages; DROP TABLE discussion_languages;
ALTER TABLE local_user RENAME COLUMN interface_language TO lang; ALTER TABLE local_user RENAME COLUMN interface_language TO lang;

View File

@ -2,5 +2,5 @@ ALTER TABLE comment ADD COLUMN language TEXT NOT NULL;
ALTER TABLE post ADD COLUMN language TEXT NOT NULL; ALTER TABLE post ADD COLUMN language TEXT NOT NULL;
ALTER TABLE private_message ADD COLUMN language TEXT NOT NULL; ALTER TABLE private_message ADD COLUMN language TEXT NOT NULL;
ALTER TABLE local_user ADD COLUMN discussion_languages TEXT[] NOT NULL; CREATE TABLE discussion_languages(id INTEGER PRIMARY KEY, local_user_id INT NOT NULL, language TEXT NOT NULL);
ALTER TABLE local_user RENAME COLUMN lang TO interface_language; ALTER TABLE local_user RENAME COLUMN lang TO interface_language;