-pub(crate) mod comment;
-pub(crate) mod community;
-pub(crate) mod post;
-pub(crate) mod private_message;
-pub(crate) mod person;
-
-/// Trait for converting an object or actor into the respective ActivityPub type.
-#[async_trait::async_trait(?Send)]
-pub(crate) trait ToApub {
- type ApubType;
- async fn to_apub(&self, pool: &DbPool) -> Result<Self::ApubType, LemmyError>;
- fn to_tombstone(&self) -> Result<Tombstone, LemmyError>;
-}
-
-#[async_trait::async_trait(?Send)]
-pub(crate) trait FromApub {
- type ApubType;
- /// Converts an object from ActivityPub type to Lemmy internal type.
- ///
- /// * `apub` The object to read from
- /// * `context` LemmyContext which holds DB pool, HTTP client etc
- /// * `expected_domain` Domain where the object was received from
- async fn from_apub(
- apub: &Self::ApubType,
- context: &LemmyContext,
- expected_domain: Url,
- request_counter: &mut i32,
- ) -> Result<Self, LemmyError>
- where
- Self: Sized;
-}
-
-#[async_trait::async_trait(?Send)]
-pub(in crate::objects) trait FromApubToForm<ApubType> {
- async fn from_apub(
- apub: &ApubType,
- context: &LemmyContext,
- expected_domain: Url,
- request_counter: &mut i32,
- ) -> Result<Self, LemmyError>
- where
- Self: Sized;
-}
-
-/// Updated is actually the deletion time
-fn create_tombstone<T>(
- deleted: bool,
- object_id: Url,
- updated: Option<NaiveDateTime>,
- former_type: T,
-) -> Result<Tombstone, LemmyError>
-where
- T: ToString,
-{
- if deleted {
- if let Some(updated) = updated {
- let mut tombstone = Tombstone::new();
- tombstone.set_id(object_id);
- tombstone.set_former_type(former_type.to_string());
- tombstone.set_deleted(convert_datetime(updated));
- Ok(tombstone)
- } else {
- Err(anyhow!("Cant convert to tombstone because updated time was None.").into())
- }
+pub mod comment;
+pub mod community;
+pub mod instance;
+pub mod person;
+pub mod post;
+pub mod private_message;
+
+pub(crate) fn read_from_string_or_source(
+ content: &str,
+ media_type: &Option<MediaTypeMarkdownOrHtml>,
+ source: &Option<Source>,
+) -> String {
+ if let Some(s) = source {
+ // markdown sent by lemmy in source field
+ s.content.clone()
+ } else if media_type == &Some(MediaTypeMarkdownOrHtml::Markdown) {
+ // markdown sent by peertube in content field
+ content.to_string()