Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge different delete activities for better compatibility (fixes #2066) #2073

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 37 additions & 30 deletions crates/api_crud/src/comment/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use lemmy_api_common::{
get_local_user_view_from_jwt,
is_mod_or_admin,
};
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove, DeletableObjects};
use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
use lemmy_db_schema::{
source::{
comment::Comment,
Expand Down Expand Up @@ -83,30 +83,34 @@ impl PerformCrud for DeleteComment {
)
.await?;

let res = send_comment_ws_message(
data.comment_id,
UserOperationCrud::DeleteComment,
websocket_id,
None, // TODO a comment delete might clear forms?
Some(local_user_view.person.id),
recipient_ids,
context,
)
.await?;

// Send the apub message
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_comment.post.community_id)
})
.await??;
send_apub_delete(
&local_user_view.person.clone().into(),
&community.clone().into(),
DeletableObjects::Comment(Box::new(updated_comment.into())),
let deletable = DeletableObjects::Comment(Box::new(updated_comment.clone().into()));
send_apub_delete_in_community(
local_user_view.person,
community,
deletable,
None,
deleted,
context,
)
.await?;

send_comment_ws_message(
data.comment_id,
UserOperationCrud::DeleteComment,
websocket_id,
None, // TODO a comment delete might clear forms?
Some(local_user_view.person.id),
recipient_ids,
context,
)
.await
Ok(res)
}
}

Expand Down Expand Up @@ -178,30 +182,33 @@ impl PerformCrud for RemoveComment {
)
.await?;

let res = send_comment_ws_message(
data.comment_id,
UserOperationCrud::RemoveComment,
websocket_id,
None, // TODO maybe this might clear other forms
Some(local_user_view.person.id),
recipient_ids,
context,
)
.await?;

// Send the apub message
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_comment.post.community_id)
})
.await??;
send_apub_remove(
&local_user_view.person.clone().into(),
&community.into(),
DeletableObjects::Comment(Box::new(updated_comment.into())),
data.reason.clone().unwrap_or_else(|| "".to_string()),
let deletable = DeletableObjects::Comment(Box::new(updated_comment.clone().into()));
send_apub_delete_in_community(
local_user_view.person,
community,
deletable,
data.reason.clone().or_else(|| Some("".to_string())),
removed,
context,
)
.await?;

send_comment_ws_message(
data.comment_id,
UserOperationCrud::RemoveComment,
websocket_id,
None, // TODO maybe this might clear other forms
Some(local_user_view.person.id),
recipient_ids,
context,
)
.await
Ok(res)
}
}
58 changes: 32 additions & 26 deletions crates/api_crud/src/community/delete.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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, DeletableObjects};
use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
use lemmy_db_schema::{
source::{
community::Community,
Expand Down Expand Up @@ -49,24 +49,28 @@ impl PerformCrud for DeleteCommunity {
.map_err(LemmyError::from)
.map_err(|e| e.with_message("couldnt_update_community"))?;

// Send apub messages
send_apub_delete(
&local_user_view.person.clone().into(),
&updated_community.clone().into(),
DeletableObjects::Community(Box::new(updated_community.into())),
deleted,
context,
)
.await?;

send_community_ws_message(
let res = send_community_ws_message(
data.community_id,
UserOperationCrud::DeleteCommunity,
websocket_id,
Some(local_user_view.person.id),
context,
)
.await
.await?;

// Send apub messages
let deletable = DeletableObjects::Community(Box::new(updated_community.clone().into()));
send_apub_delete_in_community(
local_user_view.person,
updated_community,
deletable,
None,
deleted,
context,
)
.await?;

Ok(res)
}
}

Expand Down Expand Up @@ -111,24 +115,26 @@ impl PerformCrud for RemoveCommunity {
})
.await??;

// Apub messages
send_apub_remove(
&local_user_view.person.clone().into(),
&updated_community.clone().into(),
DeletableObjects::Community(Box::new(updated_community.into())),
data.reason.clone().unwrap_or_else(|| "".to_string()),
removed,
context,
)
.await?;

send_community_ws_message(
let res = send_community_ws_message(
data.community_id,
UserOperationCrud::RemoveCommunity,
websocket_id,
Some(local_user_view.person.id),
context,
)
.await
.await?;

// Apub messages
let deletable = DeletableObjects::Community(Box::new(updated_community.clone().into()));
send_apub_delete_in_community(
local_user_view.person,
updated_community,
deletable,
data.reason.clone().or_else(|| Some("".to_string())),
removed,
context,
)
.await?;
Ok(res)
}
}
61 changes: 33 additions & 28 deletions crates/api_crud/src/post/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use lemmy_api_common::{
is_mod_or_admin,
post::*,
};
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove, DeletableObjects};
use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
use lemmy_db_schema::{
source::{
community::Community,
Expand Down Expand Up @@ -63,28 +63,31 @@ impl PerformCrud for DeletePost {
})
.await??;

let res = send_post_ws_message(
data.post_id,
UserOperationCrud::DeletePost,
websocket_id,
Some(local_user_view.person.id),
context,
)
.await?;

// apub updates
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_post.community_id)
})
.await??;
send_apub_delete(
&local_user_view.person.clone().into(),
&community.into(),
DeletableObjects::Post(Box::new(updated_post.into())),
let deletable = DeletableObjects::Post(Box::new(updated_post.into()));
send_apub_delete_in_community(
local_user_view.person,
community,
deletable,
None,
deleted,
context,
)
.await?;

send_post_ws_message(
data.post_id,
UserOperationCrud::DeletePost,
websocket_id,
Some(local_user_view.person.id),
context,
)
.await
Ok(res)
}
}

Expand Down Expand Up @@ -140,28 +143,30 @@ impl PerformCrud for RemovePost {
})
.await??;

let res = send_post_ws_message(
data.post_id,
UserOperationCrud::RemovePost,
websocket_id,
Some(local_user_view.person.id),
context,
)
.await?;

// apub updates
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_post.community_id)
})
.await??;
send_apub_remove(
&local_user_view.person.clone().into(),
&community.into(),
DeletableObjects::Post(Box::new(updated_post.into())),
data.reason.clone().unwrap_or_else(|| "".to_string()),
let deletable = DeletableObjects::Post(Box::new(updated_post.into()));
send_apub_delete_in_community(
local_user_view.person,
community,
deletable,
data.reason.clone().or_else(|| Some("".to_string())),
removed,
context,
)
.await?;

send_post_ws_message(
data.post_id,
UserOperationCrud::RemovePost,
websocket_id,
Some(local_user_view.person.id),
context,
)
.await
Ok(res)
}
}
2 changes: 1 addition & 1 deletion crates/api_crud/src/private_message/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use lemmy_api_common::{
use lemmy_apub::{
generate_local_apub_endpoint,
protocol::activities::{
private_message::create_or_update::CreateOrUpdatePrivateMessage,
create_or_update::private_message::CreateOrUpdatePrivateMessage,
CreateOrUpdateType,
},
EndpointType,
Expand Down
34 changes: 9 additions & 25 deletions crates/api_crud/src/private_message/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ use lemmy_api_common::{
get_local_user_view_from_jwt,
person::{DeletePrivateMessage, PrivateMessageResponse},
};
use lemmy_apub::protocol::activities::private_message::{
delete::DeletePrivateMessage as DeletePrivateMessageApub,
undo_delete::UndoDeletePrivateMessage,
};
use lemmy_db_schema::{
source::private_message::PrivateMessage,
traits::{Crud, DeleteableOrRemoveable},
};
use lemmy_apub::activities::deletion::send_apub_delete_private_message;
use lemmy_db_schema::{source::private_message::PrivateMessage, traits::Crud};
use lemmy_utils::{ConnectionId, LemmyError};
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};

Expand Down Expand Up @@ -51,23 +45,13 @@ impl PerformCrud for DeletePrivateMessage {
.map_err(|e| e.with_message("couldnt_update_private_message"))?;

// Send the apub update
if data.deleted {
DeletePrivateMessageApub::send(
&local_user_view.person.into(),
&updated_private_message
.blank_out_deleted_or_removed_info()
.into(),
context,
)
.await?;
} else {
UndoDeletePrivateMessage::send(
&local_user_view.person.into(),
&updated_private_message.into(),
context,
)
.await?;
}
send_apub_delete_private_message(
&local_user_view.person.into(),
updated_private_message,
data.deleted,
context,
)
.await?;

let op = UserOperationCrud::DeletePrivateMessage;
send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
Expand Down
2 changes: 1 addition & 1 deletion crates/api_crud/src/private_message/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use lemmy_api_common::{
person::{EditPrivateMessage, PrivateMessageResponse},
};
use lemmy_apub::protocol::activities::{
private_message::create_or_update::CreateOrUpdatePrivateMessage,
create_or_update::private_message::CreateOrUpdatePrivateMessage,
CreateOrUpdateType,
};
use lemmy_db_schema::{source::private_message::PrivateMessage, traits::Crud};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"object": {
"id": "http://ds9.lemmy.ml/post/1",
"type": "Tombstone"
},
"object": "http://ds9.lemmy.ml/post/1",
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"object": {
"id": "http://ds9.lemmy.ml/comment/1",
"type": "Tombstone"
},
"object": "http://ds9.lemmy.ml/comment/1",
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"object": {
"id": "http://ds9.lemmy.ml/post/1",
"type": "Tombstone"
},
"object": "http://ds9.lemmy.ml/post/1",
"cc": [
"http://enterprise.lemmy.ml/c/main"
],
Expand Down
Loading