- .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
-
- let person_id = local_user_view.person.id;
- let community_view =
- CommunityView::read(context.pool(), inserted_community.id, Some(person_id)).await?;
+ .with_lemmy_type(LemmyErrorType::CommunityFollowerAlreadyExists)?;
+
+ // Update the discussion_languages if that's provided
+ let community_id = inserted_community.id;
+ 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
+ // https://stackoverflow.com/a/64227550
+ let is_subset = languages.iter().all(|item| site_languages.contains(item));
+ if !is_subset {
+ return Err(LemmyErrorType::LanguageNotAllowed)?;
+ }
+ CommunityLanguage::update(&mut context.pool(), languages, community_id).await?;
+ }