use lemmy_structs::{blocking, comment::*, send_local_notifs};
use lemmy_utils::{
utils::{remove_slurs, scrape_text_for_mentions},
- APIError,
+ ApiError,
ConnectionId,
LemmyError,
};
// Check if post is locked, no new comments
if post.locked {
- return Err(APIError::err("locked").into());
+ return Err(ApiError::err("locked").into());
}
// If there's a parent_id, check to make sure that comment is in that post
let parent =
match blocking(context.pool(), move |conn| Comment::read(&conn, parent_id)).await? {
Ok(comment) => comment,
- Err(_e) => return Err(APIError::err("couldnt_create_comment").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_create_comment").into()),
};
if parent.post_id != post_id {
- return Err(APIError::err("couldnt_create_comment").into());
+ return Err(ApiError::err("couldnt_create_comment").into());
}
}
.await?
{
Ok(comment) => comment,
- Err(_e) => return Err(APIError::err("couldnt_create_comment").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_create_comment").into()),
};
// Necessary to update the ap_id
.await?
{
Ok(comment) => comment,
- Err(_e) => return Err(APIError::err("couldnt_create_comment").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_create_comment").into()),
};
updated_comment.send_create(&user, context).await?;
let like = move |conn: &'_ _| CommentLike::like(&conn, &like_form);
if blocking(context.pool(), like).await?.is_err() {
- return Err(APIError::err("couldnt_like_comment").into());
+ return Err(ApiError::err("couldnt_like_comment").into());
}
updated_comment.send_like(&user, context).await?;
.await?
{
Ok(comment) => comment,
- Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_update_comment").into()),
};
comment_view.comment.read = true;
}
// Verify that only the creator can edit
if user.id != orig_comment.creator.id {
- return Err(APIError::err("no_comment_edit_allowed").into());
+ return Err(ApiError::err("no_comment_edit_allowed").into());
}
// Do the update
.await?
{
Ok(comment) => comment,
- Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_update_comment").into()),
};
// Send the apub update
// Verify that only the creator can delete
if user.id != orig_comment.creator.id {
- return Err(APIError::err("no_comment_edit_allowed").into());
+ return Err(ApiError::err("no_comment_edit_allowed").into());
}
// Do the delete
.await?
{
Ok(comment) => comment,
- Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_update_comment").into()),
};
// Send the apub message
.await?
{
Ok(comment) => comment,
- Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_update_comment").into()),
};
// Mod tables
// Verify that only the recipient can mark as read
if user.id != orig_comment.get_recipient_id() {
- return Err(APIError::err("no_comment_edit_allowed").into());
+ return Err(ApiError::err("no_comment_edit_allowed").into());
}
// Do the mark as read
.await?
{
Ok(comment) => comment,
- Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_update_comment").into()),
};
// Refetch it
if data.save {
let save_comment = move |conn: &'_ _| CommentSaved::save(conn, &comment_saved_form);
if blocking(context.pool(), save_comment).await?.is_err() {
- return Err(APIError::err("couldnt_save_comment").into());
+ return Err(ApiError::err("couldnt_save_comment").into());
}
} else {
let unsave_comment = move |conn: &'_ _| CommentSaved::unsave(conn, &comment_saved_form);
if blocking(context.pool(), unsave_comment).await?.is_err() {
- return Err(APIError::err("couldnt_save_comment").into());
+ return Err(ApiError::err("couldnt_save_comment").into());
}
}
let like_form2 = like_form.clone();
let like = move |conn: &'_ _| CommentLike::like(conn, &like_form2);
if blocking(context.pool(), like).await?.is_err() {
- return Err(APIError::err("couldnt_like_comment").into());
+ return Err(ApiError::err("couldnt_like_comment").into());
}
if like_form.score == 1 {
.await?;
let comments = match comments {
Ok(comments) => comments,
- Err(_) => return Err(APIError::err("couldnt_get_comments").into()),
+ Err(_) => return Err(ApiError::err("couldnt_get_comments").into()),
};
Ok(GetCommentsResponse { comments })
// 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 = CreateCommentReportResponse { 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());
};
let report_id = data.report_id;