- let inserted_post =
- match blocking(context.pool(), move |conn| Post::create(conn, &post_form)).await? {
- Ok(post) => post,
- Err(e) => {
- let err_type = if e.to_string() == "value too long for type character varying(200)" {
- "post_title_too_long"
- } else {
- "couldnt_create_post"
- };
-
- return Err(LemmyError::from_error_message(e, err_type));
- }
- };
-
- let inserted_post_id = inserted_post.id;
- let protocol_and_hostname = context.settings().get_protocol_and_hostname();
- let updated_post = blocking(context.pool(), move |conn| -> Result<Post, LemmyError> {
- let apub_id = generate_local_apub_endpoint(
- EndpointType::Post,
- &inserted_post_id.to_string(),
- &protocol_and_hostname,
- )?;
- Ok(Post::update_ap_id(conn, inserted_post_id, apub_id)?)
- })
- .await?
- .map_err(|e| e.with_message("couldnt_create_post"))?;
-
- // They like their own post by default
- let person_id = local_user_view.person.id;
- let post_id = inserted_post.id;
- let like_form = PostLikeForm {
- post_id,
- person_id,
- score: 1,
- };
+ let post_form = PostInsertForm::builder()
+ .name(data.name.trim().to_owned())
+ .url(url)
+ .body(data.body.clone())
+ .community_id(data.community_id)
+ .creator_id(local_user_view.person.id)
+ .nsfw(data.nsfw)
+ .embed_title(embed_title)
+ .embed_description(embed_description)
+ .embed_video_url(embed_video_url)
+ .language_id(language_id)
+ .thumbnail_url(thumbnail_url)
+ .build();
+
+ let inserted_post = Post::create(&mut context.pool(), &post_form)
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntCreatePost)?;
+
+ let inserted_post_id = inserted_post.id;
+ let protocol_and_hostname = context.settings().get_protocol_and_hostname();
+ let apub_id = generate_local_apub_endpoint(
+ EndpointType::Post,
+ &inserted_post_id.to_string(),
+ &protocol_and_hostname,
+ )?;
+ let updated_post = Post::update(
+ &mut context.pool(),
+ inserted_post_id,
+ &PostUpdateForm::builder().ap_id(Some(apub_id)).build(),
+ )
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntCreatePost)?;
+
+ // They like their own post by default
+ let person_id = local_user_view.person.id;
+ let post_id = inserted_post.id;
+ let like_form = PostLikeForm {
+ post_id,
+ person_id,
+ score: 1,
+ };
+
+ PostLike::like(&mut context.pool(), &like_form)
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntLikePost)?;