diff --git a/Cargo.lock b/Cargo.lock index 7986a471e..56cfc21ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1751,6 +1751,7 @@ dependencies = [ "http", "http-signature-normalization-actix", "itertools", + "language-tags 0.3.0", "lazy_static", "lemmy_api_common", "lemmy_apub", diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index 1aaa0528e..552b4ca25 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -48,3 +48,4 @@ anyhow = "1.0.38" thiserror = "1.0.23" background-jobs = "0.8.0" reqwest = { version = "0.10.10", features = ["json"] } +language-tags = "0.3.0" diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 0ba3fbea2..e804463af 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -185,6 +185,7 @@ mod tests { person::{Person, PersonForm}, }; use lemmy_utils::claims::Claims; + use language_tags::LanguageTag; #[test] fn test_should_not_validate_user_token_after_password_change() { @@ -200,6 +201,7 @@ mod tests { let local_user_form = LocalUserForm { person_id: inserted_person.id, password_encrypted: "123456".to_string(), + discussion_languages: Some(vec![LanguageTag::parse("en").unwrap().into()]), ..LocalUserForm::default() }; diff --git a/crates/db_queries/src/aggregates/comment_aggregates.rs b/crates/db_queries/src/aggregates/comment_aggregates.rs index 898c57da3..acef56cb5 100644 --- a/crates/db_queries/src/aggregates/comment_aggregates.rs +++ b/crates/db_queries/src/aggregates/comment_aggregates.rs @@ -36,6 +36,7 @@ mod tests { post::{Post, PostForm}, }; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -68,6 +69,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -77,6 +79,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; @@ -87,6 +90,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; diff --git a/crates/db_queries/src/aggregates/community_aggregates.rs b/crates/db_queries/src/aggregates/community_aggregates.rs index c668c15ac..6cc1ec41d 100644 --- a/crates/db_queries/src/aggregates/community_aggregates.rs +++ b/crates/db_queries/src/aggregates/community_aggregates.rs @@ -40,6 +40,7 @@ mod tests { post::{Post, PostForm}, }; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -104,6 +105,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -113,6 +115,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; @@ -123,6 +126,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; diff --git a/crates/db_queries/src/aggregates/person_aggregates.rs b/crates/db_queries/src/aggregates/person_aggregates.rs index 56d72d38b..359c81fb6 100644 --- a/crates/db_queries/src/aggregates/person_aggregates.rs +++ b/crates/db_queries/src/aggregates/person_aggregates.rs @@ -36,6 +36,7 @@ mod tests { post::{Post, PostForm, PostLike, PostLikeForm}, }; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -68,6 +69,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -85,6 +87,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; @@ -104,6 +107,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; diff --git a/crates/db_queries/src/aggregates/post_aggregates.rs b/crates/db_queries/src/aggregates/post_aggregates.rs index 2fcb6f5d2..f2af0d580 100644 --- a/crates/db_queries/src/aggregates/post_aggregates.rs +++ b/crates/db_queries/src/aggregates/post_aggregates.rs @@ -40,6 +40,7 @@ mod tests { post::{Post, PostForm, PostLike, PostLikeForm}, }; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -72,6 +73,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -81,6 +83,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; @@ -91,6 +94,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; diff --git a/crates/db_queries/src/aggregates/site_aggregates.rs b/crates/db_queries/src/aggregates/site_aggregates.rs index 995462e1a..3aab0df25 100644 --- a/crates/db_queries/src/aggregates/site_aggregates.rs +++ b/crates/db_queries/src/aggregates/site_aggregates.rs @@ -34,6 +34,7 @@ mod tests { site::{Site, SiteForm}, }; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -74,6 +75,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -85,6 +87,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; @@ -96,6 +99,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; diff --git a/crates/db_queries/src/source/comment.rs b/crates/db_queries/src/source/comment.rs index e41aa6ff5..fa235a2fe 100644 --- a/crates/db_queries/src/source/comment.rs +++ b/crates/db_queries/src/source/comment.rs @@ -238,6 +238,7 @@ mod tests { post::*, }; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -263,6 +264,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -272,6 +274,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; @@ -290,7 +293,7 @@ mod tests { updated: None, ap_id: inserted_comment.ap_id.to_owned(), local: true, - language: None, + language: LanguageTag::parse("en").unwrap().into(), }; let child_comment_form = CommentForm { @@ -298,6 +301,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; diff --git a/crates/db_queries/src/source/moderator.rs b/crates/db_queries/src/source/moderator.rs index 14bb07f1c..bd65b916c 100644 --- a/crates/db_queries/src/source/moderator.rs +++ b/crates/db_queries/src/source/moderator.rs @@ -200,6 +200,7 @@ mod tests { use crate::{establish_unpooled_connection, Crud}; use lemmy_db_schema::source::{comment::*, community::*, moderator::*, person::*, post::*}; use serial_test::serial; + use language_tags::LanguageTag; // use Crud; #[test] @@ -233,6 +234,7 @@ mod tests { name: "A test post thweep".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -242,6 +244,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; diff --git a/crates/db_queries/src/source/password_reset_request.rs b/crates/db_queries/src/source/password_reset_request.rs index 6fe4ee3a5..877821a5e 100644 --- a/crates/db_queries/src/source/password_reset_request.rs +++ b/crates/db_queries/src/source/password_reset_request.rs @@ -87,6 +87,7 @@ mod tests { person::*, }; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -103,6 +104,7 @@ mod tests { let new_local_user = LocalUserForm { person_id: inserted_person.id, password_encrypted: "pass".to_string(), + discussion_languages: Some(vec![LanguageTag::parse("en").unwrap().into()]), ..LocalUserForm::default() }; diff --git a/crates/db_queries/src/source/person_mention.rs b/crates/db_queries/src/source/person_mention.rs index 456894200..c55b4bb7b 100644 --- a/crates/db_queries/src/source/person_mention.rs +++ b/crates/db_queries/src/source/person_mention.rs @@ -82,6 +82,7 @@ mod tests { post::*, }; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -114,6 +115,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -123,6 +125,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; diff --git a/crates/db_queries/src/source/post.rs b/crates/db_queries/src/source/post.rs index 8220ae3e3..64aac78a9 100644 --- a/crates/db_queries/src/source/post.rs +++ b/crates/db_queries/src/source/post.rs @@ -265,6 +265,7 @@ mod tests { person::*, }; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -290,6 +291,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -315,7 +317,7 @@ mod tests { thumbnail_url: None, ap_id: inserted_post.ap_id.to_owned(), local: true, - language: None, + language: LanguageTag::parse("en").unwrap().into(), }; // Post Like diff --git a/crates/db_queries/src/source/private_message.rs b/crates/db_queries/src/source/private_message.rs index 98c8e08ce..da5d8afb0 100644 --- a/crates/db_queries/src/source/private_message.rs +++ b/crates/db_queries/src/source/private_message.rs @@ -142,6 +142,7 @@ mod tests { use crate::{establish_unpooled_connection, source::private_message::PrivateMessage_, Crud}; use lemmy_db_schema::source::{person::*, private_message::*}; use serial_test::serial; + use language_tags::LanguageTag; #[test] #[serial] @@ -166,6 +167,7 @@ mod tests { content: "A test private message".into(), creator_id: inserted_creator.id, recipient_id: inserted_recipient.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PrivateMessageForm::default() }; @@ -182,6 +184,7 @@ mod tests { published: inserted_private_message.published, ap_id: inserted_private_message.ap_id.to_owned(), local: true, + language: LanguageTag::parse("en").unwrap().into(), }; let read_private_message = PrivateMessage::read(&conn, inserted_private_message.id).unwrap(); diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 02fedab21..946298482 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -472,6 +472,7 @@ mod tests { name: "A test post 2".into(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() }; @@ -481,6 +482,7 @@ mod tests { content: "A test comment 32".into(), creator_id: inserted_person.id, post_id: inserted_post.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..CommentForm::default() }; diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index a8d3d472b..348d29915 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -484,6 +484,7 @@ mod tests { name: post_name.to_owned(), creator_id: inserted_person.id, community_id: inserted_community.id, + language: Some(LanguageTag::parse("en").unwrap().into()), ..PostForm::default() };