-use crate::{ApubObject, Crud};
+use crate::{ApubObject, Crud, DeleteableOrRemoveable};
+use chrono::NaiveDateTime;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, source::private_message::*, DbUrl, PersonId, PrivateMessageId};
-impl Crud<PrivateMessageForm, PrivateMessageId> for PrivateMessage {
+impl Crud for PrivateMessage {
+ type Form = PrivateMessageForm;
+ type IdType = PrivateMessageId;
fn read(conn: &PgConnection, private_message_id: PrivateMessageId) -> Result<Self, Error> {
use lemmy_db_schema::schema::private_message::dsl::*;
private_message.find(private_message_id).first::<Self>(conn)
}
}
-impl ApubObject<PrivateMessageForm> for PrivateMessage {
+impl ApubObject for PrivateMessage {
+ fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
+ None
+ }
+
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
where
Self: Sized,
.filter(ap_id.eq(object_id))
.first::<Self>(conn)
}
-
- fn upsert(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
- use lemmy_db_schema::schema::private_message::dsl::*;
- insert_into(private_message)
- .values(private_message_form)
- .on_conflict(ap_id)
- .do_update()
- .set(private_message_form)
- .get_result::<Self>(conn)
- }
}
pub trait PrivateMessage_ {
conn: &PgConnection,
for_recipient_id: PersonId,
) -> Result<Vec<PrivateMessage>, Error>;
+ fn upsert(
+ conn: &PgConnection,
+ private_message_form: &PrivateMessageForm,
+ ) -> Result<PrivateMessage, Error>;
}
impl PrivateMessage_ for PrivateMessage {
.set(read.eq(true))
.get_results::<Self>(conn)
}
+
+ fn upsert(
+ conn: &PgConnection,
+ private_message_form: &PrivateMessageForm,
+ ) -> Result<PrivateMessage, Error> {
+ use lemmy_db_schema::schema::private_message::dsl::*;
+ insert_into(private_message)
+ .values(private_message_form)
+ .on_conflict(ap_id)
+ .do_update()
+ .set(private_message_form)
+ .get_result::<Self>(conn)
+ }
+}
+
+impl DeleteableOrRemoveable for PrivateMessage {
+ fn blank_out_deleted_or_removed_info(mut self) -> Self {
+ self.content = "".into();
+ self
+ }
}
#[cfg(test)]