mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-18 05:10:34 +00:00
* Update comment.rs * Update community.rs * Update local_site.rs * Update local_site_rate_limit.rs * Update local_user.rs * Update person.rs * Update comment.rs * Update community.rs * Update local_site.rs * Update local_site_rate_limit.rs * Update local_user.rs * Update post.rs * Update private_message.rs * Update site.rs * Update post.rs * Update person.rs * Update private_message.rs * Update comment.rs * Update create.rs * Update leave_admin.rs * Update update.rs * Update remove.rs * Update add_admin.rs * Update verify_email.rs * Update mod.rs * Update mod.rs * Update undo_delete.rs * Update undo_delete.rs * Update utils.rs * Update feature.rs * Update delete.rs * Update lock.rs * Update create.rs * Update approve.rs * Update update.rs * Update lock_page.rs * Update block_user.rs * Update delete.rs * Update undo_block_user.rs * Update collection_remove.rs * Update post.rs * Update hide.rs * Update person.rs * Update remove.rs * Update post_view.rs * Update create.rs * Update remove.rs * Update collection_add.rs * Update community.rs * Update update.rs * Update post_aggregates.rs * Update update.rs * Update comment.rs * Update code_migrations.rs * Update registration_application_view.rs * Update update.rs * Update ban_person.rs * Update community.rs * Update delete.rs * Update delete.rs * Update delete.rs * Update person_aggregates.rs * Update save_settings.rs * Update distinguish.rs * Update mark_read.rs * Update site_aggregates.rs * Update create.rs * Fix * rerun ci * Update comment.rs * rerun ci * Update create.rs * Update create.rs * Update post_view.rs * rerun ci * Update undo_delete.rs * rerun ci
68 lines
2.1 KiB
Rust
68 lines
2.1 KiB
Rust
use activitypub_federation::config::Data;
|
|
use actix_web::web::Json;
|
|
use lemmy_api_common::{
|
|
context::LemmyContext,
|
|
private_message::{EditPrivateMessage, PrivateMessageResponse},
|
|
send_activity::{ActivityChannel, SendActivityData},
|
|
utils::{local_site_to_slur_regex, local_user_view_from_jwt, sanitize_html},
|
|
};
|
|
use lemmy_db_schema::{
|
|
source::{
|
|
local_site::LocalSite,
|
|
private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
|
},
|
|
traits::Crud,
|
|
utils::naive_now,
|
|
};
|
|
use lemmy_db_views::structs::PrivateMessageView;
|
|
use lemmy_utils::{
|
|
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
|
|
utils::{slurs::remove_slurs, validation::is_valid_body_field},
|
|
};
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
pub async fn update_private_message(
|
|
data: Json<EditPrivateMessage>,
|
|
context: Data<LemmyContext>,
|
|
) -> Result<Json<PrivateMessageResponse>, LemmyError> {
|
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
|
|
|
// Checking permissions
|
|
let private_message_id = data.private_message_id;
|
|
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
|
if local_user_view.person.id != orig_private_message.creator_id {
|
|
return Err(LemmyErrorType::EditPrivateMessageNotAllowed)?;
|
|
}
|
|
|
|
// Doing the update
|
|
let content = sanitize_html(&data.content);
|
|
let content = remove_slurs(&content, &local_site_to_slur_regex(&local_site));
|
|
is_valid_body_field(&Some(content.clone()), false)?;
|
|
|
|
let private_message_id = data.private_message_id;
|
|
PrivateMessage::update(
|
|
&mut context.pool(),
|
|
private_message_id,
|
|
&PrivateMessageUpdateForm {
|
|
content: Some(content),
|
|
updated: Some(Some(naive_now())),
|
|
..Default::default()
|
|
},
|
|
)
|
|
.await
|
|
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
|
|
|
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
|
|
|
ActivityChannel::submit_activity(
|
|
SendActivityData::UpdatePrivateMessage(view.clone()),
|
|
&context,
|
|
)
|
|
.await?;
|
|
|
|
Ok(Json(PrivateMessageResponse {
|
|
private_message_view: view,
|
|
}))
|
|
}
|