mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-05 01:32:23 +00:00
add code for local_user_discussion_language_view
This commit is contained in:
parent
87f77e7030
commit
624f4dfbab
17 changed files with 82 additions and 39 deletions
|
@ -152,7 +152,6 @@ impl Perform for SaveUserSettings {
|
||||||
send_notifications_to_email: data.send_notifications_to_email,
|
send_notifications_to_email: data.send_notifications_to_email,
|
||||||
email_verified: None,
|
email_verified: None,
|
||||||
accepted_application: None,
|
accepted_application: None,
|
||||||
discussion_languages,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let local_user_res = blocking(context.pool(), move |conn| {
|
let local_user_res = blocking(context.pool(), move |conn| {
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub struct Login {
|
||||||
pub password: Sensitive<String>,
|
pub password: Sensitive<String>,
|
||||||
}
|
}
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId, PersonMentionId, PrivateMessageId},
|
newtypes::{CommunityId, LanguageId, PersonId, PersonMentionId, PrivateMessageId},
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ pub struct SaveUserSettings {
|
||||||
pub show_bot_accounts: Option<bool>,
|
pub show_bot_accounts: Option<bool>,
|
||||||
pub show_read_posts: Option<bool>,
|
pub show_read_posts: Option<bool>,
|
||||||
pub show_new_post_notifs: Option<bool>,
|
pub show_new_post_notifs: Option<bool>,
|
||||||
pub discussion_languages: Option<Vec<String>>,
|
pub discussion_languages: Option<Vec<LanguageId>>,
|
||||||
pub auth: Sensitive<String>,
|
pub auth: Sensitive<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,7 @@ pub struct MyUserInfo {
|
||||||
pub moderates: Vec<CommunityModeratorView>,
|
pub moderates: Vec<CommunityModeratorView>,
|
||||||
pub community_blocks: Vec<CommunityBlockView>,
|
pub community_blocks: Vec<CommunityBlockView>,
|
||||||
pub person_blocks: Vec<PersonBlockView>,
|
pub person_blocks: Vec<PersonBlockView>,
|
||||||
|
pub discussion_languages: Vec<Language>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
|
|
@ -33,7 +33,6 @@ mod safe_settings_type {
|
||||||
show_new_post_notifs,
|
show_new_post_notifs,
|
||||||
email_verified,
|
email_verified,
|
||||||
accepted_application,
|
accepted_application,
|
||||||
discussion_languages,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
impl ToSafeSettings for LocalUser {
|
impl ToSafeSettings for LocalUser {
|
||||||
|
@ -59,7 +58,6 @@ mod safe_settings_type {
|
||||||
show_new_post_notifs,
|
show_new_post_notifs,
|
||||||
email_verified,
|
email_verified,
|
||||||
accepted_application,
|
accepted_application,
|
||||||
discussion_languages,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,6 @@ table! {
|
||||||
show_new_post_notifs -> Bool,
|
show_new_post_notifs -> Bool,
|
||||||
email_verified -> Bool,
|
email_verified -> Bool,
|
||||||
accepted_application -> Bool,
|
accepted_application -> Bool,
|
||||||
discussion_languages -> Array<Int4>,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
|
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
|
||||||
|
language::Language,
|
||||||
person::{Person, PersonSafe},
|
person::{Person, PersonSafe},
|
||||||
person_block::PersonBlock,
|
person_block::PersonBlock,
|
||||||
post::{Post, PostRead, PostSaved},
|
post::{Post, PostRead, PostSaved},
|
||||||
|
@ -46,6 +47,7 @@ type PostViewTuple = (
|
||||||
Option<PostRead>,
|
Option<PostRead>,
|
||||||
Option<PersonBlock>,
|
Option<PersonBlock>,
|
||||||
Option<i16>,
|
Option<i16>,
|
||||||
|
Language,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl PostView {
|
impl PostView {
|
||||||
|
@ -257,10 +259,7 @@ impl<'a> PostQueryBuilder<'a> {
|
||||||
self.show_nsfw = Some(user.local_user.show_nsfw);
|
self.show_nsfw = Some(user.local_user.show_nsfw);
|
||||||
self.show_bot_accounts = Some(user.local_user.show_bot_accounts);
|
self.show_bot_accounts = Some(user.local_user.show_bot_accounts);
|
||||||
self.show_read_posts = Some(user.local_user.show_read_posts);
|
self.show_read_posts = Some(user.local_user.show_read_posts);
|
||||||
// if user has no languages set, then dont filter by language
|
//TODO: add local user discussion languages (need to store them in LocalUserView?)
|
||||||
if !user.local_user.discussion_languages.is_empty() {
|
|
||||||
self.languages = Some(user.local_user.discussion_languages.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,10 @@ impl ViewToVec for CommunityBlockView {
|
||||||
type DbTuple = CommunityBlockViewTuple;
|
type DbTuple = CommunityBlockViewTuple;
|
||||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||||
items
|
items
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|a| Self {
|
.map(|a| Self {
|
||||||
person: a.0.to_owned(),
|
person: a.0,
|
||||||
community: a.1.to_owned(),
|
community: a.1,
|
||||||
})
|
})
|
||||||
.collect::<Vec<Self>>()
|
.collect::<Vec<Self>>()
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ impl ViewToVec for CommunityFollowerView {
|
||||||
type DbTuple = CommunityFollowerViewTuple;
|
type DbTuple = CommunityFollowerViewTuple;
|
||||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||||
items
|
items
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|a| Self {
|
.map(|a| Self {
|
||||||
community: a.0.to_owned(),
|
community: a.0,
|
||||||
follower: a.1.to_owned(),
|
follower: a.1,
|
||||||
})
|
})
|
||||||
.collect::<Vec<Self>>()
|
.collect::<Vec<Self>>()
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,10 +70,10 @@ impl ViewToVec for CommunityModeratorView {
|
||||||
type DbTuple = CommunityModeratorViewTuple;
|
type DbTuple = CommunityModeratorViewTuple;
|
||||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||||
items
|
items
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|a| Self {
|
.map(|a| Self {
|
||||||
community: a.0.to_owned(),
|
community: a.0,
|
||||||
moderator: a.1.to_owned(),
|
moderator: a.1,
|
||||||
})
|
})
|
||||||
.collect::<Vec<Self>>()
|
.collect::<Vec<Self>>()
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,10 +258,10 @@ impl ViewToVec for CommunityView {
|
||||||
type DbTuple = CommunityViewTuple;
|
type DbTuple = CommunityViewTuple;
|
||||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||||
items
|
items
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|a| Self {
|
.map(|a| Self {
|
||||||
community: a.0.to_owned(),
|
community: a.0,
|
||||||
counts: a.1.to_owned(),
|
counts: a.1,
|
||||||
subscribed: CommunityFollower::to_subscribed_type(&a.2),
|
subscribed: CommunityFollower::to_subscribed_type(&a.2),
|
||||||
blocked: a.3.is_some(),
|
blocked: a.3.is_some(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,6 +9,8 @@ pub mod community_person_ban_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod community_view;
|
pub mod community_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
pub mod local_user_discusion_language_view;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
pub mod person_block_view;
|
pub mod person_block_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod person_mention_view;
|
pub mod person_mention_view;
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
use crate::structs::LocalUserDiscussionLanguageView;
|
||||||
|
use diesel::{result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
newtypes::LocalUserId,
|
||||||
|
schema::{language, local_user, local_user_language},
|
||||||
|
source::{
|
||||||
|
language::Language,
|
||||||
|
local_user::{LocalUser, LocalUserSettings},
|
||||||
|
},
|
||||||
|
traits::ToSafeSettings,
|
||||||
|
};
|
||||||
|
|
||||||
|
type LocalUserDiscussionLanguageViewTuple = (LocalUserSettings, Language);
|
||||||
|
|
||||||
|
impl LocalUserDiscussionLanguageView {
|
||||||
|
pub fn read(conn: &PgConnection, local_user_id: LocalUserId) -> Result<Vec<Self>, Error> {
|
||||||
|
let res = local_user_language::table
|
||||||
|
.inner_join(local_user::table)
|
||||||
|
.inner_join(language::table)
|
||||||
|
.select((
|
||||||
|
LocalUser::safe_settings_columns_tuple(),
|
||||||
|
language::all_columns,
|
||||||
|
))
|
||||||
|
.filter(local_user::id.eq(local_user_id))
|
||||||
|
.load::<LocalUserDiscussionLanguageViewTuple>(conn)?;
|
||||||
|
|
||||||
|
Ok(
|
||||||
|
res
|
||||||
|
.into_iter()
|
||||||
|
.map(|a| Self {
|
||||||
|
local_user: a.0,
|
||||||
|
language: a.1,
|
||||||
|
})
|
||||||
|
.collect::<Vec<Self>>(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,10 +30,10 @@ impl ViewToVec for PersonBlockView {
|
||||||
type DbTuple = PersonBlockViewTuple;
|
type DbTuple = PersonBlockViewTuple;
|
||||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||||
items
|
items
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|a| Self {
|
.map(|a| Self {
|
||||||
person: a.0.to_owned(),
|
person: a.0,
|
||||||
target: a.1.to_owned(),
|
target: a.1,
|
||||||
})
|
})
|
||||||
.collect::<Vec<Self>>()
|
.collect::<Vec<Self>>()
|
||||||
}
|
}
|
||||||
|
|
|
@ -326,15 +326,15 @@ impl ViewToVec for PersonMentionView {
|
||||||
type DbTuple = PersonMentionViewTuple;
|
type DbTuple = PersonMentionViewTuple;
|
||||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||||
items
|
items
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|a| Self {
|
.map(|a| Self {
|
||||||
person_mention: a.0.to_owned(),
|
person_mention: a.0,
|
||||||
comment: a.1.to_owned(),
|
comment: a.1,
|
||||||
creator: a.2.to_owned(),
|
creator: a.2,
|
||||||
post: a.3.to_owned(),
|
post: a.3,
|
||||||
community: a.4.to_owned(),
|
community: a.4,
|
||||||
recipient: a.5.to_owned(),
|
recipient: a.5,
|
||||||
counts: a.6.to_owned(),
|
counts: a.6,
|
||||||
creator_banned_from_community: a.7.is_some(),
|
creator_banned_from_community: a.7.is_some(),
|
||||||
subscribed: CommunityFollower::to_subscribed_type(&a.8),
|
subscribed: CommunityFollower::to_subscribed_type(&a.8),
|
||||||
saved: a.9.is_some(),
|
saved: a.9.is_some(),
|
||||||
|
|
|
@ -137,10 +137,10 @@ impl ViewToVec for PersonViewSafe {
|
||||||
type DbTuple = PersonViewSafeTuple;
|
type DbTuple = PersonViewSafeTuple;
|
||||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||||
items
|
items
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|a| Self {
|
.map(|a| Self {
|
||||||
person: a.0.to_owned(),
|
person: a.0,
|
||||||
counts: a.1.to_owned(),
|
counts: a.1,
|
||||||
})
|
})
|
||||||
.collect::<Vec<Self>>()
|
.collect::<Vec<Self>>()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
community::CommunitySafe,
|
community::CommunitySafe,
|
||||||
|
language::Language,
|
||||||
|
local_user::LocalUserSettings,
|
||||||
person::{PersonSafe, PersonSafeAlias1},
|
person::{PersonSafe, PersonSafeAlias1},
|
||||||
person_mention::PersonMention,
|
person_mention::PersonMention,
|
||||||
post::Post,
|
post::Post,
|
||||||
|
@ -70,3 +72,9 @@ pub struct PersonViewSafe {
|
||||||
pub person: PersonSafe,
|
pub person: PersonSafe,
|
||||||
pub counts: PersonAggregates,
|
pub counts: PersonAggregates,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct LocalUserDiscussionLanguageView {
|
||||||
|
pub local_user: LocalUserSettings,
|
||||||
|
pub language: Language,
|
||||||
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ impl ViewToVec for AdminPurgeCommunityView {
|
||||||
type DbTuple = AdminPurgeCommunityViewTuple;
|
type DbTuple = AdminPurgeCommunityViewTuple;
|
||||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||||
items
|
items
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|a| Self {
|
.map(|a| Self {
|
||||||
admin_purge_community: a.0.to_owned(),
|
admin_purge_community: a.0,
|
||||||
admin: a.1.to_owned(),
|
admin: a.1,
|
||||||
})
|
})
|
||||||
.collect::<Vec<Self>>()
|
.collect::<Vec<Self>>()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue