2 fetcher::post_or_comment::PostOrComment,
3 mentions::MentionOrValue,
4 objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
7 use activitystreams_kinds::object::NoteType;
8 use chrono::{DateTime, FixedOffset};
9 use lemmy_api_common::utils::blocking;
10 use lemmy_apub_lib::{object_id::ObjectId, values::MediaTypeMarkdownOrHtml};
11 use lemmy_db_schema::{newtypes::CommentId, source::post::Post, traits::Crud};
12 use lemmy_utils::LemmyError;
13 use lemmy_websocket::LemmyContext;
14 use serde::{Deserialize, Serialize};
15 use serde_with::skip_serializing_none;
19 #[skip_serializing_none]
20 #[derive(Clone, Debug, Deserialize, Serialize)]
21 #[serde(rename_all = "camelCase")]
23 pub(crate) r#type: NoteType,
24 pub(crate) id: ObjectId<ApubComment>,
25 pub(crate) attributed_to: ObjectId<ApubPerson>,
26 #[serde(deserialize_with = "crate::deserialize_one_or_many")]
27 pub(crate) to: Vec<Url>,
28 #[serde(deserialize_with = "crate::deserialize_one_or_many", default)]
29 pub(crate) cc: Vec<Url>,
30 pub(crate) content: String,
31 pub(crate) in_reply_to: ObjectId<PostOrComment>,
33 pub(crate) media_type: Option<MediaTypeMarkdownOrHtml>,
34 #[serde(deserialize_with = "crate::deserialize_skip_error", default)]
35 pub(crate) source: Option<Source>,
36 pub(crate) published: Option<DateTime<FixedOffset>>,
37 pub(crate) updated: Option<DateTime<FixedOffset>>,
39 pub(crate) tag: Vec<MentionOrValue>,
43 pub(crate) async fn get_parents(
45 context: &LemmyContext,
46 request_counter: &mut i32,
47 ) -> Result<(ApubPost, Option<CommentId>), LemmyError> {
48 // Fetch parent comment chain in a box, otherwise it can cause a stack overflow.
49 let parent = Box::pin(
52 .dereference(context, context.client(), request_counter)
55 match parent.deref() {
56 PostOrComment::Post(p) => {
57 // Workaround because I cant figure out how to get the post out of the box (and we dont
58 // want to stackoverflow in a deep comment hierarchy).
60 let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
61 Ok((post.into(), None))
63 PostOrComment::Comment(c) => {
64 let post_id = c.post_id;
65 let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
66 Ok((post.into(), Some(c.id)))