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-07-14 15:17:06 +00:00
|
|
|
insert_received_activity,
|
2024-01-25 14:22:11 +00:00
|
|
|
objects::{community::ApubCommunity, person::ApubPerson, read_from_string_or_source_opt},
|
2022-12-01 20:52:49 +00:00
|
|
|
protocol::{activities::community::update::UpdateCommunity, InCommunity},
|
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
|
|
|
};
|
2023-08-02 16:52:41 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
|
|
|
use lemmy_db_schema::{
|
2024-01-25 14:22:11 +00:00
|
|
|
source::{
|
|
|
|
activity::ActivitySendTargets,
|
|
|
|
community::{Community, CommunityUpdateForm},
|
|
|
|
person::Person,
|
|
|
|
},
|
2023-08-02 16:52:41 +00:00
|
|
|
traits::Crud,
|
2024-01-25 14:22:11 +00:00
|
|
|
utils::naive_now,
|
2022-11-26 02:04:46 +00:00
|
|
|
};
|
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-08-02 16:52:41 +00:00
|
|
|
pub(crate) async fn send_update_community(
|
|
|
|
community: Community,
|
|
|
|
actor: Person,
|
|
|
|
context: Data<LemmyContext>,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let community: ApubCommunity = community.into();
|
|
|
|
let actor: ApubPerson = actor.into();
|
|
|
|
let id = generate_activity_id(
|
|
|
|
UpdateType::Update,
|
|
|
|
&context.settings().get_protocol_and_hostname(),
|
|
|
|
)?;
|
|
|
|
let update = UpdateCommunity {
|
|
|
|
actor: actor.id().into(),
|
|
|
|
to: vec![public()],
|
|
|
|
object: Box::new(community.clone().into_json(&context).await?),
|
|
|
|
cc: vec![community.id()],
|
|
|
|
kind: UpdateType::Update,
|
|
|
|
id: id.clone(),
|
|
|
|
audience: Some(community.id().into()),
|
|
|
|
};
|
2021-08-19 21:24:33 +00:00
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
let activity = AnnouncableActivities::UpdateCommunity(update);
|
2023-09-09 16:25:03 +00:00
|
|
|
send_activity_in_community(
|
|
|
|
activity,
|
|
|
|
&actor,
|
|
|
|
&community,
|
|
|
|
ActivitySendTargets::empty(),
|
|
|
|
true,
|
|
|
|
&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
|
|
|
}
|
|
|
|
|
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?;
|
2023-09-26 01:39:18 +00:00
|
|
|
verify_mod_action(&self.actor, &community, context).await?;
|
2023-03-21 15:03:05 +00:00
|
|
|
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> {
|
2024-01-11 23:56:19 +00:00
|
|
|
insert_received_activity(&self.id, context).await?;
|
2023-03-21 15:03:05 +00:00
|
|
|
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
|
|
|
|
2024-01-25 14:22:11 +00:00
|
|
|
let community_update_form = CommunityUpdateForm {
|
|
|
|
title: Some(self.object.name.unwrap_or(self.object.preferred_username)),
|
|
|
|
description: Some(read_from_string_or_source_opt(
|
|
|
|
&self.object.summary,
|
|
|
|
&None,
|
|
|
|
&self.object.source,
|
|
|
|
)),
|
|
|
|
removed: None,
|
|
|
|
published: self.object.published.map(Into::into),
|
|
|
|
updated: Some(self.object.updated.map(Into::into)),
|
|
|
|
deleted: None,
|
|
|
|
nsfw: Some(self.object.sensitive.unwrap_or(false)),
|
|
|
|
actor_id: Some(self.object.id.into()),
|
|
|
|
local: None,
|
|
|
|
private_key: None,
|
|
|
|
hidden: None,
|
|
|
|
public_key: Some(self.object.public_key.public_key_pem),
|
|
|
|
last_refreshed_at: Some(naive_now()),
|
|
|
|
icon: Some(self.object.icon.map(|i| i.url.into())),
|
|
|
|
banner: Some(self.object.image.map(|i| i.url.into())),
|
|
|
|
followers_url: Some(self.object.followers.into()),
|
|
|
|
inbox_url: Some(self.object.inbox.into()),
|
|
|
|
shared_inbox_url: Some(self.object.endpoints.map(|e| e.shared_inbox.into())),
|
|
|
|
moderators_url: self.object.attributed_to.map(Into::into),
|
|
|
|
posting_restricted_to_mods: self.object.posting_restricted_to_mods,
|
|
|
|
featured_url: self.object.featured.map(Into::into),
|
|
|
|
};
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-07-11 13:09:59 +00:00
|
|
|
Community::update(&mut 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
|
|
|
}
|
|
|
|
}
|