diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 9f513607f..473966606 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -71,11 +71,11 @@ impl PerformCrud for CreatePost { .unwrap_or((None, None, None)); let post_form = PostForm { - name: Some(data.name.trim().to_owned()), + name: data.name.trim().to_owned(), url: data_url.map(|u| clean_url_params(u.to_owned()).into()), body: clean_optional_text(&data.body), - community_id: Some(data.community_id), - creator_id: Some(local_user_view.person.id), + community_id: data.community_id, + creator_id: local_user_view.person.id, nsfw: data.nsfw, embed_title, embed_description, diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index 858e619bb..fa19c2c9b 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -75,9 +75,9 @@ impl PerformCrud for EditPost { .unwrap_or((None, None, None)); let post_form = PostForm { - creator_id: Some(orig_post.creator_id.to_owned()), - community_id: Some(orig_post.community_id), - name: Some(data.name.to_owned().unwrap_or(orig_post.name)), + creator_id: orig_post.creator_id.to_owned(), + community_id: orig_post.community_id, + name: data.name.to_owned().unwrap_or(orig_post.name), url: data_url.map(|u| clean_url_params(u.to_owned()).into()), body: clean_optional_text(&data.body), nsfw: data.nsfw, diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index e55f44c92..88ca1ceb0 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -182,11 +182,11 @@ impl ApubObject for ApubPost { .map(|s| remove_slurs(&s, &context.settings().slur_regex())); PostForm { - name: Some(page.name.clone()), + name: page.name.clone(), url: url.map(Into::into), body: body_slurs_removed, - creator_id: Some(creator.id), - community_id: Some(community.id), + creator_id: creator.id, + community_id: community.id, removed: None, locked: page.comments_enabled.map(|e| !e), published: page.published.map(|u| u.naive_local()), @@ -204,6 +204,9 @@ impl ApubObject for ApubPost { } else { // if is mod action, only update locked/stickied fields, nothing else PostForm { + name: page.name.clone(), + creator_id: creator.id, + community_id: community.id, locked: page.comments_enabled.map(|e| !e), stickied: page.stickied, updated: page.updated.map(|u| u.naive_local()), diff --git a/crates/db_schema/src/aggregates/comment_aggregates.rs b/crates/db_schema/src/aggregates/comment_aggregates.rs index 0215900ab..d47899bbf 100644 --- a/crates/db_schema/src/aggregates/comment_aggregates.rs +++ b/crates/db_schema/src/aggregates/comment_aggregates.rs @@ -66,9 +66,9 @@ mod tests { let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { - name: Some("A test post".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/aggregates/community_aggregates.rs b/crates/db_schema/src/aggregates/community_aggregates.rs index d4515b928..d80425e17 100644 --- a/crates/db_schema/src/aggregates/community_aggregates.rs +++ b/crates/db_schema/src/aggregates/community_aggregates.rs @@ -102,9 +102,9 @@ mod tests { CommunityFollower::follow(&conn, &another_community_follow).unwrap(); let new_post = PostForm { - name: Some("A test post".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/aggregates/person_aggregates.rs b/crates/db_schema/src/aggregates/person_aggregates.rs index 20e555cd0..e0fc0734c 100644 --- a/crates/db_schema/src/aggregates/person_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_aggregates.rs @@ -66,9 +66,9 @@ mod tests { let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { - name: Some("A test post".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/aggregates/post_aggregates.rs b/crates/db_schema/src/aggregates/post_aggregates.rs index b77f5f679..cb8aba26e 100644 --- a/crates/db_schema/src/aggregates/post_aggregates.rs +++ b/crates/db_schema/src/aggregates/post_aggregates.rs @@ -70,9 +70,9 @@ mod tests { let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { - name: Some("A test post".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/aggregates/site_aggregates.rs b/crates/db_schema/src/aggregates/site_aggregates.rs index fa94c6dc7..745097dfe 100644 --- a/crates/db_schema/src/aggregates/site_aggregates.rs +++ b/crates/db_schema/src/aggregates/site_aggregates.rs @@ -69,9 +69,9 @@ mod tests { let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { - name: Some("A test post".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 34117d57a..09389aad8 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -241,9 +241,9 @@ mod tests { let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { - name: Some("A test post".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/impls/moderator.rs b/crates/db_schema/src/impls/moderator.rs index f18722219..696dbe0a4 100644 --- a/crates/db_schema/src/impls/moderator.rs +++ b/crates/db_schema/src/impls/moderator.rs @@ -301,9 +301,9 @@ mod tests { let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { - name: Some("A test post thweep".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post thweep".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/impls/person_mention.rs b/crates/db_schema/src/impls/person_mention.rs index 3ae5c9dd0..df0e55ede 100644 --- a/crates/db_schema/src/impls/person_mention.rs +++ b/crates/db_schema/src/impls/person_mention.rs @@ -118,9 +118,9 @@ mod tests { let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { - name: Some("A test post".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index 60369bae0..9a8bbcece 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -292,9 +292,9 @@ mod tests { let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { - name: Some("A test post".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index ff2226e1a..cc9325361 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -30,9 +30,9 @@ pub struct Post { #[derive(Insertable, AsChangeset, Default)] #[table_name = "post"] pub struct PostForm { - pub creator_id: Option, - pub community_id: Option, - pub name: Option, + pub name: String, + pub creator_id: PersonId, + pub community_id: CommunityId, pub nsfw: Option, pub url: Option, pub body: Option, diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 23d8f359d..63701db93 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -372,9 +372,9 @@ mod tests { let _inserted_moderator = CommunityModerator::join(&conn, &timmy_moderator_form).unwrap(); let new_post = PostForm { - name: Some("A test post crv".into()), - creator_id: Some(inserted_timmy.id), - community_id: Some(inserted_community.id), + name: "A test post crv".into(), + creator_id: inserted_timmy.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 45f18eb47..4a7f96b6a 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -579,9 +579,9 @@ mod tests { let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { - name: Some("A test post 2".into()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: "A test post 2".into(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index cecd8c1ef..66341d67b 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -360,9 +360,9 @@ mod tests { let _inserted_moderator = CommunityModerator::join(&conn, &timmy_moderator_form).unwrap(); let new_post = PostForm { - name: Some("A test post crv".into()), - creator_id: Some(inserted_timmy.id), - community_id: Some(inserted_community.id), + name: "A test post crv".into(), + creator_id: inserted_timmy.id, + community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 9a03e3d0e..a3df66afa 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -571,9 +571,9 @@ mod tests { let inserted_blocked_person = Person::create(&conn, &blocked_person).unwrap(); let post_from_blocked_person = PostForm { - name: Some("blocked_person_post".to_string()), - creator_id: Some(inserted_blocked_person.id), - community_id: Some(inserted_community.id), + name: "blocked_person_post".to_string(), + creator_id: inserted_blocked_person.id, + community_id: inserted_community.id, ..PostForm::default() }; @@ -589,18 +589,18 @@ mod tests { // A sample post let new_post = PostForm { - name: Some(post_name.to_owned()), - creator_id: Some(inserted_person.id), - community_id: Some(inserted_community.id), + name: post_name.to_owned(), + creator_id: inserted_person.id, + community_id: inserted_community.id, ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); let new_bot_post = PostForm { - name: Some(bot_post_name), - creator_id: Some(inserted_bot.id), - community_id: Some(inserted_community.id), + name: bot_post_name, + creator_id: inserted_bot.id, + community_id: inserted_community.id, ..PostForm::default() };