use lemmy_utils::{utils::convert_datetime, LemmyError};
use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
+use serde_with::skip_serializing_none;
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,
to: Url,
content: String,
}
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)
+ }
+
pub(crate) async fn verify(
&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<PrivateMessage, 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 recipient = get_or_fetch_and_upsert_person(¬e.to, context, request_counter).await?;
updated: note.updated.map(|u| u.to_owned().naive_local()),
deleted: None,
read: None,
- ap_id: Some(note.id.clone().into()),
+ ap_id,
local: Some(false),
};
Ok(