1 use crate::fetcher::person::get_or_fetch_and_upsert_person;
4 object::{kind::ImageType, Tombstone, TombstoneExt},
7 use chrono::NaiveDateTime;
8 use lemmy_apub_lib::values::MediaTypeMarkdown;
9 use lemmy_db_queries::DbPool;
10 use lemmy_utils::{utils::convert_datetime, LemmyError};
11 use lemmy_websocket::LemmyContext;
14 pub(crate) mod comment;
15 pub(crate) mod community;
16 pub(crate) mod person;
18 pub(crate) mod private_message;
20 /// Trait for converting an object or actor into the respective ActivityPub type.
21 #[async_trait::async_trait(?Send)]
22 pub(crate) trait ToApub {
24 async fn to_apub(&self, pool: &DbPool) -> Result<Self::ApubType, LemmyError>;
25 fn to_tombstone(&self) -> Result<Tombstone, LemmyError>;
28 #[async_trait::async_trait(?Send)]
29 pub(crate) trait FromApub {
31 /// Converts an object from ActivityPub type to Lemmy internal type.
33 /// * `apub` The object to read from
34 /// * `context` LemmyContext which holds DB pool, HTTP client etc
35 /// * `expected_domain` Domain where the object was received from. None in case of mod action.
36 /// * `mod_action_allowed` True if the object can be a mod activity, ignore `expected_domain` in this case
38 apub: &Self::ApubType,
39 context: &LemmyContext,
40 expected_domain: &Url,
41 request_counter: &mut i32,
42 ) -> Result<Self, LemmyError>
47 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
48 #[serde(rename_all = "camelCase")]
51 media_type: MediaTypeMarkdown,
54 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
55 #[serde(rename_all = "camelCase")]
56 pub struct ImageObject {
57 #[serde(rename = "type")]
62 /// Updated is actually the deletion time
63 fn create_tombstone<T>(
66 updated: Option<NaiveDateTime>,
68 ) -> Result<Tombstone, LemmyError>
73 if let Some(updated) = updated {
74 let mut tombstone = Tombstone::new();
75 tombstone.set_id(object_id);
76 tombstone.set_former_type(former_type.to_string());
77 tombstone.set_deleted(convert_datetime(updated));
80 Err(anyhow!("Cant convert to tombstone because updated time was None.").into())
83 Err(anyhow!("Cant convert object to tombstone if it wasnt deleted").into())