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,
|
2023-03-21 15:03:05 +00:00
|
|
|
insert_activity,
|
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-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::{
|
2023-03-21 15:03:05 +00:00
|
|
|
config::Data,
|
|
|
|
kinds::{activity::UpdateType, public},
|
|
|
|
traits::{ActivityHandler, Actor, Object},
|
2021-10-29 10:32:42 +00:00
|
|
|
};
|
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,
|
2023-05-25 14:50:07 +00:00
|
|
|
utils::local_user_view_from_jwt,
|
2022-11-26 02:04:46 +00:00
|
|
|
};
|
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
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
#[async_trait::async_trait]
|
2022-11-28 14:29:33 +00:00
|
|
|
impl SendActivity for EditCommunity {
|
|
|
|
type Response = CommunityResponse;
|
|
|
|
|
|
|
|
async fn send_activity(
|
|
|
|
request: &Self,
|
|
|
|
_response: &Self::Response,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2022-11-28 14:29:33 +00:00
|
|
|
) -> Result<(), LemmyError> {
|
2023-05-25 14:50:07 +00:00
|
|
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
2022-11-28 14:29:33 +00:00
|
|
|
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,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2021-08-19 21:24:33 +00:00
|
|
|
) -> 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 {
|
2023-03-21 15:03:05 +00:00
|
|
|
actor: actor.id().into(),
|
2021-10-25 17:22:34 +00:00
|
|
|
to: vec![public()],
|
2023-03-21 15:03:05 +00:00
|
|
|
object: Box::new(community.clone().into_json(context).await?),
|
|
|
|
cc: vec![community.id()],
|
2021-08-19 21:24:33 +00:00
|
|
|
kind: UpdateType::Update,
|
|
|
|
id: id.clone(),
|
2023-03-21 15:03:05 +00:00
|
|
|
audience: Some(community.id().into()),
|
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
|
|
|
}
|
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
#[async_trait::async_trait]
|
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
|
|
|
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)]
|
2023-03-21 15:03:05 +00:00
|
|
|
async fn verify(&self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
|
2021-11-06 17:44:34 +00:00
|
|
|
verify_is_public(&self.to, &self.cc)?;
|
2023-03-21 15:03:05 +00:00
|
|
|
let community = self.community(context).await?;
|
|
|
|
verify_person_in_community(&self.actor, &community, context).await?;
|
|
|
|
verify_mod_action(&self.actor, self.object.id.inner(), community.id, context).await?;
|
|
|
|
ApubCommunity::verify(&self.object, &community.actor_id.clone().into(), context).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)]
|
2023-03-21 15:03:05 +00:00
|
|
|
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
|
|
|
|
insert_activity(&self.id, &self, false, false, context).await?;
|
|
|
|
let community = self.community(context).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();
|
|
|
|
|
2023-06-06 16:27:22 +00:00
|
|
|
Community::update(context.pool(), community.id, &community_update_form).await?;
|
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
|
|
|
}
|
|
|
|
}
|
2022-11-28 14:29:33 +00:00
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
#[async_trait::async_trait]
|
2022-11-28 14:29:33 +00:00
|
|
|
impl SendActivity for HideCommunity {
|
|
|
|
type Response = CommunityResponse;
|
|
|
|
|
|
|
|
async fn send_activity(
|
|
|
|
request: &Self,
|
|
|
|
_response: &Self::Response,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2022-11-28 14:29:33 +00:00
|
|
|
) -> Result<(), LemmyError> {
|
2023-05-25 14:50:07 +00:00
|
|
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
2022-11-28 14:29:33 +00:00
|
|
|
let community = Community::read(context.pool(), request.community_id).await?;
|
|
|
|
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
|
|
|
}
|
|
|
|
}
|