objects::{private_message::Note, FromApub, ToApub},
ActorType,
};
+use activitystreams::{base::AnyBase, primitives::OneOrMany, unparsed::Unparsed};
use lemmy_api_common::blocking;
-use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler};
+use lemmy_apub_lib::{verify_domains_match, ActivityFields, ActivityHandler};
use lemmy_db_queries::Crud;
use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
use lemmy_utils::LemmyError;
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
+use serde::{Deserialize, Serialize};
use url::Url;
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrUpdatePrivateMessage {
+ #[serde(rename = "@context")]
+ pub context: OneOrMany<AnyBase>,
+ id: Url,
+ actor: Url,
to: Url,
+ cc: [Url; 0],
object: Note,
#[serde(rename = "type")]
kind: CreateOrUpdateType,
#[serde(flatten)]
- common: ActivityCommonFields,
+ pub unparsed: Unparsed,
}
impl CreateOrUpdatePrivateMessage {
let id = generate_activity_id(kind.clone())?;
let create_or_update = CreateOrUpdatePrivateMessage {
+ context: lemmy_context(),
+ id: id.clone(),
+ actor: actor.actor_id(),
to: recipient.actor_id(),
+ cc: [],
object: private_message.to_apub(context.pool()).await?,
kind,
- common: ActivityCommonFields {
- context: lemmy_context(),
- id: id.clone(),
- actor: actor.actor_id(),
- unparsed: Default::default(),
- },
+ unparsed: Default::default(),
};
let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
send_activity_new(context, &create_or_update, &id, actor, inbox, true).await
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- verify_activity(self.common())?;
- verify_person(&self.common.actor, context, request_counter).await?;
- verify_domains_match(&self.common.actor, self.object.id_unchecked())?;
+ verify_activity(self)?;
+ verify_person(&self.actor, context, request_counter).await?;
+ verify_domains_match(&self.actor, self.object.id_unchecked())?;
self.object.verify(context, request_counter).await?;
Ok(())
}
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let private_message =
- PrivateMessage::from_apub(&self.object, context, &self.common.actor, request_counter).await?;
+ PrivateMessage::from_apub(&self.object, context, &self.actor, request_counter).await?;
let notif_type = match self.kind {
CreateOrUpdateType::Create => UserOperationCrud::CreatePrivateMessage,
Ok(())
}
-
- fn common(&self) -> &ActivityCommonFields {
- &self.common
- }
}