--- /dev/null
+use crate::Perform;
+use actix_web::web::Data;
+use lemmy_api_common::{
+ comment::{CommentResponse, DistinguishComment},
+ context::LemmyContext,
+ utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin},
+};
+use lemmy_db_schema::{
+ source::comment::{Comment, CommentUpdateForm},
+ traits::Crud,
+};
+use lemmy_db_views::structs::CommentView;
+use lemmy_utils::{error::LemmyError, ConnectionId};
+
+#[async_trait::async_trait(?Send)]
+impl Perform for DistinguishComment {
+ type Response = CommentResponse;
+
+ #[tracing::instrument(skip(context, _websocket_id))]
+ async fn perform(
+ &self,
+ context: &Data<LemmyContext>,
+ _websocket_id: Option<ConnectionId>,
+ ) -> Result<CommentResponse, LemmyError> {
+ let data: &DistinguishComment = self;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
+
+ let comment_id = data.comment_id;
+ let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
+
+ check_community_ban(
+ local_user_view.person.id,
+ orig_comment.community.id,
+ context.pool(),
+ )
+ .await?;
+
+ // Verify that only a mod or admin can distinguish a comment
+ is_mod_or_admin(
+ context.pool(),
+ local_user_view.person.id,
+ orig_comment.community.id,
+ )
+ .await?;
+
+ // Update the Comment
+ let comment_id = data.comment_id;
+ let form = CommentUpdateForm::builder()
+ .distinguished(Some(data.distinguished))
+ .build();
+ Comment::update(context.pool(), comment_id, &form)
+ .await
+ .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
+
+ let comment_id = data.comment_id;
+ let person_id = local_user_view.person.id;
+ let comment_view = CommentView::read(context.pool(), comment_id, Some(person_id)).await?;
+
+ Ok(CommentResponse {
+ comment_view,
+ recipient_ids: Vec::new(),
+ form_id: None,
+ })
+ }
+}
+mod distinguish;
mod like;
mod save;
pub struct EditComment {
pub comment_id: CommentId,
pub content: Option<String>,
- pub distinguished: Option<bool>,
pub language_id: Option<LanguageId>,
pub form_id: Option<String>,
pub auth: Sensitive<String>,
}
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
+pub struct DistinguishComment {
+ pub comment_id: CommentId,
+ pub distinguished: bool,
+ pub auth: Sensitive<String>,
+}
+
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct DeleteComment {
pub comment_id: CommentId,
GetCaptcha,
SaveComment,
CreateCommentLike,
+ DistinguishComment,
CreateCommentReport,
ResolveCommentReport,
ListCommentReports,
use lemmy_api_common::{
comment::{CommentResponse, EditComment},
context::LemmyContext,
- utils::{
- check_community_ban,
- get_local_user_view_from_jwt,
- is_mod_or_admin,
- local_site_to_slur_regex,
- },
+ utils::{check_community_ban, get_local_user_view_from_jwt, local_site_to_slur_regex},
websocket::{
send::{send_comment_ws_message, send_local_notifs},
UserOperationCrud,
return Err(LemmyError::from_message("no_comment_edit_allowed"));
}
- if data.distinguished.is_some() {
- // Verify that only a mod or admin can distinguish a comment
- is_mod_or_admin(
- context.pool(),
- local_user_view.person.id,
- orig_comment.community.id,
- )
- .await?;
- }
-
let language_id = self.language_id;
CommunityLanguage::is_allowed_community_language(
context.pool(),
let comment_id = data.comment_id;
let form = CommentUpdateForm::builder()
.content(content_slurs_removed)
- .distinguished(data.distinguished)
.language_id(data.language_id)
.updated(Some(Some(naive_now())))
.build();
comment::{
CommentReportResponse,
CommentResponse,
+ DistinguishComment,
GetComment,
GetComments,
GetCommentsResponse,
type Response = CommentResponse;
}
+impl SendActivity for DistinguishComment {
+ type Response = CommentResponse;
+}
+
impl SendActivity for ListCommentReports {
type Response = ListCommentReportsResponse;
}
CreateCommentLike,
CreateCommentReport,
DeleteComment,
+ DistinguishComment,
EditComment,
GetComment,
GetComments,
"/mark_as_read",
web::post().to(route_post::<MarkCommentReplyAsRead>),
)
+ .route(
+ "/distinguish",
+ web::post().to(route_post::<DistinguishComment>),
+ )
.route("/like", web::post().to(route_post::<CreateCommentLike>))
.route("/save", web::put().to(route_post::<SaveComment>))
.route("/list", web::get().to(route_get_apub::<GetComments>))
CreateCommentLike,
CreateCommentReport,
DeleteComment,
+ DistinguishComment,
EditComment,
GetComment,
GetComments,
UserOperation::CreateCommentLike => {
do_websocket_operation::<CreateCommentLike>(context, id, op, data).await
}
+ UserOperation::DistinguishComment => {
+ do_websocket_operation::<DistinguishComment>(context, id, op, data).await
+ }
UserOperation::CreateCommentReport => {
do_websocket_operation::<CreateCommentReport>(context, id, op, data).await
}