- // if no language is set, copy language from parent post/comment
- let parent_language = parent_opt
- .as_ref()
- .map(|p| p.language_id)
- .unwrap_or(post.language_id);
- let language_id = Some(data.language_id.unwrap_or(parent_language));
-
- let comment_form = CommentForm {
- content: content_slurs_removed,
- post_id: data.post_id,
- creator_id: local_user_view.person.id,
- language_id,
- ..CommentForm::default()
+ CommunityLanguage::is_allowed_community_language(
+ &mut context.pool(),
+ data.language_id,
+ community_id,
+ )
+ .await?;
+
+ // attempt to set default language if none was provided
+ let language_id = match data.language_id {
+ Some(lid) => Some(lid),
+ None => {
+ default_post_language(
+ &mut context.pool(),
+ community_id,
+ local_user_view.local_user.id,
+ )
+ .await?
+ }