lemmy/crates/db_schema/src/impls/private_message_report.rs
Dessalines 231cce9350
Cleanup post action forms (#5197)
* Removing a few SuccessResponses for PostHide and MarkPostAsRead.

- This also removes the pointless multiple post_ids. These can be done
  as individual calls on the front end anyway.
- Fixes #4755

* Fixing federation tests.

* Upgrading lemmy-js-client deps.

* Add ability to mark several posts as read.

Context:

- https://github.com/LemmyNet/lemmy/pull/5043
- https://github.com/LemmyNet/lemmy/issues/4755
- https://github.com/LemmyNet/lemmy/pull/5160

* Simplifying forms.

* Fixing forms.

* Cleanup post action forms by using derive_new defaults.

- Fixes #5195

* Fix ntfy to notify on success builds also.

* Removing pointless naive_now function.

* Running taplo fmt.
2024-11-15 11:21:08 +01:00

74 lines
1.9 KiB
Rust

use crate::{
newtypes::{PersonId, PrivateMessageId, PrivateMessageReportId},
schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
traits::Reportable,
utils::{get_conn, DbPool},
};
use chrono::Utc;
use diesel::{
dsl::{insert_into, update},
result::Error,
ExpressionMethods,
QueryDsl,
};
use diesel_async::RunQueryDsl;
#[async_trait]
impl Reportable for PrivateMessageReport {
type Form = PrivateMessageReportForm;
type IdType = PrivateMessageReportId;
type ObjectIdType = PrivateMessageId;
async fn report(
pool: &mut DbPool<'_>,
pm_report_form: &PrivateMessageReportForm,
) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(private_message_report)
.values(pm_report_form)
.get_result::<Self>(conn)
.await
}
async fn resolve(
pool: &mut DbPool<'_>,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
update(private_message_report.find(report_id))
.set((
resolved.eq(true),
resolver_id.eq(by_resolver_id),
updated.eq(Utc::now()),
))
.execute(conn)
.await
}
// TODO: this is unused because private message doesn't have remove handler
async fn resolve_all_for_object(
_pool: &mut DbPool<'_>,
_pm_id_: PrivateMessageId,
_by_resolver_id: PersonId,
) -> Result<usize, Error> {
Err(Error::NotFound)
}
async fn unresolve(
pool: &mut DbPool<'_>,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
update(private_message_report.find(report_id))
.set((
resolved.eq(false),
resolver_id.eq(by_resolver_id),
updated.eq(Utc::now()),
))
.execute(conn)
.await
}
}