-use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
-
-use crate::PerformCrud;
-
-#[async_trait::async_trait(?Send)]
-impl PerformCrud for CreatePost {
- type Response = PostResponse;
-
- async fn perform(
- &self,
- context: &Data<LemmyContext>,
- websocket_id: Option<ConnectionId>,
- ) -> Result<PostResponse, LemmyError> {
- let data: &CreatePost = self;
- let local_user_view =
- get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
-
- let slur_regex = &context.settings().slur_regex();
- check_slurs(&data.name, slur_regex)?;
- check_slurs_opt(&data.body, slur_regex)?;
- honeypot_check(&data.honeypot)?;
-
- if !is_valid_post_title(&data.name) {
- return Err(ApiError::err_plain("invalid_post_title").into());
- }
-
- check_community_ban(local_user_view.person.id, data.community_id, context.pool()).await?;
- check_community_deleted_or_removed(data.community_id, context.pool()).await?;
-
- // Fetch post links and pictrs cached image
- let data_url = data.url.as_ref();
- let (metadata_res, pictrs_thumbnail) =
- fetch_site_data(context.client(), &context.settings(), data_url).await;
- let (embed_title, embed_description, embed_html) = metadata_res
- .map(|u| (u.title, u.description, u.html))
- .unwrap_or((None, None, None));
-
- let post_form = PostForm {
- name: data.name.trim().to_owned(),
- url: data_url.map(|u| clean_url_params(u.to_owned()).into()),
- body: data.body.to_owned(),
- community_id: data.community_id,
- creator_id: local_user_view.person.id,
- nsfw: data.nsfw,
- embed_title,
- embed_description,
- embed_html,
- thumbnail_url: pictrs_thumbnail.map(|u| u.into()),
- ..PostForm::default()
- };