use lemmy_utils::{
request::fetch_iframely_and_pictrs_data,
utils::{check_slurs, check_slurs_opt, is_valid_post_title},
- APIError,
+ ApiError,
ConnectionId,
LemmyError,
};
check_slurs_opt(&data.body)?;
if !is_valid_post_title(&data.name) {
- return Err(APIError::err("invalid_post_title").into());
+ return Err(ApiError::err("invalid_post_title").into());
}
check_community_ban(user.id, data.community_id, context.pool()).await?;
"couldnt_create_post"
};
- return Err(APIError::err(err_type).into());
+ return Err(ApiError::err(err_type).into());
}
};
.await?
{
Ok(post) => post,
- Err(_e) => return Err(APIError::err("couldnt_create_post").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_create_post").into()),
};
updated_post.send_create(&user, context).await?;
let like = move |conn: &'_ _| PostLike::like(conn, &like_form);
if blocking(context.pool(), like).await?.is_err() {
- return Err(APIError::err("couldnt_like_post").into());
+ return Err(ApiError::err("couldnt_like_post").into());
}
updated_post.send_like(&user, context).await?;
.await?
{
Ok(post) => post,
- Err(_e) => return Err(APIError::err("couldnt_find_post").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_find_post").into()),
};
let res = PostResponse { post_view };
.await?
{
Ok(post) => post,
- Err(_e) => return Err(APIError::err("couldnt_find_post").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_find_post").into()),
};
let id = data.id;
.await?
{
Ok(community) => community,
- Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_find_community").into()),
};
let online = context
.await?
{
Ok(posts) => posts,
- Err(_e) => return Err(APIError::err("couldnt_get_posts").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_get_posts").into()),
};
Ok(GetPostsResponse { posts })
let like_form2 = like_form.clone();
let like = move |conn: &'_ _| PostLike::like(conn, &like_form2);
if blocking(context.pool(), like).await?.is_err() {
- return Err(APIError::err("couldnt_like_post").into());
+ return Err(ApiError::err("couldnt_like_post").into());
}
if like_form.score == 1 {
.await?
{
Ok(post) => post,
- Err(_e) => return Err(APIError::err("couldnt_find_post").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_find_post").into()),
};
let res = PostResponse { post_view };
check_slurs_opt(&data.body)?;
if !is_valid_post_title(&data.name) {
- return Err(APIError::err("invalid_post_title").into());
+ return Err(ApiError::err("invalid_post_title").into());
}
let post_id = data.post_id;
// Verify that only the creator can edit
if !Post::is_post_creator(user.id, orig_post.creator_id) {
- return Err(APIError::err("no_post_edit_allowed").into());
+ return Err(ApiError::err("no_post_edit_allowed").into());
}
// Fetch Iframely and Pictrs cached image
"couldnt_update_post"
};
- return Err(APIError::err(err_type).into());
+ return Err(ApiError::err(err_type).into());
}
};
// Verify that only the creator can delete
if !Post::is_post_creator(user.id, orig_post.creator_id) {
- return Err(APIError::err("no_post_edit_allowed").into());
+ return Err(ApiError::err("no_post_edit_allowed").into());
}
// Update the post
if data.save {
let save = move |conn: &'_ _| PostSaved::save(conn, &post_saved_form);
if blocking(context.pool(), save).await?.is_err() {
- return Err(APIError::err("couldnt_save_post").into());
+ return Err(ApiError::err("couldnt_save_post").into());
}
} else {
let unsave = move |conn: &'_ _| PostSaved::unsave(conn, &post_saved_form);
if blocking(context.pool(), unsave).await?.is_err() {
- return Err(APIError::err("couldnt_save_post").into());
+ return Err(ApiError::err("couldnt_save_post").into());
}
}
// check size of report and check for whitespace
let reason = data.reason.trim();
if reason.is_empty() {
- return Err(APIError::err("report_reason_required").into());
+ return Err(ApiError::err("report_reason_required").into());
}
if reason.chars().count() > 1000 {
- return Err(APIError::err("report_too_long").into());
+ return Err(ApiError::err("report_too_long").into());
}
let user_id = user.id;
.await?
{
Ok(report) => report,
- Err(_e) => return Err(APIError::err("couldnt_create_report").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_create_report").into()),
};
let res = CreatePostReportResponse { success: true };
};
if blocking(context.pool(), resolve_fun).await?.is_err() {
- return Err(APIError::err("couldnt_resolve_report").into());
+ return Err(ApiError::err("couldnt_resolve_report").into());
};
context.chat_server().do_send(SendModRoomMessage {