use crate::{
- activities::{
- generate_activity_id,
- private_message::send_websocket_message,
- verify_activity,
- verify_person,
- },
+ activities::{generate_activity_id, verify_activity, verify_person},
activity_queue::send_activity_new,
extensions::context::lemmy_context,
+ fetcher::object_id::ObjectId,
ActorType,
};
-use activitystreams::activity::kind::DeleteType;
+use activitystreams::{
+ activity::kind::DeleteType,
+ 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::{source::private_message::PrivateMessage_, ApubObject, Crud};
use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
use lemmy_utils::LemmyError;
-use lemmy_websocket::{LemmyContext, UserOperationCrud};
+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 DeletePrivateMessage {
- pub(in crate::activities::private_message) to: Url,
+ actor: ObjectId<Person>,
+ to: ObjectId<Person>,
pub(in crate::activities::private_message) object: Url,
#[serde(rename = "type")]
- pub(in crate::activities::private_message) kind: DeleteType,
+ kind: DeleteType,
+ id: Url,
+ #[serde(rename = "@context")]
+ context: OneOrMany<AnyBase>,
#[serde(flatten)]
- pub(in crate::activities::private_message) common: ActivityCommonFields,
+ unparsed: Unparsed,
}
impl DeletePrivateMessage {
+ pub(in crate::activities::private_message) fn new(
+ actor: &Person,
+ pm: &PrivateMessage,
+ ) -> Result<DeletePrivateMessage, LemmyError> {
+ Ok(DeletePrivateMessage {
+ actor: ObjectId::new(actor.actor_id()),
+ to: ObjectId::new(actor.actor_id()),
+ object: pm.ap_id.clone().into(),
+ kind: DeleteType::Delete,
+ id: generate_activity_id(DeleteType::Delete)?,
+ context: lemmy_context(),
+ unparsed: Default::default(),
+ })
+ }
pub async fn send(
actor: &Person,
pm: &PrivateMessage,
context: &LemmyContext,
) -> Result<(), LemmyError> {
+ let delete = DeletePrivateMessage::new(actor, pm)?;
+ let delete_id = delete.id.clone();
+
let recipient_id = pm.recipient_id;
let recipient =
blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
-
- let id = generate_activity_id(DeleteType::Delete)?;
- let delete = DeletePrivateMessage {
- to: actor.actor_id(),
- object: pm.ap_id.clone().into(),
- kind: DeleteType::Delete,
- common: ActivityCommonFields {
- context: lemmy_context(),
- id: id.clone(),
- actor: actor.actor_id(),
- unparsed: Default::default(),
- },
- };
let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
- send_activity_new(context, &delete, &id, actor, inbox, true).await
+ send_activity_new(context, &delete, &delete_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)?;
+ verify_activity(self)?;
+ verify_person(&self.actor, context, request_counter).await?;
+ verify_domains_match(self.actor.inner(), &self.object)?;
Ok(())
}
})
.await??;
- send_websocket_message(
+ send_pm_ws_message(
deleted_private_message.id,
UserOperationCrud::DeletePrivateMessage,
+ None,
context,
)
.await?;
Ok(())
}
-
- fn common(&self) -> &ActivityCommonFields {
- &self.common
- }
}