2021-07-17 12:20:44 -04:00
|
|
|
use crate::{
|
2022-06-02 10:33:41 -04:00
|
|
|
activities::{generate_activity_id, send_lemmy_activity},
|
2023-03-21 11:03:05 -04:00
|
|
|
insert_activity,
|
2022-11-23 18:40:47 -05:00
|
|
|
protocol::activities::following::{accept::AcceptFollow, follow::Follow},
|
2021-08-19 17:24:33 -04:00
|
|
|
};
|
2022-06-02 10:33:41 -04:00
|
|
|
use activitypub_federation::{
|
2023-03-21 11:03:05 -04:00
|
|
|
config::Data,
|
|
|
|
kinds::activity::AcceptType,
|
|
|
|
protocol::verification::verify_urls_match,
|
2022-06-08 11:45:39 -04:00
|
|
|
traits::{ActivityHandler, Actor},
|
2021-10-06 16:20:05 -04:00
|
|
|
};
|
2022-11-25 21:04:46 -05:00
|
|
|
use lemmy_api_common::{
|
|
|
|
community::CommunityResponse,
|
2022-11-28 09:29:33 -05:00
|
|
|
context::LemmyContext,
|
2022-12-09 10:31:47 -05:00
|
|
|
websocket::UserOperation,
|
2022-11-25 21:04:46 -05:00
|
|
|
};
|
2022-12-19 06:40:22 -05:00
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{actor_language::CommunityLanguage, community::CommunityFollower},
|
|
|
|
traits::Followable,
|
|
|
|
};
|
2022-07-28 11:49:26 -04:00
|
|
|
use lemmy_db_views::structs::LocalUserView;
|
|
|
|
use lemmy_db_views_actor::structs::CommunityView;
|
2022-06-02 10:33:41 -04: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 12:08:46 -04:00
|
|
|
|
2022-11-23 18:40:47 -05:00
|
|
|
impl AcceptFollow {
|
2021-12-06 09:54:47 -05:00
|
|
|
#[tracing::instrument(skip_all)]
|
2023-03-21 11:03:05 -04:00
|
|
|
pub async fn send(follow: Follow, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
|
2022-11-23 18:40:47 -05:00
|
|
|
let user_or_community = follow.object.dereference_local(context).await?;
|
2023-03-21 11:03:05 -04:00
|
|
|
let person = follow.actor.clone().dereference(context).await?;
|
2022-11-23 18:40:47 -05:00
|
|
|
let accept = AcceptFollow {
|
2023-03-21 11:03:05 -04:00
|
|
|
actor: user_or_community.id().into(),
|
2021-08-12 08:48:09 -04:00
|
|
|
object: follow,
|
|
|
|
kind: AcceptType::Accept,
|
2021-09-22 11:57:09 -04:00
|
|
|
id: generate_activity_id(
|
|
|
|
AcceptType::Accept,
|
|
|
|
&context.settings().get_protocol_and_hostname(),
|
|
|
|
)?,
|
2021-08-12 08:48:09 -04:00
|
|
|
};
|
2022-06-08 11:45:39 -04:00
|
|
|
let inbox = vec![person.shared_inbox_or_inbox()];
|
2022-11-23 18:40:47 -05:00
|
|
|
send_lemmy_activity(context, accept, &user_or_community, inbox, true).await
|
2021-08-12 08:48:09 -04:00
|
|
|
}
|
|
|
|
}
|
2021-10-06 16:20:05 -04: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 12:08:46 -04:00
|
|
|
/// Handle accepted follows
|
2023-03-21 11:03:05 -04:00
|
|
|
#[async_trait::async_trait]
|
2022-11-23 18:40:47 -05:00
|
|
|
impl ActivityHandler for AcceptFollow {
|
2021-10-06 16:20:05 -04:00
|
|
|
type DataType = LemmyContext;
|
2022-06-02 10:33:41 -04:00
|
|
|
type Error = LemmyError;
|
|
|
|
|
|
|
|
fn id(&self) -> &Url {
|
|
|
|
&self.id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn actor(&self) -> &Url {
|
|
|
|
self.actor.inner()
|
|
|
|
}
|
2021-12-06 09:54:47 -05:00
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
2023-03-21 11:03:05 -04:00
|
|
|
async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
|
2021-11-16 11:27:43 -05:00
|
|
|
verify_urls_match(self.actor.inner(), self.object.object.inner())?;
|
2023-03-21 11:03:05 -04:00
|
|
|
self.object.verify(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 12:08:46 -04:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-12-06 09:54:47 -05:00
|
|
|
#[tracing::instrument(skip_all)]
|
2023-03-21 11:03:05 -04:00
|
|
|
async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
|
|
|
|
insert_activity(&self.id, &self, false, true, context).await?;
|
|
|
|
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 12:08:46 -04:00
|
|
|
// This will throw an error if no follow was requested
|
2022-07-28 11:49:26 -04:00
|
|
|
let community_id = community.id;
|
|
|
|
let person_id = person.id;
|
2022-11-09 05:05:00 -05:00
|
|
|
CommunityFollower::follow_accepted(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 12:08:46 -04:00
|
|
|
|
2022-07-28 11:49:26 -04:00
|
|
|
// Send the Subscribed message over websocket
|
|
|
|
// Re-read the community_view to get the new SubscribedType
|
2023-02-28 22:46:15 -05:00
|
|
|
let community_view =
|
|
|
|
CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
|
2022-07-28 11:49:26 -04:00
|
|
|
|
|
|
|
// Get the local_user_id
|
2022-11-09 05:05:00 -05:00
|
|
|
let local_recipient_id = LocalUserView::read_person(context.pool(), person_id)
|
|
|
|
.await?
|
|
|
|
.local_user
|
|
|
|
.id;
|
2022-12-19 06:40:22 -05:00
|
|
|
let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
|
2022-07-28 11:49:26 -04:00
|
|
|
|
2022-12-19 06:40:22 -05:00
|
|
|
let response = CommunityResponse {
|
|
|
|
community_view,
|
|
|
|
discussion_languages,
|
|
|
|
};
|
2022-07-28 11:49:26 -04:00
|
|
|
|
2022-12-09 10:31:47 -05:00
|
|
|
context
|
|
|
|
.chat_server()
|
|
|
|
.send_user_room_message(
|
|
|
|
&UserOperation::FollowCommunity,
|
|
|
|
&response,
|
|
|
|
local_recipient_id,
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
.await?;
|
2022-07-28 11:49:26 -04: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 12:08:46 -04:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|