mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-03-29 14:45:27 +00:00
When creating community copy allowed languages from creator profile (#5490)
This commit is contained in:
parent
bb82e5dd43
commit
b6f46cd38c
1 changed files with 16 additions and 8 deletions
|
@ -17,7 +17,7 @@ use lemmy_api_common::{
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
actor_language::{CommunityLanguage, SiteLanguage},
|
actor_language::{CommunityLanguage, LocalUserLanguage, SiteLanguage},
|
||||||
community::{
|
community::{
|
||||||
Community,
|
Community,
|
||||||
CommunityFollower,
|
CommunityFollower,
|
||||||
|
@ -112,10 +112,11 @@ pub async fn create_community(
|
||||||
let inserted_community = Community::create(&mut context.pool(), &community_form)
|
let inserted_community = Community::create(&mut context.pool(), &community_form)
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CommunityAlreadyExists)?;
|
.with_lemmy_type(LemmyErrorType::CommunityAlreadyExists)?;
|
||||||
|
let community_id = inserted_community.id;
|
||||||
|
|
||||||
// The community creator becomes a moderator
|
// The community creator becomes a moderator
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: inserted_community.id,
|
community_id,
|
||||||
person_id: local_user_view.person.id,
|
person_id: local_user_view.person.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -125,7 +126,7 @@ pub async fn create_community(
|
||||||
|
|
||||||
// Follow your own community
|
// Follow your own community
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: inserted_community.id,
|
community_id,
|
||||||
person_id: local_user_view.person.id,
|
person_id: local_user_view.person.id,
|
||||||
state: Some(CommunityFollowerState::Accepted),
|
state: Some(CommunityFollowerState::Accepted),
|
||||||
approver_id: None,
|
approver_id: None,
|
||||||
|
@ -136,17 +137,24 @@ pub async fn create_community(
|
||||||
.with_lemmy_type(LemmyErrorType::CommunityFollowerAlreadyExists)?;
|
.with_lemmy_type(LemmyErrorType::CommunityFollowerAlreadyExists)?;
|
||||||
|
|
||||||
// Update the discussion_languages if that's provided
|
// Update the discussion_languages if that's provided
|
||||||
let community_id = inserted_community.id;
|
let site_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
|
||||||
if let Some(languages) = data.discussion_languages.clone() {
|
let languages = if let Some(languages) = data.discussion_languages.clone() {
|
||||||
let site_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
|
|
||||||
// check that community languages are a subset of site languages
|
// check that community languages are a subset of site languages
|
||||||
// https://stackoverflow.com/a/64227550
|
// https://stackoverflow.com/a/64227550
|
||||||
let is_subset = languages.iter().all(|item| site_languages.contains(item));
|
let is_subset = languages.iter().all(|item| site_languages.contains(item));
|
||||||
if !is_subset {
|
if !is_subset {
|
||||||
Err(LemmyErrorType::LanguageNotAllowed)?
|
Err(LemmyErrorType::LanguageNotAllowed)?
|
||||||
}
|
}
|
||||||
CommunityLanguage::update(&mut context.pool(), languages, community_id).await?;
|
languages
|
||||||
}
|
} else {
|
||||||
|
// Copy languages from creator
|
||||||
|
LocalUserLanguage::read(&mut context.pool(), local_user_view.local_user.id)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.filter(|l| site_languages.contains(l))
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
CommunityLanguage::update(&mut context.pool(), languages, community_id).await?;
|
||||||
|
|
||||||
build_community_response(&context, local_user_view, community_id).await
|
build_community_response(&context, local_user_view, community_id).await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue