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

Rewrite remaining activities #1712

Merged
merged 11 commits into from
Aug 19, 2021
Prev Previous commit
Next Next commit
Rewrite delete activities
  • Loading branch information
Nutomic committed Aug 13, 2021
commit bc6294a834fc06dc118ed1bc9c39724484a1efd7
53 changes: 29 additions & 24 deletions crates/api_crud/src/comment/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use lemmy_api_common::{
is_mod_or_admin,
send_local_notifs,
};
use lemmy_apub::ApubObjectType;
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
use lemmy_db_queries::{source::comment::Comment_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::source::{comment::*, moderator::*};
use lemmy_db_schema::source::{comment::*, community::Community, moderator::*};
use lemmy_db_views::comment_view::CommentView;
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperationCrud};
Expand Down Expand Up @@ -47,23 +47,25 @@ impl PerformCrud for DeleteComment {

// Do the delete
let deleted = data.deleted;
let mut updated_comment = blocking(context.pool(), move |conn| {
let updated_comment = blocking(context.pool(), move |conn| {
Comment::update_deleted(conn, comment_id, deleted)
})
.await?
.map_err(|_| ApiError::err("couldnt_update_comment"))?;

// Send the apub message
if deleted {
updated_comment = updated_comment.blank_out_deleted_or_removed_info();
updated_comment
.send_delete(&local_user_view.person, context)
.await?;
} else {
updated_comment
.send_undo_delete(&local_user_view.person, context)
.await?;
}
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_comment.post.community_id)
})
.await??;
send_apub_delete(
&local_user_view.person,
&community,
updated_comment.ap_id.clone().into(),
deleted,
context,
)
.await?;

// Refetch it
let comment_id = data.comment_id;
Expand Down Expand Up @@ -142,7 +144,7 @@ impl PerformCrud for RemoveComment {

// Do the remove
let removed = data.removed;
let mut updated_comment = blocking(context.pool(), move |conn| {
let updated_comment = blocking(context.pool(), move |conn| {
Comment::update_removed(conn, comment_id, removed)
})
.await?
Expand All @@ -161,16 +163,19 @@ impl PerformCrud for RemoveComment {
.await??;

// Send the apub message
if removed {
updated_comment = updated_comment.blank_out_deleted_or_removed_info();
updated_comment
.send_remove(&local_user_view.person, context)
.await?;
} else {
updated_comment
.send_undo_remove(&local_user_view.person, context)
.await?;
}
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_comment.post.community_id)
})
.await??;
send_apub_remove(
&local_user_view.person,
&community,
updated_comment.ap_id.clone().into(),
data.reason.clone().unwrap_or_else(|| "".to_string()),
removed,
context,
)
.await?;

// Refetch it
let comment_id = data.comment_id;
Expand Down
37 changes: 18 additions & 19 deletions crates/api_crud/src/community/delete.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{community::send_community_websocket, PerformCrud};
use actix_web::web::Data;
use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin};
use lemmy_apub::CommunityType;
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
use lemmy_db_queries::{source::community::Community_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::source::{
community::*,
Expand Down Expand Up @@ -48,16 +48,14 @@ impl PerformCrud for DeleteCommunity {
.map_err(|_| ApiError::err("couldnt_update_community"))?;

// Send apub messages
if deleted {
updated_community
.blank_out_deleted_or_removed_info()
.send_delete(local_user_view.person.to_owned(), context)
.await?;
} else {
updated_community
.send_undo_delete(local_user_view.person.to_owned(), context)
.await?;
}
send_apub_delete(
&local_user_view.person,
&updated_community,
updated_community.actor_id.clone().into(),
deleted,
context,
)
.await?;

let community_id = data.community_id;
let person_id = local_user_view.person.id;
Expand Down Expand Up @@ -123,14 +121,15 @@ impl PerformCrud for RemoveCommunity {
.await??;

// Apub messages
if removed {
updated_community
.blank_out_deleted_or_removed_info()
.send_remove(context)
.await?;
} else {
updated_community.send_undo_remove(context).await?;
}
send_apub_remove(
&local_user_view.person,
&updated_community,
updated_community.actor_id.clone().into(),
data.reason.clone().unwrap_or_else(|| "".to_string()),
removed,
context,
)
.await?;

let community_id = data.community_id;
let person_id = local_user_view.person.id;
Expand Down
49 changes: 27 additions & 22 deletions crates/api_crud/src/post/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use lemmy_api_common::{
is_mod_or_admin,
post::*,
};
use lemmy_apub::ApubObjectType;
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
use lemmy_db_queries::{source::post::Post_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::source::{moderator::*, post::*};
use lemmy_db_schema::source::{community::Community, moderator::*, post::*};
use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperationCrud};
Expand Down Expand Up @@ -50,16 +50,18 @@ impl PerformCrud for DeletePost {
.await??;

// apub updates
if deleted {
updated_post
.blank_out_deleted_or_removed_info()
.send_delete(&local_user_view.person, context)
.await?;
} else {
updated_post
.send_undo_delete(&local_user_view.person, context)
.await?;
}
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_post.community_id)
})
.await??;
send_apub_delete(
&local_user_view.person,
&community,
updated_post.ap_id.into(),
deleted,
context,
)
.await?;

// Refetch the post
let post_id = data.post_id;
Expand Down Expand Up @@ -135,16 +137,19 @@ impl PerformCrud for RemovePost {
.await??;

// apub updates
if removed {
updated_post
.blank_out_deleted_or_removed_info()
.send_remove(&local_user_view.person, context)
.await?;
} else {
updated_post
.send_undo_remove(&local_user_view.person, context)
.await?;
}
let community = blocking(context.pool(), move |conn| {
Community::read(conn, orig_post.community_id)
})
.await??;
send_apub_remove(
&local_user_view.person,
&community,
updated_post.ap_id.into(),
data.reason.clone().unwrap_or_else(|| "".to_string()),
removed,
context,
)
.await?;

// Refetch the post
let post_id = data.post_id;
Expand Down
16 changes: 5 additions & 11 deletions crates/apub/src/activities/community/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ use crate::{
list_community_follower_inboxes,
undo_block_user::UndoBlockUserFromCommunity,
},
deletion::{
delete::DeletePostCommentOrCommunity,
undo_delete::UndoDeletePostCommentOrCommunity,
},
deletion::{delete::Delete, undo_delete::UndoDelete},
generate_activity_id,
post::create_or_update::CreateOrUpdatePost,
removal::{
remove::RemovePostCommentCommunityOrMod,
undo_remove::UndoRemovePostCommentOrCommunity,
},
removal::{remove::RemoveMod, undo_remove::UndoRemovePostCommentOrCommunity},
verify_activity,
verify_community,
voting::{undo_vote::UndoVote, vote::Vote},
Expand All @@ -43,13 +37,13 @@ pub enum AnnouncableActivities {
CreateOrUpdatePost(Box<CreateOrUpdatePost>),
Vote(Vote),
UndoVote(UndoVote),
DeletePostCommentOrCommunity(DeletePostCommentOrCommunity),
UndoDeletePostCommentOrCommunity(UndoDeletePostCommentOrCommunity),
RemovePostCommentCommunityOrMod(RemovePostCommentCommunityOrMod),
Delete(Delete),
UndoDelete(UndoDelete),
UndoRemovePostCommentOrCommunity(UndoRemovePostCommentOrCommunity),
BlockUserFromCommunity(BlockUserFromCommunity),
UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
AddMod(AddMod),
RemoveMod(RemoveMod),
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
Expand Down
Loading