mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-22 19:01:32 +00:00
Finegal private messages
This commit is contained in:
parent
a5ac8eca3d
commit
502b5a1856
4 changed files with 26 additions and 17 deletions
|
@ -1,9 +1,10 @@
|
||||||
use actix_web::web::{Data, Json};
|
use actix_web::web::{Data, Json, Path};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
|
private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
newtypes::PrivateMessageId,
|
||||||
source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
|
@ -15,16 +16,16 @@ pub async fn mark_pm_as_read(
|
||||||
data: Json<MarkPrivateMessageAsRead>,
|
data: Json<MarkPrivateMessageAsRead>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
|
path: Path<PrivateMessageId>,
|
||||||
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = path.into_inner();
|
||||||
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||||
if local_user_view.person.id != orig_private_message.recipient_id {
|
if local_user_view.person.id != orig_private_message.recipient_id {
|
||||||
Err(LemmyErrorType::CouldntUpdatePrivateMessage)?
|
Err(LemmyErrorType::CouldntUpdatePrivateMessage)?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Doing the update
|
// Doing the update
|
||||||
let private_message_id = data.private_message_id;
|
|
||||||
let read = data.read;
|
let read = data.read;
|
||||||
PrivateMessage::update(
|
PrivateMessage::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::{Json, Path};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
newtypes::PrivateMessageId,
|
||||||
source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
|
@ -17,16 +18,16 @@ pub async fn delete_private_message(
|
||||||
data: Json<DeletePrivateMessage>,
|
data: Json<DeletePrivateMessage>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
|
path: Path<PrivateMessageId>,
|
||||||
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = path.into_inner();
|
||||||
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||||
if local_user_view.person.id != orig_private_message.creator_id {
|
if local_user_view.person.id != orig_private_message.creator_id {
|
||||||
Err(LemmyErrorType::EditPrivateMessageNotAllowed)?
|
Err(LemmyErrorType::EditPrivateMessageNotAllowed)?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Doing the update
|
// Doing the update
|
||||||
let private_message_id = data.private_message_id;
|
|
||||||
let deleted = data.deleted;
|
let deleted = data.deleted;
|
||||||
let private_message = PrivateMessage::update(
|
let private_message = PrivateMessage::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::{Json, Path};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
@ -8,6 +8,7 @@ use lemmy_api_common::{
|
||||||
utils::{get_url_blocklist, local_site_to_slur_regex, process_markdown},
|
utils::{get_url_blocklist, local_site_to_slur_regex, process_markdown},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
newtypes::PrivateMessageId,
|
||||||
source::{
|
source::{
|
||||||
local_site::LocalSite,
|
local_site::LocalSite,
|
||||||
private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
||||||
|
@ -25,11 +26,12 @@ pub async fn update_private_message(
|
||||||
data: Json<EditPrivateMessage>,
|
data: Json<EditPrivateMessage>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
|
path: Path<PrivateMessageId>,
|
||||||
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
||||||
|
let private_message_id = path.into_inner();
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
|
||||||
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||||
if local_user_view.person.id != orig_private_message.creator_id {
|
if local_user_view.person.id != orig_private_message.creator_id {
|
||||||
Err(LemmyErrorType::EditPrivateMessageNotAllowed)?
|
Err(LemmyErrorType::EditPrivateMessageNotAllowed)?
|
||||||
|
@ -41,7 +43,6 @@ pub async fn update_private_message(
|
||||||
let content = process_markdown(&data.content, &slur_regex, &url_blocklist, &context).await?;
|
let content = process_markdown(&data.content, &slur_regex, &url_blocklist, &context).await?;
|
||||||
is_valid_body_field(&content, false)?;
|
is_valid_body_field(&content, false)?;
|
||||||
|
|
||||||
let private_message_id = data.private_message_id;
|
|
||||||
PrivateMessage::update(
|
PrivateMessage::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
private_message_id,
|
private_message_id,
|
||||||
|
|
|
@ -258,15 +258,21 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
)
|
)
|
||||||
// Private Message
|
// Private Message
|
||||||
.service(
|
.service(
|
||||||
scope("/private_message")
|
scope("/direct-messages")
|
||||||
.route("/list", get().to(get_private_message))
|
.route("", get().to(get_private_message))
|
||||||
.route("", post().to(create_private_message))
|
.route("", post().to(create_private_message))
|
||||||
|
.service(
|
||||||
|
scope("/{message_id}")
|
||||||
.route("", put().to(update_private_message))
|
.route("", put().to(update_private_message))
|
||||||
.route("/delete", post().to(delete_private_message))
|
.route("", delete().to(delete_private_message))
|
||||||
.route("/mark_as_read", post().to(mark_pm_as_read))
|
.route("/mark-as-read", post().to(mark_pm_as_read))
|
||||||
.route("/report", post().to(create_pm_report))
|
.service(
|
||||||
.route("/report/resolve", put().to(resolve_pm_report))
|
scope("/reports")
|
||||||
.route("/report/list", get().to(list_pm_reports)),
|
.route("", get().to(list_pm_reports))
|
||||||
|
.route("", post().to(create_pm_report))
|
||||||
|
.service(scope("/{report_id}").route("", delete().to(resolve_pm_report))),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
// User
|
// User
|
||||||
.service(
|
.service(
|
||||||
|
|
Loading…
Reference in a new issue