-use crate::activities::{
- private_message::{delete::DeletePrivateMessage, send_websocket_message},
- verify_activity,
- verify_person,
+use crate::{
+ activities::{
+ generate_activity_id,
+ private_message::delete::DeletePrivateMessage,
+ verify_activity,
+ verify_person,
+ },
+ activity_queue::send_activity_new,
+ extensions::context::lemmy_context,
+ fetcher::object_id::ObjectId,
+ ActorType,
};
-use activitystreams::activity::kind::UndoType;
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::{
- verify_domains_match,
- verify_urls_match,
- ActivityCommonFields,
- ActivityHandler,
+use activitystreams::{
+ activity::kind::UndoType,
+ base::AnyBase,
+ primitives::OneOrMany,
+ unparsed::Unparsed,
};
-use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject};
-use lemmy_db_schema::source::private_message::PrivateMessage;
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::{verify_domains_match, verify_urls_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 UndoDeletePrivateMessage {
- to: Url,
+ actor: ObjectId<Person>,
+ to: ObjectId<Person>,
object: DeletePrivateMessage,
#[serde(rename = "type")]
kind: UndoType,
+ id: Url,
+ #[serde(rename = "@context")]
+ context: OneOrMany<AnyBase>,
#[serde(flatten)]
- common: ActivityCommonFields,
+ unparsed: Unparsed,
+}
+
+impl UndoDeletePrivateMessage {
+ pub async fn send(
+ actor: &Person,
+ pm: &PrivateMessage,
+ context: &LemmyContext,
+ ) -> Result<(), LemmyError> {
+ let recipient_id = pm.recipient_id;
+ let recipient =
+ blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
+
+ let object = DeletePrivateMessage::new(actor, pm)?;
+ let id = generate_activity_id(UndoType::Undo)?;
+ let undo = UndoDeletePrivateMessage {
+ actor: ObjectId::new(actor.actor_id()),
+ to: ObjectId::new(recipient.actor_id()),
+ object,
+ kind: UndoType::Undo,
+ id: id.clone(),
+ context: lemmy_context(),
+ unparsed: Default::default(),
+ };
+ let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
+ send_activity_new(context, &undo, &id, actor, inbox, true).await
+ }
}
#[async_trait::async_trait(?Send)]
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- verify_activity(self.common())?;
- verify_person(&self.common.actor, context, request_counter).await?;
- verify_urls_match(&self.common.actor, &self.object.common.actor)?;
- verify_domains_match(&self.common.actor, &self.object.object)?;
+ verify_activity(self)?;
+ verify_person(&self.actor, context, request_counter).await?;
+ verify_urls_match(self.actor(), self.object.actor())?;
+ verify_domains_match(self.actor(), &self.object.object)?;
self.object.verify(context, request_counter).await?;
Ok(())
}
async fn receive(
- &self,
+ self,
context: &LemmyContext,
_request_counter: &mut i32,
) -> Result<(), LemmyError> {
})
.await??;
- send_websocket_message(
+ send_pm_ws_message(
deleted_private_message.id,
UserOperationCrud::EditPrivateMessage,
+ None,
context,
)
.await?;
Ok(())
}
-
- fn common(&self) -> &ActivityCommonFields {
- &self.common
- }
}