2021-07-17 16:20:44 +00:00
|
|
|
use crate::{
|
2022-06-02 14:33:41 +00:00
|
|
|
activities::{generate_activity_id, send_lemmy_activity},
|
2023-07-14 15:17:06 +00:00
|
|
|
insert_received_activity,
|
2022-11-23 23:40:47 +00:00
|
|
|
protocol::activities::following::{accept::AcceptFollow, follow::Follow},
|
2021-08-19 21:24:33 +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::AcceptType,
|
|
|
|
protocol::verification::verify_urls_match,
|
2022-06-08 15:45:39 +00:00
|
|
|
traits::{ActivityHandler, Actor},
|
2021-10-06 20:20:05 +00:00
|
|
|
};
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
|
|
|
use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
|
2022-06-02 14:33:41 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
|
|
|
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
|
|
|
|
2022-11-23 23:40:47 +00:00
|
|
|
impl AcceptFollow {
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2023-03-21 15:03:05 +00:00
|
|
|
pub async fn send(follow: Follow, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
|
2022-11-23 23:40:47 +00:00
|
|
|
let user_or_community = follow.object.dereference_local(context).await?;
|
2023-03-21 15:03:05 +00:00
|
|
|
let person = follow.actor.clone().dereference(context).await?;
|
2022-11-23 23:40:47 +00:00
|
|
|
let accept = AcceptFollow {
|
2023-03-21 15:03:05 +00:00
|
|
|
actor: user_or_community.id().into(),
|
2023-04-24 21:19:08 +00:00
|
|
|
to: Some([person.id().into()]),
|
2021-08-12 12:48:09 +00:00
|
|
|
object: follow,
|
|
|
|
kind: AcceptType::Accept,
|
2021-09-22 15:57:09 +00:00
|
|
|
id: generate_activity_id(
|
|
|
|
AcceptType::Accept,
|
|
|
|
&context.settings().get_protocol_and_hostname(),
|
|
|
|
)?,
|
2021-08-12 12:48:09 +00:00
|
|
|
};
|
2022-06-08 15:45:39 +00:00
|
|
|
let inbox = vec![person.shared_inbox_or_inbox()];
|
2022-11-23 23:40:47 +00:00
|
|
|
send_lemmy_activity(context, accept, &user_or_community, inbox, true).await
|
2021-08-12 12:48:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-06 20:20:05 +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
|
|
|
/// Handle accepted follows
|
2023-03-21 15:03:05 +00:00
|
|
|
#[async_trait::async_trait]
|
2022-11-23 23:40:47 +00:00
|
|
|
impl ActivityHandler for AcceptFollow {
|
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<LemmyContext>) -> Result<(), LemmyError> {
|
2023-07-14 15:17:06 +00:00
|
|
|
insert_received_activity(&self.id, context).await?;
|
2021-11-16 16:27:43 +00:00
|
|
|
verify_urls_match(self.actor.inner(), self.object.object.inner())?;
|
2023-03-21 15:03:05 +00:00
|
|
|
self.object.verify(context).await?;
|
2023-04-24 21:19:08 +00:00
|
|
|
if let Some(to) = &self.to {
|
|
|
|
verify_urls_match(to[0].inner(), self.object.actor.inner())?;
|
|
|
|
}
|
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<LemmyContext>) -> Result<(), LemmyError> {
|
|
|
|
let community = self.actor.dereference(context).await?;
|
|
|
|
let person = self.object.actor.dereference(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
|
|
|
// This will throw an error if no follow was requested
|
2022-07-28 15:49:26 +00:00
|
|
|
let community_id = community.id;
|
|
|
|
let person_id = person.id;
|
2023-07-11 13:09:59 +00:00
|
|
|
CommunityFollower::follow_accepted(&mut context.pool(), community_id, person_id).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(())
|
|
|
|
}
|
|
|
|
}
|