2021-11-03 17:33:51 +00:00
|
|
|
use crate::{
|
|
|
|
activities::{
|
2022-02-14 15:14:24 +00:00
|
|
|
community::announce::GetCommunity,
|
2021-11-05 00:24:10 +00:00
|
|
|
deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
|
2021-11-03 17:33:51 +00:00
|
|
|
generate_activity_id,
|
|
|
|
},
|
2022-06-02 14:33:41 +00:00
|
|
|
local_instance,
|
2021-11-03 17:33:51 +00:00
|
|
|
objects::{community::ApubCommunity, person::ApubPerson},
|
2022-06-02 17:48:53 +00:00
|
|
|
protocol::{activities::deletion::delete::Delete, IdOrNestedObject},
|
2021-11-03 17:33:51 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
|
2022-02-14 15:14:24 +00:00
|
|
|
use activitystreams_kinds::activity::DeleteType;
|
|
|
|
use anyhow::anyhow;
|
2022-05-03 17:44:13 +00:00
|
|
|
use lemmy_api_common::utils::blocking;
|
2021-10-16 13:33:38 +00:00
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{
|
|
|
|
comment::Comment,
|
|
|
|
community::Community,
|
|
|
|
moderator::{
|
|
|
|
ModRemoveComment,
|
|
|
|
ModRemoveCommentForm,
|
|
|
|
ModRemoveCommunity,
|
|
|
|
ModRemoveCommunityForm,
|
|
|
|
ModRemovePost,
|
|
|
|
ModRemovePostForm,
|
|
|
|
},
|
|
|
|
post::Post,
|
2021-08-17 18:04:58 +00:00
|
|
|
},
|
2021-10-16 13:33:38 +00:00
|
|
|
traits::Crud,
|
2021-08-17 18:04:58 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2021-08-17 18:04:58 +00:00
|
|
|
use lemmy_websocket::{
|
|
|
|
send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
|
|
|
|
LemmyContext,
|
|
|
|
UserOperationCrud,
|
|
|
|
};
|
2021-11-03 17:33:51 +00:00
|
|
|
use url::Url;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
|
|
|
|
#[async_trait::async_trait(?Send)]
|
2021-08-17 18:04:58 +00:00
|
|
|
impl ActivityHandler for Delete {
|
2021-10-06 20:20:05 +00:00
|
|
|
type DataType = LemmyContext;
|
2022-06-02 14:33:41 +00:00
|
|
|
type Error = LemmyError;
|
|
|
|
|
|
|
|
fn id(&self) -> &Url {
|
|
|
|
&self.id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn actor(&self) -> &Url {
|
|
|
|
self.actor.inner()
|
|
|
|
}
|
2021-12-06 14:54:47 +00:00
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
async fn verify(
|
|
|
|
&self,
|
2021-10-06 20:20:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
request_counter: &mut i32,
|
|
|
|
) -> Result<(), LemmyError> {
|
2022-02-14 15:14:24 +00:00
|
|
|
verify_delete_activity(self, self.summary.is_some(), context, request_counter).await?;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
async fn receive(
|
2021-08-12 12:48:09 +00:00
|
|
|
self,
|
2021-10-06 20:20:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
request_counter: &mut i32,
|
|
|
|
) -> Result<(), LemmyError> {
|
2021-08-17 18:04:58 +00:00
|
|
|
if let Some(reason) = self.summary {
|
|
|
|
// We set reason to empty string if it doesn't exist, to distinguish between delete and
|
|
|
|
// remove. Here we change it back to option, so we don't write it to db.
|
|
|
|
let reason = if reason.is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(reason)
|
|
|
|
};
|
2021-11-16 00:58:15 +00:00
|
|
|
receive_remove_action(
|
2022-04-07 20:44:28 +00:00
|
|
|
&self
|
|
|
|
.actor
|
2022-06-08 15:45:39 +00:00
|
|
|
.dereference(context, local_instance(context), request_counter)
|
2022-04-07 20:44:28 +00:00
|
|
|
.await?,
|
2022-02-14 15:14:24 +00:00
|
|
|
self.object.id(),
|
2021-11-16 00:58:15 +00:00
|
|
|
reason,
|
|
|
|
context,
|
|
|
|
)
|
|
|
|
.await
|
2021-08-17 18:04:58 +00:00
|
|
|
} else {
|
2022-02-14 15:14:24 +00:00
|
|
|
receive_delete_action(
|
|
|
|
self.object.id(),
|
|
|
|
&self.actor,
|
|
|
|
true,
|
|
|
|
context,
|
|
|
|
request_counter,
|
|
|
|
)
|
|
|
|
.await
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Delete {
|
2021-08-19 21:24:33 +00:00
|
|
|
pub(in crate::activities::deletion) fn new(
|
2022-06-08 15:45:39 +00:00
|
|
|
actor: &ApubPerson,
|
2021-11-16 00:58:15 +00:00
|
|
|
object: DeletableObjects,
|
2022-02-14 15:14:24 +00:00
|
|
|
to: Url,
|
|
|
|
community: Option<&Community>,
|
2021-08-17 18:04:58 +00:00
|
|
|
summary: Option<String>,
|
2021-09-22 15:57:09 +00:00
|
|
|
context: &LemmyContext,
|
2021-08-19 21:24:33 +00:00
|
|
|
) -> Result<Delete, LemmyError> {
|
2022-02-14 15:14:24 +00:00
|
|
|
let id = generate_activity_id(
|
|
|
|
DeleteType::Delete,
|
|
|
|
&context.settings().get_protocol_and_hostname(),
|
|
|
|
)?;
|
|
|
|
let cc: Option<Url> = community.map(|c| c.actor_id.clone().into());
|
2021-08-19 21:24:33 +00:00
|
|
|
Ok(Delete {
|
2022-02-14 15:14:24 +00:00
|
|
|
actor: ObjectId::new(actor.actor_id.clone()),
|
|
|
|
to: vec![to],
|
2022-06-02 17:48:53 +00:00
|
|
|
object: IdOrNestedObject::Id(object.id()),
|
2022-02-14 15:14:24 +00:00
|
|
|
cc: cc.into_iter().collect(),
|
2021-08-17 18:04:58 +00:00
|
|
|
kind: DeleteType::Delete,
|
|
|
|
summary,
|
2022-02-14 15:14:24 +00:00
|
|
|
id,
|
2021-08-19 21:24:33 +00:00
|
|
|
unparsed: Default::default(),
|
|
|
|
})
|
|
|
|
}
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-08-17 18:04:58 +00:00
|
|
|
pub(in crate::activities) async fn receive_remove_action(
|
2022-04-07 20:44:28 +00:00
|
|
|
actor: &ApubPerson,
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
object: &Url,
|
2021-08-17 18:04:58 +00:00
|
|
|
reason: Option<String>,
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
context: &LemmyContext,
|
2021-08-17 18:04:58 +00:00
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
use UserOperationCrud::*;
|
|
|
|
match DeletableObjects::read_from_db(object, context).await? {
|
|
|
|
DeletableObjects::Community(community) => {
|
|
|
|
if community.local {
|
2021-12-06 14:54:47 +00:00
|
|
|
return Err(LemmyError::from_message(
|
|
|
|
"Only local admin can remove community",
|
|
|
|
));
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
}
|
2021-08-17 18:04:58 +00:00
|
|
|
let form = ModRemoveCommunityForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
community_id: community.id,
|
|
|
|
removed: Some(true),
|
|
|
|
reason,
|
|
|
|
expires: None,
|
|
|
|
};
|
|
|
|
blocking(context.pool(), move |conn| {
|
|
|
|
ModRemoveCommunity::create(conn, &form)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
let deleted_community = blocking(context.pool(), move |conn| {
|
|
|
|
Community::update_removed(conn, community.id, true)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
send_community_ws_message(deleted_community.id, RemoveCommunity, None, None, context).await?;
|
|
|
|
}
|
|
|
|
DeletableObjects::Post(post) => {
|
|
|
|
let form = ModRemovePostForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
post_id: post.id,
|
|
|
|
removed: Some(true),
|
|
|
|
reason,
|
|
|
|
};
|
|
|
|
blocking(context.pool(), move |conn| {
|
|
|
|
ModRemovePost::create(conn, &form)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
let removed_post = blocking(context.pool(), move |conn| {
|
|
|
|
Post::update_removed(conn, post.id, true)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
send_post_ws_message(removed_post.id, RemovePost, None, None, context).await?;
|
|
|
|
}
|
|
|
|
DeletableObjects::Comment(comment) => {
|
|
|
|
let form = ModRemoveCommentForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
comment_id: comment.id,
|
|
|
|
removed: Some(true),
|
|
|
|
reason,
|
|
|
|
};
|
|
|
|
blocking(context.pool(), move |conn| {
|
|
|
|
ModRemoveComment::create(conn, &form)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
let removed_comment = blocking(context.pool(), move |conn| {
|
|
|
|
Comment::update_removed(conn, comment.id, true)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
send_comment_ws_message_simple(removed_comment.id, RemoveComment, context).await?;
|
|
|
|
}
|
2022-02-14 15:14:24 +00:00
|
|
|
DeletableObjects::PrivateMessage(_) => unimplemented!(),
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
}
|
2021-10-28 11:46:48 +00:00
|
|
|
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl GetCommunity for Delete {
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-10-28 11:46:48 +00:00
|
|
|
async fn get_community(
|
|
|
|
&self,
|
|
|
|
context: &LemmyContext,
|
|
|
|
_request_counter: &mut i32,
|
|
|
|
) -> Result<ApubCommunity, LemmyError> {
|
2022-02-14 15:14:24 +00:00
|
|
|
let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? {
|
2021-10-28 11:46:48 +00:00
|
|
|
DeletableObjects::Community(c) => c.id,
|
|
|
|
DeletableObjects::Comment(c) => {
|
|
|
|
let post = blocking(context.pool(), move |conn| Post::read(conn, c.post_id)).await??;
|
|
|
|
post.community_id
|
|
|
|
}
|
|
|
|
DeletableObjects::Post(p) => p.community_id,
|
2022-02-14 15:14:24 +00:00
|
|
|
DeletableObjects::PrivateMessage(_) => {
|
|
|
|
return Err(anyhow!("Private message is not part of community").into())
|
|
|
|
}
|
2021-10-28 11:46:48 +00:00
|
|
|
};
|
|
|
|
let community = blocking(context.pool(), move |conn| {
|
|
|
|
Community::read(conn, community_id)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
Ok(community.into())
|
|
|
|
}
|
|
|
|
}
|