};
use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
+use serde_with::skip_serializing_none;
use std::ops::Deref;
use url::Url;
+#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Note {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
r#type: NoteType,
- pub(crate) id: Url,
+ id: Url,
pub(crate) attributed_to: Url,
/// Indicates that the object is publicly readable. Unlike [`Post.to`], this one doesn't contain
/// the community ID, as it would be incompatible with Pleroma (and we can get the community from
}
impl Note {
+ pub(crate) fn id_unchecked(&self) -> &Url {
+ &self.id
+ }
+ pub(crate) fn id(&self, expected_domain: &Url) -> Result<&Url, LemmyError> {
+ verify_domains_match(&self.id, expected_domain)?;
+ Ok(&self.id)
+ }
+
async fn get_parents(
&self,
context: &LemmyContext,
async fn from_apub(
note: &Note,
context: &LemmyContext,
- _expected_domain: Url,
+ expected_domain: &Url,
request_counter: &mut i32,
- _mod_action_allowed: bool,
) -> Result<Comment, LemmyError> {
+ let ap_id = Some(note.id(expected_domain)?.clone().into());
let creator =
get_or_fetch_and_upsert_person(¬e.attributed_to, context, request_counter).await?;
let (post, parent_comment_id) = note.get_parents(context, request_counter).await?;
published: Some(note.published.naive_local()),
updated: note.updated.map(|u| u.to_owned().naive_local()),
deleted: None,
- ap_id: Some(note.id.clone().into()),
+ ap_id,
local: Some(false),
};
Ok(blocking(context.pool(), move |conn| Comment::upsert(conn, &form)).await??)