2 fetcher::post_or_comment::PostOrComment,
4 mentions::MentionOrValue,
5 objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
6 protocol::{objects::LanguageTag, Source},
8 use activitypub_federation::{
9 core::object_id::ObjectId,
11 helpers::{deserialize_one_or_many, deserialize_skip_error},
12 values::MediaTypeMarkdownOrHtml,
15 use activitystreams_kinds::object::NoteType;
16 use chrono::{DateTime, FixedOffset};
17 use lemmy_db_schema::{source::post::Post, traits::Crud};
18 use lemmy_utils::error::LemmyError;
19 use lemmy_websocket::LemmyContext;
20 use serde::{Deserialize, Serialize};
21 use serde_with::skip_serializing_none;
25 #[skip_serializing_none]
26 #[derive(Clone, Debug, Deserialize, Serialize)]
27 #[serde(rename_all = "camelCase")]
29 pub(crate) r#type: NoteType,
30 pub(crate) id: ObjectId<ApubComment>,
31 pub(crate) attributed_to: ObjectId<ApubPerson>,
32 #[serde(deserialize_with = "deserialize_one_or_many")]
33 pub(crate) to: Vec<Url>,
34 #[serde(deserialize_with = "deserialize_one_or_many", default)]
35 pub(crate) cc: Vec<Url>,
36 pub(crate) content: String,
37 pub(crate) in_reply_to: ObjectId<PostOrComment>,
39 pub(crate) media_type: Option<MediaTypeMarkdownOrHtml>,
40 #[serde(deserialize_with = "deserialize_skip_error", default)]
41 pub(crate) source: Option<Source>,
42 pub(crate) published: Option<DateTime<FixedOffset>>,
43 pub(crate) updated: Option<DateTime<FixedOffset>>,
45 pub(crate) tag: Vec<MentionOrValue>,
47 pub(crate) distinguished: Option<bool>,
48 pub(crate) language: Option<LanguageTag>,
52 pub(crate) async fn get_parents(
54 context: &LemmyContext,
55 request_counter: &mut i32,
56 ) -> Result<(ApubPost, Option<ApubComment>), LemmyError> {
57 // Fetch parent comment chain in a box, otherwise it can cause a stack overflow.
58 let parent = Box::pin(
61 .dereference(context, local_instance(context).await, request_counter)
64 match parent.deref() {
65 PostOrComment::Post(p) => {
66 let post = p.deref().clone();
69 PostOrComment::Comment(c) => {
70 let post_id = c.post_id;
71 let post = Post::read(context.pool(), post_id).await?;
72 let comment = c.deref().clone();
73 Ok((post.into(), Some(comment)))