2021-07-17 16:20:44 +00:00
|
|
|
use crate::{
|
2021-08-19 21:24:33 +00:00
|
|
|
activities::{
|
2022-12-01 20:52:49 +00:00
|
|
|
community::send_activity_in_community,
|
2021-08-19 21:24:33 +00:00
|
|
|
generate_activity_id,
|
2021-10-25 17:22:34 +00:00
|
|
|
verify_is_public,
|
2021-08-19 21:24:33 +00:00
|
|
|
verify_mod_action,
|
|
|
|
verify_person_in_community,
|
|
|
|
},
|
2021-10-29 10:32:42 +00:00
|
|
|
activity_lists::AnnouncableActivities,
|
2021-10-28 21:17:59 +00:00
|
|
|
objects::{community::ApubCommunity, person::ApubPerson},
|
2022-12-01 20:52:49 +00:00
|
|
|
protocol::{activities::community::update::UpdateCommunity, InCommunity},
|
2022-06-02 14:33:41 +00:00
|
|
|
ActorType,
|
2022-11-28 14:29:33 +00:00
|
|
|
SendActivity,
|
2021-10-06 20:20:05 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{
|
|
|
|
core::object_id::ObjectId,
|
2021-10-29 10:32:42 +00:00
|
|
|
data::Data,
|
2022-06-02 14:33:41 +00:00
|
|
|
traits::{ActivityHandler, ApubObject},
|
2021-10-29 10:32:42 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitystreams_kinds::{activity::UpdateType, public};
|
2022-11-26 02:04:46 +00:00
|
|
|
use lemmy_api_common::{
|
2022-11-28 14:29:33 +00:00
|
|
|
community::{CommunityResponse, EditCommunity, HideCommunity},
|
|
|
|
context::LemmyContext,
|
|
|
|
utils::get_local_user_view_from_jwt,
|
2022-11-26 02:04:46 +00:00
|
|
|
websocket::{send::send_community_ws_message, UserOperationCrud},
|
|
|
|
};
|
2022-10-27 09:24:07 +00:00
|
|
|
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
2022-06-02 14:33:41 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
|
|
|
use url::Url;
|
2021-08-19 21:24:33 +00:00
|
|
|
|
2022-11-28 14:29:33 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl SendActivity for EditCommunity {
|
|
|
|
type Response = CommunityResponse;
|
|
|
|
|
|
|
|
async fn send_activity(
|
|
|
|
request: &Self,
|
|
|
|
_response: &Self::Response,
|
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let local_user_view =
|
|
|
|
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
|
|
let community = Community::read(context.pool(), request.community_id).await?;
|
|
|
|
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 21:24:33 +00:00
|
|
|
impl UpdateCommunity {
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-08-19 21:24:33 +00:00
|
|
|
pub async fn send(
|
2021-11-06 12:37:55 +00:00
|
|
|
community: ApubCommunity,
|
2021-10-18 21:36:44 +00:00
|
|
|
actor: &ApubPerson,
|
2021-08-19 21:24:33 +00:00
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<(), LemmyError> {
|
2021-09-22 15:57:09 +00:00
|
|
|
let id = generate_activity_id(
|
|
|
|
UpdateType::Update,
|
|
|
|
&context.settings().get_protocol_and_hostname(),
|
|
|
|
)?;
|
2021-08-19 21:24:33 +00:00
|
|
|
let update = UpdateCommunity {
|
2021-09-25 15:44:52 +00:00
|
|
|
actor: ObjectId::new(actor.actor_id()),
|
2021-10-25 17:22:34 +00:00
|
|
|
to: vec![public()],
|
2021-11-06 13:25:34 +00:00
|
|
|
object: Box::new(community.clone().into_apub(context).await?),
|
2021-10-28 12:47:56 +00:00
|
|
|
cc: vec![community.actor_id()],
|
2021-08-19 21:24:33 +00:00
|
|
|
kind: UpdateType::Update,
|
|
|
|
id: id.clone(),
|
2022-12-01 20:52:49 +00:00
|
|
|
audience: Some(ObjectId::new(community.actor_id())),
|
2021-08-19 21:24:33 +00:00
|
|
|
};
|
|
|
|
|
2021-11-06 13:25:34 +00:00
|
|
|
let activity = AnnouncableActivities::UpdateCommunity(update);
|
2022-11-23 23:40:47 +00:00
|
|
|
send_activity_in_community(activity, actor, &community, vec![], true, context).await
|
2021-08-19 21:24:33 +00:00
|
|
|
}
|
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)]
|
|
|
|
impl ActivityHandler for UpdateCommunity {
|
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> {
|
2021-11-06 17:44:34 +00:00
|
|
|
verify_is_public(&self.to, &self.cc)?;
|
2022-12-01 20:52:49 +00:00
|
|
|
let community = self.community(context, request_counter).await?;
|
2021-10-28 11:46:48 +00:00
|
|
|
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
|
2022-04-04 14:46:49 +00:00
|
|
|
verify_mod_action(
|
|
|
|
&self.actor,
|
|
|
|
self.object.id.inner(),
|
2022-10-10 15:20:36 +00:00
|
|
|
community.id,
|
2022-04-04 14:46:49 +00:00
|
|
|
context,
|
|
|
|
request_counter,
|
|
|
|
)
|
|
|
|
.await?;
|
2021-11-06 17:35:14 +00:00
|
|
|
ApubCommunity::verify(
|
|
|
|
&self.object,
|
|
|
|
&community.actor_id.clone().into(),
|
|
|
|
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>,
|
|
|
|
request_counter: &mut i32,
|
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
|
|
|
) -> Result<(), LemmyError> {
|
2022-12-01 20:52:49 +00:00
|
|
|
let community = self.community(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
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
let community_update_form = self.object.into_update_form();
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let updated_community =
|
|
|
|
Community::update(context.pool(), community.id, &community_update_form).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
|
|
|
send_community_ws_message(
|
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
|
|
|
updated_community.id,
|
|
|
|
UserOperationCrud::EditCommunity,
|
2021-08-17 18:04:58 +00:00
|
|
|
None,
|
|
|
|
None,
|
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,
|
|
|
|
)
|
2021-08-17 18:04:58 +00:00
|
|
|
.await?;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2022-11-28 14:29:33 +00:00
|
|
|
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl SendActivity for HideCommunity {
|
|
|
|
type Response = CommunityResponse;
|
|
|
|
|
|
|
|
async fn send_activity(
|
|
|
|
request: &Self,
|
|
|
|
_response: &Self::Response,
|
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let local_user_view =
|
|
|
|
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
|
|
let community = Community::read(context.pool(), request.community_id).await?;
|
|
|
|
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
|
|
|
}
|
|
|
|
}
|