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},
|
|
|
|
local_instance,
|
2022-11-23 23:40:47 +00:00
|
|
|
protocol::activities::following::{accept::AcceptFollow, follow::Follow},
|
2022-06-02 14:33:41 +00:00
|
|
|
ActorType,
|
2021-08-19 21:24:33 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{
|
|
|
|
core::object_id::ObjectId,
|
2021-10-06 20:20:05 +00:00
|
|
|
data::Data,
|
2022-06-08 15:45:39 +00:00
|
|
|
traits::{ActivityHandler, Actor},
|
2022-06-02 14:33:41 +00:00
|
|
|
utils::verify_urls_match,
|
2021-10-06 20:20:05 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitystreams_kinds::activity::AcceptType;
|
2022-11-26 02:04:46 +00:00
|
|
|
use lemmy_api_common::{
|
|
|
|
community::CommunityResponse,
|
|
|
|
websocket::{messages::SendUserRoomMessage, UserOperation},
|
|
|
|
LemmyContext,
|
|
|
|
};
|
2021-10-18 21:36:44 +00:00
|
|
|
use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
|
2022-07-28 15:49:26 +00:00
|
|
|
use lemmy_db_views::structs::LocalUserView;
|
|
|
|
use lemmy_db_views_actor::structs::CommunityView;
|
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)]
|
2021-10-06 20:20:05 +00:00
|
|
|
pub async fn send(
|
2022-11-23 23:40:47 +00:00
|
|
|
follow: Follow,
|
2021-10-06 20:20:05 +00:00
|
|
|
context: &LemmyContext,
|
|
|
|
request_counter: &mut i32,
|
|
|
|
) -> Result<(), LemmyError> {
|
2022-11-23 23:40:47 +00:00
|
|
|
let user_or_community = follow.object.dereference_local(context).await?;
|
2021-10-06 20:20:05 +00:00
|
|
|
let person = follow
|
|
|
|
.actor
|
|
|
|
.clone()
|
2022-11-09 10:05:00 +00:00
|
|
|
.dereference(context, local_instance(context).await, request_counter)
|
2021-10-06 20:20:05 +00:00
|
|
|
.await?;
|
2022-11-23 23:40:47 +00:00
|
|
|
let accept = AcceptFollow {
|
|
|
|
actor: ObjectId::new(user_or_community.actor_id()),
|
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
|
|
|
|
#[async_trait::async_trait(?Send)]
|
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)]
|
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-16 16:27:43 +00:00
|
|
|
verify_urls_match(self.actor.inner(), self.object.object.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
|
|
|
self.object.verify(context, request_counter).await?;
|
|
|
|
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>,
|
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> {
|
2022-07-28 15:49:26 +00:00
|
|
|
let community = self
|
2021-12-06 22:54:34 +00:00
|
|
|
.actor
|
2022-11-09 10:05:00 +00:00
|
|
|
.dereference(context, local_instance(context).await, request_counter)
|
2021-12-06 22:54:34 +00:00
|
|
|
.await?;
|
2022-07-28 15:49:26 +00:00
|
|
|
let person = self
|
2021-11-16 16:27:43 +00:00
|
|
|
.object
|
|
|
|
.actor
|
2022-11-09 10:05:00 +00:00
|
|
|
.dereference(context, local_instance(context).await, request_counter)
|
2021-11-16 16:27:43 +00:00
|
|
|
.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;
|
2022-11-09 10:05:00 +00: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 16:08:46 +00:00
|
|
|
|
2022-07-28 15:49:26 +00:00
|
|
|
// Send the Subscribed message over websocket
|
|
|
|
// Re-read the community_view to get the new SubscribedType
|
2022-11-09 10:05:00 +00:00
|
|
|
let community_view = CommunityView::read(context.pool(), community_id, Some(person_id)).await?;
|
2022-07-28 15:49:26 +00:00
|
|
|
|
|
|
|
// Get the local_user_id
|
2022-11-09 10:05:00 +00:00
|
|
|
let local_recipient_id = LocalUserView::read_person(context.pool(), person_id)
|
|
|
|
.await?
|
|
|
|
.local_user
|
|
|
|
.id;
|
2022-07-28 15:49:26 +00:00
|
|
|
|
|
|
|
let response = CommunityResponse { community_view };
|
|
|
|
|
|
|
|
context.chat_server().do_send(SendUserRoomMessage {
|
|
|
|
op: UserOperation::FollowCommunity,
|
|
|
|
response,
|
|
|
|
local_recipient_id,
|
|
|
|
websocket_id: 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
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|