mirror of https://github.com/LemmyNet/lemmy.git
fix compilation, move user languages to separate table
parent
12c632d2dd
commit
fb8c05d6ba
|
@ -1,3 +1,10 @@
|
|||
use lemmy_db_schema::{
|
||||
CommunityId,
|
||||
PersonId,
|
||||
PersonMentionId,
|
||||
PrimaryLanguageTag,
|
||||
PrivateMessageId,
|
||||
};
|
||||
use lemmy_db_views::{
|
||||
comment_view::CommentView,
|
||||
post_view::PostView,
|
||||
|
@ -16,7 +23,6 @@ pub struct Login {
|
|||
pub username_or_email: String,
|
||||
pub password: String,
|
||||
}
|
||||
use lemmy_db_schema::{CommunityId, DbLanguage, PersonId, PersonMentionId, PrivateMessageId};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Register {
|
||||
|
@ -27,7 +33,7 @@ pub struct Register {
|
|||
pub show_nsfw: bool,
|
||||
pub captcha_uuid: Option<String>,
|
||||
pub captcha_answer: Option<String>,
|
||||
pub discussion_languages: Vec<DbLanguage>,
|
||||
pub discussion_languages: Vec<PrimaryLanguageTag>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -62,7 +68,7 @@ pub struct SaveUserSettings {
|
|||
pub show_avatars: Option<bool>,
|
||||
pub send_notifications_to_email: Option<bool>,
|
||||
pub auth: String,
|
||||
pub discussion_languages: Option<Vec<DbLanguage>>,
|
||||
pub discussion_languages: Option<Vec<PrimaryLanguageTag>>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use activitystreams::unparsed::UnparsedMutExt;
|
||||
use activitystreams_ext::UnparsedExtension;
|
||||
use lemmy_db_schema::DbLanguage;
|
||||
use lemmy_db_schema::PrimaryLanguageTag;
|
||||
use lemmy_utils::LemmyError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -10,11 +10,11 @@ use serde::{Deserialize, Serialize};
|
|||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NoteExtension {
|
||||
pub language: Option<DbLanguage>,
|
||||
pub language: Option<PrimaryLanguageTag>,
|
||||
}
|
||||
|
||||
impl NoteExtension {
|
||||
pub fn new(language: DbLanguage) -> Result<NoteExtension, LemmyError> {
|
||||
pub fn new(language: PrimaryLanguageTag) -> Result<NoteExtension, LemmyError> {
|
||||
Ok(NoteExtension {
|
||||
language: Some(language),
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use activitystreams::unparsed::UnparsedMutExt;
|
||||
use activitystreams_ext::UnparsedExtension;
|
||||
use lemmy_db_schema::DbLanguage;
|
||||
use lemmy_db_schema::PrimaryLanguageTag;
|
||||
use lemmy_utils::LemmyError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -13,7 +13,7 @@ pub struct PageExtension {
|
|||
pub comments_enabled: Option<bool>,
|
||||
pub sensitive: Option<bool>,
|
||||
pub stickied: Option<bool>,
|
||||
pub language: Option<DbLanguage>,
|
||||
pub language: Option<PrimaryLanguageTag>,
|
||||
}
|
||||
|
||||
impl PageExtension {
|
||||
|
@ -21,7 +21,7 @@ impl PageExtension {
|
|||
comments_enabled: bool,
|
||||
sensitive: bool,
|
||||
stickied: bool,
|
||||
language: DbLanguage,
|
||||
language: PrimaryLanguageTag,
|
||||
) -> Result<PageExtension, LemmyError> {
|
||||
Ok(PageExtension {
|
||||
comments_enabled: Some(comments_enabled),
|
||||
|
|
|
@ -123,8 +123,7 @@ pub fn naive_now() -> NaiveDateTime {
|
|||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, Queryable)]
|
||||
#[sql_type = "Text"]
|
||||
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
|
||||
pub struct PrimaryLanguageTag(String);
|
||||
|
||||
impl TryFrom<LanguageTag> for PrimaryLanguageTag {
|
||||
|
|
|
@ -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 -> comment_alias_1 (parent_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!(site -> person (creator_id));
|
||||
joinable!(site_aggregates -> site (site_id));
|
||||
joinable!(user_languages -> local_user (local_user_id));
|
||||
|
||||
allow_tables_to_appear_in_same_query!(
|
||||
activity,
|
||||
|
@ -587,6 +596,7 @@ allow_tables_to_appear_in_same_query!(
|
|||
community_follower,
|
||||
community_moderator,
|
||||
community_person_ban,
|
||||
user_languages,
|
||||
local_user,
|
||||
mod_add,
|
||||
mod_add_community,
|
||||
|
|
|
@ -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,
|
||||
}
|
|
@ -2,6 +2,7 @@ pub mod activity;
|
|||
pub mod comment;
|
||||
pub mod comment_report;
|
||||
pub mod community;
|
||||
pub mod languages;
|
||||
pub mod local_user;
|
||||
pub mod moderator;
|
||||
pub mod password_reset_request;
|
||||
|
|
|
@ -28,9 +28,9 @@ use lemmy_db_schema::{
|
|||
post::{Post, PostRead, PostSaved},
|
||||
},
|
||||
CommunityId,
|
||||
DbLanguage,
|
||||
PersonId,
|
||||
PostId,
|
||||
PrimaryLanguageTag,
|
||||
};
|
||||
use log::debug;
|
||||
use serde::Serialize;
|
||||
|
@ -169,7 +169,7 @@ pub struct PostQueryBuilder<'a> {
|
|||
unread_only: bool,
|
||||
page: Option<i64>,
|
||||
limit: Option<i64>,
|
||||
languages: Option<Vec<DbLanguage>>,
|
||||
languages: Option<Vec<PrimaryLanguageTag>>,
|
||||
}
|
||||
|
||||
impl<'a> PostQueryBuilder<'a> {
|
||||
|
@ -253,7 +253,7 @@ impl<'a> PostQueryBuilder<'a> {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@ ALTER TABLE comment DROP COLUMN language;
|
|||
ALTER TABLE post 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;
|
||||
|
|
|
@ -2,5 +2,5 @@ ALTER TABLE comment 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 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;
|
||||
|
|
Loading…
Reference in New Issue