get_local_user_view_from_jwt,
is_mod_or_admin,
};
-use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
+use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove, DeletableObjects};
use lemmy_db_schema::{
source::{
comment::Comment,
.await?
.map_err(|e| ApiError::err("couldnt_update_comment", e))?;
+ let post_id = updated_comment.post_id;
+ let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+ let recipient_ids = send_local_notifs(
+ vec![],
+ &updated_comment,
+ &local_user_view.person,
+ &post,
+ false,
+ context,
+ )
+ .await?;
+
// Send the apub message
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_comment.post.community_id)
send_apub_delete(
&local_user_view.person.clone().into(),
&community.clone().into(),
- updated_comment.ap_id.clone().into(),
+ DeletableObjects::Comment(Box::new(updated_comment.into())),
deleted,
context,
)
.await?;
- let post_id = updated_comment.post_id;
- let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
- let recipient_ids = send_local_notifs(
- vec![],
- &updated_comment,
- &local_user_view.person,
- &post,
- false,
- context,
- )
- .await?;
-
send_comment_ws_message(
data.comment_id,
UserOperationCrud::DeleteComment,
})
.await??;
+ let post_id = updated_comment.post_id;
+ let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+ let recipient_ids = send_local_notifs(
+ vec![],
+ &updated_comment,
+ &local_user_view.person.clone(),
+ &post,
+ false,
+ context,
+ )
+ .await?;
+
// Send the apub message
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_comment.post.community_id)
send_apub_remove(
&local_user_view.person.clone().into(),
&community.into(),
- updated_comment.ap_id.clone().into(),
+ DeletableObjects::Comment(Box::new(updated_comment.into())),
data.reason.clone().unwrap_or_else(|| "".to_string()),
removed,
context,
)
.await?;
- let post_id = updated_comment.post_id;
- let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
- let recipient_ids = send_local_notifs(
- vec![],
- &updated_comment,
- &local_user_view.person.clone(),
- &post,
- false,
- context,
- )
- .await?;
-
send_comment_ws_message(
data.comment_id,
UserOperationCrud::RemoveComment,
use crate::PerformCrud;
use actix_web::web::Data;
use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin};
-use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
+use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove, DeletableObjects};
use lemmy_db_schema::{
source::{
community::Community,
send_apub_delete(
&local_user_view.person.clone().into(),
&updated_community.clone().into(),
- updated_community.actor_id.clone().into(),
+ DeletableObjects::Community(Box::new(updated_community.into())),
deleted,
context,
)
send_apub_remove(
&local_user_view.person.clone().into(),
&updated_community.clone().into(),
- updated_community.actor_id.clone().into(),
+ DeletableObjects::Community(Box::new(updated_community.into())),
data.reason.clone().unwrap_or_else(|| "".to_string()),
removed,
context,
is_mod_or_admin,
post::*,
};
-use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
+use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove, DeletableObjects};
use lemmy_db_schema::{
source::{
community::Community,
send_apub_delete(
&local_user_view.person.clone().into(),
&community.into(),
- updated_post.ap_id.into(),
+ DeletableObjects::Post(Box::new(updated_post.into())),
deleted,
context,
)
send_apub_remove(
&local_user_view.person.clone().into(),
&community.into(),
- updated_post.ap_id.into(),
+ DeletableObjects::Post(Box::new(updated_post.into())),
data.reason.clone().unwrap_or_else(|| "".to_string()),
removed,
context,
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
- "object": "http://ds9.lemmy.ml/post/1",
+ "object": {
+ "id": "http://ds9.lemmy.ml/post/1",
+ "type": "Tombstone"
+ },
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
- "object": "http://ds9.lemmy.ml/comment/1",
+ "object": {
+ "id": "http://ds9.lemmy.ml/comment/1",
+ "type": "Tombstone"
+ },
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
- "object": "http://ds9.lemmy.ml/post/1",
+ "object": {
+ "id": "http://ds9.lemmy.ml/post/1",
+ "type": "Tombstone"
+ },
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
- "object": "http://ds9.lemmy.ml/comment/1",
+ "object": {
+ "id": "http://ds9.lemmy.ml/comment/1",
+ "type": "Tombstone"
+ },
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- verify_is_public(&self.to, &self.cc)?;
+ verify_is_public(&self.to, &[])?;
verify_activity(&self.id, self.actor.inner(), &context.settings())?;
let community = self.get_community(context, request_counter).await?;
verify_delete_activity(
- &self.object,
+ &self.object.id,
&self.actor,
&community,
self.summary.is_some(),
} else {
Some(reason)
};
- receive_remove_action(&self.actor, &self.object, reason, context, request_counter).await
+ receive_remove_action(
+ &self.actor,
+ &self.object.id,
+ reason,
+ context,
+ request_counter,
+ )
+ .await
} else {
- receive_delete_action(&self.object, &self.actor, true, context, request_counter).await
+ receive_delete_action(&self.object.id, &self.actor, true, context, request_counter).await
}
}
}
impl Delete {
pub(in crate::activities::deletion) fn new(
actor: &ApubPerson,
- community: &ApubCommunity,
- object_id: Url,
+ object: DeletableObjects,
summary: Option<String>,
context: &LemmyContext,
) -> Result<Delete, LemmyError> {
Ok(Delete {
actor: ObjectId::new(actor.actor_id()),
to: vec![public()],
- object: object_id,
- cc: vec![community.actor_id()],
+ object: object.to_tombstone()?,
kind: DeleteType::Delete,
summary,
id: generate_activity_id(
pub(in crate::activities::deletion) async fn send(
actor: &ApubPerson,
community: &ApubCommunity,
- object_id: Url,
+ object: DeletableObjects,
summary: Option<String>,
context: &LemmyContext,
) -> Result<(), LemmyError> {
- let delete = Delete::new(actor, community, object_id, summary, context)?;
+ let delete = Delete::new(actor, object, summary, context)?;
let delete_id = delete.id.clone();
let activity = AnnouncableActivities::Delete(delete);
context: &LemmyContext,
_request_counter: &mut i32,
) -> Result<ApubCommunity, LemmyError> {
- let community_id = match DeletableObjects::read_from_db(&self.object, context).await? {
+ let community_id = match DeletableObjects::read_from_db(&self.object.id, context).await? {
DeletableObjects::Community(c) => c.id,
DeletableObjects::Comment(c) => {
let post = blocking(context.pool(), move |conn| Post::read(conn, c.post_id)).await??;
use crate::{
activities::{verify_mod_action, verify_person_in_community},
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
- protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
+ protocol::{
+ activities::deletion::{delete::Delete, undo_delete::UndoDelete},
+ objects::tombstone::Tombstone,
+ },
};
use lemmy_api_common::blocking;
-use lemmy_apub_lib::{
- object_id::ObjectId,
- traits::{ActorType, ApubObject},
- verify::verify_domains_match,
-};
+use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject, verify::verify_domains_match};
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
use lemmy_utils::LemmyError;
use lemmy_websocket::{
pub async fn send_apub_delete(
actor: &ApubPerson,
community: &ApubCommunity,
- object_id: Url,
+ object: DeletableObjects,
deleted: bool,
context: &LemmyContext,
) -> Result<(), LemmyError> {
if deleted {
- Delete::send(actor, community, object_id, None, context).await
+ Delete::send(actor, community, object, None, context).await
} else {
- UndoDelete::send(actor, community, object_id, None, context).await
+ UndoDelete::send(actor, community, object, None, context).await
}
}
pub async fn send_apub_remove(
actor: &ApubPerson,
community: &ApubCommunity,
- object_id: Url,
+ object: DeletableObjects,
reason: String,
removed: bool,
context: &LemmyContext,
) -> Result<(), LemmyError> {
if removed {
- Delete::send(actor, community, object_id, Some(reason), context).await
+ Delete::send(actor, community, object, Some(reason), context).await
} else {
- UndoDelete::send(actor, community, object_id, Some(reason), context).await
+ UndoDelete::send(actor, community, object, Some(reason), context).await
}
}
}
Err(diesel::NotFound.into())
}
+
+ pub(crate) fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
+ match self {
+ DeletableObjects::Community(c) => c.to_tombstone(),
+ DeletableObjects::Comment(c) => c.to_tombstone(),
+ DeletableObjects::Post(p) => p.to_tombstone(),
+ }
+ }
}
pub(in crate::activities) async fn verify_delete_activity(
DeletableObjects::Community(community) => {
if community.local {
let mod_ = actor.dereference(context, request_counter).await?;
- let object = community.actor_id();
+ let object = DeletableObjects::Community(community.clone());
send_apub_delete(&mod_, &community.clone(), object, true, context).await?;
}
self.object.verify(context, request_counter).await?;
let community = self.get_community(context, request_counter).await?;
verify_delete_activity(
- &self.object.object,
+ &self.object.object.id,
&self.actor,
&community,
self.object.summary.is_some(),
request_counter: &mut i32,
) -> Result<(), LemmyError> {
if self.object.summary.is_some() {
- UndoDelete::receive_undo_remove_action(&self.object.object, context).await
+ UndoDelete::receive_undo_remove_action(&self.object.object.id, context).await
} else {
receive_delete_action(
- &self.object.object,
+ &self.object.object.id,
&self.actor,
false,
context,
pub(in crate::activities::deletion) async fn send(
actor: &ApubPerson,
community: &ApubCommunity,
- object_id: Url,
+ object: DeletableObjects,
summary: Option<String>,
context: &LemmyContext,
) -> Result<(), LemmyError> {
- let object = Delete::new(actor, community, object_id, summary, context)?;
+ let object = Delete::new(actor, object, summary, context)?;
let id = generate_activity_id(
UndoType::Undo,
}
pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> Result<(), LemmyError> {
- if !to.contains(&public()) && !cc.contains(&public()) {
+ if ![to, cc].iter().any(|set| set.contains(&public())) {
return Err(anyhow!("Object is not public").into());
}
Ok(())
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- Ok(Tombstone::new(
- NoteType::Note,
- self.updated.unwrap_or(self.published),
- ))
+ Ok(Tombstone::new(self.ap_id.clone().into()))
}
async fn verify(
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- Ok(Tombstone::new(
- GroupType::Group,
- self.updated.unwrap_or(self.published),
- ))
+ Ok(Tombstone::new(self.actor_id()))
}
async fn verify(
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- Ok(Tombstone::new(
- PageType::Page,
- self.updated.unwrap_or(self.published),
- ))
+ Ok(Tombstone::new(self.ap_id.clone().into()))
}
async fn verify(
-use crate::objects::person::ApubPerson;
+use crate::{objects::person::ApubPerson, protocol::objects::tombstone::Tombstone};
use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize};
pub struct Delete {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
- pub(crate) object: Url,
- pub(crate) cc: Vec<Url>,
+ pub(crate) object: Tombstone,
#[serde(rename = "type")]
pub(crate) kind: DeleteType,
/// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
#[actix_rt::test]
#[serial]
- async fn test_parse_lemmy_voting() {
+ async fn test_parse_lemmy_deletion() {
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/remove_note.json");
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/delete_page.json");
use activitystreams::object::kind::TombstoneType;
-use chrono::{DateTime, FixedOffset, NaiveDateTime};
-use lemmy_utils::utils::convert_datetime;
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 Tombstone {
+ pub(crate) id: Url,
#[serde(rename = "type")]
kind: TombstoneType,
- former_type: String,
- deleted: DateTime<FixedOffset>,
}
impl Tombstone {
- pub fn new<T: ToString>(former_type: T, updated_time: NaiveDateTime) -> Tombstone {
+ pub fn new(id: Url) -> Tombstone {
Tombstone {
+ id,
kind: TombstoneType::Tombstone,
- former_type: former_type.to_string(),
- deleted: convert_datetime(updated_time),
}
}
}