mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 04:41:19 +00:00
Separate comment distinguish (#2740)
* Combine prod and dev docker setups using build-arg - Fixes #2603 * Dont use cache for release build. * Separate comment distinguish into its own action. - Fixes #2708 --------- Co-authored-by: Nutomic <me@nutomic.com>
This commit is contained in:
parent
3735c6fabf
commit
1917e3d495
8 changed files with 90 additions and 18 deletions
66
crates/api/src/comment/distinguish.rs
Normal file
66
crates/api/src/comment/distinguish.rs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,2 +1,3 @@
|
||||||
|
mod distinguish;
|
||||||
mod like;
|
mod like;
|
||||||
mod save;
|
mod save;
|
||||||
|
|
|
@ -27,12 +27,18 @@ pub struct GetComment {
|
||||||
pub struct EditComment {
|
pub struct EditComment {
|
||||||
pub comment_id: CommentId,
|
pub comment_id: CommentId,
|
||||||
pub content: Option<String>,
|
pub content: Option<String>,
|
||||||
pub distinguished: Option<bool>,
|
|
||||||
pub language_id: Option<LanguageId>,
|
pub language_id: Option<LanguageId>,
|
||||||
pub form_id: Option<String>,
|
pub form_id: Option<String>,
|
||||||
pub auth: Sensitive<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)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
pub struct DeleteComment {
|
pub struct DeleteComment {
|
||||||
pub comment_id: CommentId,
|
pub comment_id: CommentId,
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub enum UserOperation {
|
||||||
GetCaptcha,
|
GetCaptcha,
|
||||||
SaveComment,
|
SaveComment,
|
||||||
CreateCommentLike,
|
CreateCommentLike,
|
||||||
|
DistinguishComment,
|
||||||
CreateCommentReport,
|
CreateCommentReport,
|
||||||
ResolveCommentReport,
|
ResolveCommentReport,
|
||||||
ListCommentReports,
|
ListCommentReports,
|
||||||
|
|
|
@ -3,12 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, EditComment},
|
comment::{CommentResponse, EditComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::{
|
utils::{check_community_ban, get_local_user_view_from_jwt, local_site_to_slur_regex},
|
||||||
check_community_ban,
|
|
||||||
get_local_user_view_from_jwt,
|
|
||||||
is_mod_or_admin,
|
|
||||||
local_site_to_slur_regex,
|
|
||||||
},
|
|
||||||
websocket::{
|
websocket::{
|
||||||
send::{send_comment_ws_message, send_local_notifs},
|
send::{send_comment_ws_message, send_local_notifs},
|
||||||
UserOperationCrud,
|
UserOperationCrud,
|
||||||
|
@ -60,16 +55,6 @@ impl PerformCrud for EditComment {
|
||||||
return Err(LemmyError::from_message("no_comment_edit_allowed"));
|
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;
|
let language_id = self.language_id;
|
||||||
CommunityLanguage::is_allowed_community_language(
|
CommunityLanguage::is_allowed_community_language(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
|
@ -86,7 +71,6 @@ impl PerformCrud for EditComment {
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let form = CommentUpdateForm::builder()
|
let form = CommentUpdateForm::builder()
|
||||||
.content(content_slurs_removed)
|
.content(content_slurs_removed)
|
||||||
.distinguished(data.distinguished)
|
|
||||||
.language_id(data.language_id)
|
.language_id(data.language_id)
|
||||||
.updated(Some(Some(naive_now())))
|
.updated(Some(Some(naive_now())))
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -3,6 +3,7 @@ use lemmy_api_common::{
|
||||||
comment::{
|
comment::{
|
||||||
CommentReportResponse,
|
CommentReportResponse,
|
||||||
CommentResponse,
|
CommentResponse,
|
||||||
|
DistinguishComment,
|
||||||
GetComment,
|
GetComment,
|
||||||
GetComments,
|
GetComments,
|
||||||
GetCommentsResponse,
|
GetCommentsResponse,
|
||||||
|
@ -342,6 +343,10 @@ impl SendActivity for SaveComment {
|
||||||
type Response = CommentResponse;
|
type Response = CommentResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SendActivity for DistinguishComment {
|
||||||
|
type Response = CommentResponse;
|
||||||
|
}
|
||||||
|
|
||||||
impl SendActivity for ListCommentReports {
|
impl SendActivity for ListCommentReports {
|
||||||
type Response = ListCommentReportsResponse;
|
type Response = ListCommentReportsResponse;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use lemmy_api_common::{
|
||||||
CreateCommentLike,
|
CreateCommentLike,
|
||||||
CreateCommentReport,
|
CreateCommentReport,
|
||||||
DeleteComment,
|
DeleteComment,
|
||||||
|
DistinguishComment,
|
||||||
EditComment,
|
EditComment,
|
||||||
GetComment,
|
GetComment,
|
||||||
GetComments,
|
GetComments,
|
||||||
|
@ -218,6 +219,10 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
"/mark_as_read",
|
"/mark_as_read",
|
||||||
web::post().to(route_post::<MarkCommentReplyAsRead>),
|
web::post().to(route_post::<MarkCommentReplyAsRead>),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
"/distinguish",
|
||||||
|
web::post().to(route_post::<DistinguishComment>),
|
||||||
|
)
|
||||||
.route("/like", web::post().to(route_post::<CreateCommentLike>))
|
.route("/like", web::post().to(route_post::<CreateCommentLike>))
|
||||||
.route("/save", web::put().to(route_post::<SaveComment>))
|
.route("/save", web::put().to(route_post::<SaveComment>))
|
||||||
.route("/list", web::get().to(route_get_apub::<GetComments>))
|
.route("/list", web::get().to(route_get_apub::<GetComments>))
|
||||||
|
|
|
@ -9,6 +9,7 @@ use lemmy_api_common::{
|
||||||
CreateCommentLike,
|
CreateCommentLike,
|
||||||
CreateCommentReport,
|
CreateCommentReport,
|
||||||
DeleteComment,
|
DeleteComment,
|
||||||
|
DistinguishComment,
|
||||||
EditComment,
|
EditComment,
|
||||||
GetComment,
|
GetComment,
|
||||||
GetComments,
|
GetComments,
|
||||||
|
@ -590,6 +591,9 @@ pub async fn match_websocket_operation(
|
||||||
UserOperation::CreateCommentLike => {
|
UserOperation::CreateCommentLike => {
|
||||||
do_websocket_operation::<CreateCommentLike>(context, id, op, data).await
|
do_websocket_operation::<CreateCommentLike>(context, id, op, data).await
|
||||||
}
|
}
|
||||||
|
UserOperation::DistinguishComment => {
|
||||||
|
do_websocket_operation::<DistinguishComment>(context, id, op, data).await
|
||||||
|
}
|
||||||
UserOperation::CreateCommentReport => {
|
UserOperation::CreateCommentReport => {
|
||||||
do_websocket_operation::<CreateCommentReport>(context, id, op, data).await
|
do_websocket_operation::<CreateCommentReport>(context, id, op, data).await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue