2021-03-18 20:25:21 +00:00
|
|
|
use crate::{schema::private_message, DbUrl, PersonId, PrivateMessageId};
|
2021-10-06 20:20:05 +00:00
|
|
|
use chrono::NaiveDateTime;
|
|
|
|
use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
|
|
|
|
use lemmy_apub_lib::traits::ApubObject;
|
|
|
|
use lemmy_utils::LemmyError;
|
2020-12-21 13:38:34 +00:00
|
|
|
use serde::Serialize;
|
2021-10-06 20:20:05 +00:00
|
|
|
use url::Url;
|
2020-12-21 13:38:34 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
|
|
|
#[table_name = "private_message"]
|
|
|
|
pub struct PrivateMessage {
|
2021-03-18 20:25:21 +00:00
|
|
|
pub id: PrivateMessageId,
|
|
|
|
pub creator_id: PersonId,
|
|
|
|
pub recipient_id: PersonId,
|
2020-12-21 13:38:34 +00:00
|
|
|
pub content: String,
|
|
|
|
pub deleted: bool,
|
|
|
|
pub read: bool,
|
|
|
|
pub published: chrono::NaiveDateTime,
|
|
|
|
pub updated: Option<chrono::NaiveDateTime>,
|
2021-03-02 12:41:48 +00:00
|
|
|
pub ap_id: DbUrl,
|
2020-12-21 13:38:34 +00:00
|
|
|
pub local: bool,
|
|
|
|
}
|
|
|
|
|
2021-03-20 20:59:07 +00:00
|
|
|
#[derive(Insertable, AsChangeset, Default)]
|
2020-12-21 13:38:34 +00:00
|
|
|
#[table_name = "private_message"]
|
|
|
|
pub struct PrivateMessageForm {
|
2021-03-18 20:25:21 +00:00
|
|
|
pub creator_id: PersonId,
|
|
|
|
pub recipient_id: PersonId,
|
2020-12-21 13:38:34 +00:00
|
|
|
pub content: String,
|
|
|
|
pub deleted: Option<bool>,
|
|
|
|
pub read: Option<bool>,
|
|
|
|
pub published: Option<chrono::NaiveDateTime>,
|
|
|
|
pub updated: Option<chrono::NaiveDateTime>,
|
2021-03-02 12:41:48 +00:00
|
|
|
pub ap_id: Option<DbUrl>,
|
2021-03-20 20:59:07 +00:00
|
|
|
pub local: Option<bool>,
|
2020-12-21 13:38:34 +00:00
|
|
|
}
|
2021-10-06 20:20:05 +00:00
|
|
|
|
|
|
|
impl ApubObject for PrivateMessage {
|
|
|
|
type DataType = PgConnection;
|
|
|
|
|
|
|
|
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
|
|
|
|
use crate::schema::private_message::dsl::*;
|
|
|
|
let object_id: DbUrl = object_id.into();
|
|
|
|
Ok(
|
|
|
|
private_message
|
|
|
|
.filter(ap_id.eq(object_id))
|
|
|
|
.first::<Self>(conn)
|
|
|
|
.ok(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|