2024-01-03 18:39:21 +00:00
|
|
|
use actix_web::web::{Data, Json, Query};
|
|
|
|
use lemmy_api_common::{
|
|
|
|
comment::{ListCommentLikes, ListCommentLikesResponse},
|
|
|
|
context::LemmyContext,
|
2024-01-23 23:47:28 +00:00
|
|
|
utils::is_mod_or_admin,
|
2024-01-03 18:39:21 +00:00
|
|
|
};
|
2024-01-23 23:47:28 +00:00
|
|
|
use lemmy_db_views::structs::{CommentView, LocalUserView, VoteView};
|
2024-04-16 12:48:15 +00:00
|
|
|
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
2024-01-03 18:39:21 +00:00
|
|
|
|
|
|
|
/// Lists likes for a comment
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn list_comment_likes(
|
|
|
|
data: Query<ListCommentLikes>,
|
|
|
|
context: Data<LemmyContext>,
|
|
|
|
local_user_view: LocalUserView,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<Json<ListCommentLikesResponse>> {
|
2024-01-23 23:47:28 +00:00
|
|
|
let comment_view = CommentView::read(
|
|
|
|
&mut context.pool(),
|
|
|
|
data.comment_id,
|
2024-07-07 16:28:42 +00:00
|
|
|
Some(&local_user_view.local_user),
|
2024-01-23 23:47:28 +00:00
|
|
|
)
|
2024-04-16 12:48:15 +00:00
|
|
|
.await?
|
|
|
|
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
|
|
|
2024-01-23 23:47:28 +00:00
|
|
|
is_mod_or_admin(
|
|
|
|
&mut context.pool(),
|
|
|
|
&local_user_view.person,
|
|
|
|
comment_view.community.id,
|
|
|
|
)
|
|
|
|
.await?;
|
2024-01-03 18:39:21 +00:00
|
|
|
|
|
|
|
let comment_likes =
|
|
|
|
VoteView::list_for_comment(&mut context.pool(), data.comment_id, data.page, data.limit).await?;
|
|
|
|
|
|
|
|
Ok(Json(ListCommentLikesResponse { comment_likes }))
|
|
|
|
}
|