1 use crate::{schema::private_message, DbUrl, PersonId, PrivateMessageId};
2 use chrono::NaiveDateTime;
3 use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
4 use lemmy_apub_lib::traits::ApubObject;
5 use lemmy_utils::LemmyError;
9 #[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
10 #[table_name = "private_message"]
11 pub struct PrivateMessage {
12 pub id: PrivateMessageId,
13 pub creator_id: PersonId,
14 pub recipient_id: PersonId,
18 pub published: chrono::NaiveDateTime,
19 pub updated: Option<chrono::NaiveDateTime>,
24 #[derive(Insertable, AsChangeset, Default)]
25 #[table_name = "private_message"]
26 pub struct PrivateMessageForm {
27 pub creator_id: PersonId,
28 pub recipient_id: PersonId,
30 pub deleted: Option<bool>,
31 pub read: Option<bool>,
32 pub published: Option<chrono::NaiveDateTime>,
33 pub updated: Option<chrono::NaiveDateTime>,
34 pub ap_id: Option<DbUrl>,
35 pub local: Option<bool>,
38 impl ApubObject for PrivateMessage {
39 type DataType = PgConnection;
41 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
45 fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
46 use crate::schema::private_message::dsl::*;
47 let object_id: DbUrl = object_id.into();
50 .filter(ap_id.eq(object_id))