-#[skip_serializing_none]
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ChatMessage {
- #[serde(rename = "@context")]
- context: OneOrMany<AnyBase>,
- r#type: ChatMessageType,
- id: Url,
- pub(crate) attributed_to: ObjectId<ApubPerson>,
- to: [ObjectId<ApubPerson>; 1],
- content: String,
- media_type: Option<MediaTypeHtml>,
- source: Option<Source>,
- published: Option<DateTime<FixedOffset>>,
- updated: Option<DateTime<FixedOffset>>,
- #[serde(flatten)]
- unparsed: Unparsed,
-}
-
-/// https://docs.pleroma.social/backend/development/ap_extensions/#chatmessages
-#[derive(Clone, Debug, Deserialize, Serialize)]
-pub enum ChatMessageType {
- ChatMessage,
-}
-
-impl ChatMessage {
- 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,
- request_counter: &mut i32,
- ) -> Result<(), LemmyError> {
- verify_domains_match(self.attributed_to.inner(), &self.id)?;
- let person = self
- .attributed_to
- .dereference(context, request_counter)
- .await?;
- if person.banned {
- return Err(anyhow!("Person is banned from site").into());
- }
- Ok(())
- }
-}
-