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;
6 use serde::{Deserialize, Serialize};
10 Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize,
12 #[table_name = "private_message"]
13 pub struct PrivateMessage {
14 pub id: PrivateMessageId,
15 pub creator_id: PersonId,
16 pub recipient_id: PersonId,
20 pub published: chrono::NaiveDateTime,
21 pub updated: Option<chrono::NaiveDateTime>,
26 #[derive(Insertable, AsChangeset, Default)]
27 #[table_name = "private_message"]
28 pub struct PrivateMessageForm {
29 pub creator_id: PersonId,
30 pub recipient_id: PersonId,
32 pub deleted: Option<bool>,
33 pub read: Option<bool>,
34 pub published: Option<chrono::NaiveDateTime>,
35 pub updated: Option<chrono::NaiveDateTime>,
36 pub ap_id: Option<DbUrl>,
37 pub local: Option<bool>,
40 impl ApubObject for PrivateMessage {
41 type DataType = PgConnection;
43 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
47 fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
48 use crate::schema::private_message::dsl::*;
49 let object_id: DbUrl = object_id.into();
52 .filter(ap_id.eq(object_id))