From efc355b7f98146c99df68171fe4cc7542a400f5e Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Fri, 1 Feb 2019 10:23:30 -0500 Subject: [PATCH] Implement FollowHandler --- src/Activities/FollowHandler.php | 77 ++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/Activities/FollowHandler.php diff --git a/src/Activities/FollowHandler.php b/src/Activities/FollowHandler.php new file mode 100644 index 0000000..c0a62e5 --- /dev/null +++ b/src/Activities/FollowHandler.php @@ -0,0 +1,77 @@ + 'handleInbox', + ); + } + + public function __construct( bool $autoAccepts, + Client $httpClient, + ContextProvider $contextProvider ) + { + $this->autoAccepts = $autoAccepts; + $this->httpsClient = $httpClient; + $this->contextProvider = $contextProvider; + } + + public function handleInbox( InboxActivityEvent $event, + string $eventName, + EventDispatcher $eventDispatcher ) + { + $activity = $event->getActivity(); + if ( ! $activity['type'] === 'Follow' ) { + return; + } + if ( $this->autoAccepts ) { + $localActor = $event->getActor(); + $accept = array( + '@context' => $this->contextProvider->getContext(), + 'type' => 'Accept', + 'actor' => $localActor['id'], + 'object' => $activity['id'], + ); + $request = Request::create( + $localActor['outbox'], + Request::METHOD_POST, + array(), array(), array(), + array( + 'HTTP_ACCEPT' => 'application/ld+json', + 'CONTENT_TYPE' => 'application/json' + ), + json_encode( $accept ) + ); + $request->attributes->set( 'actor', $localActor ); + $outboxEvent = new OutboxActivityEvent( $accept, $localActor, $request ); + $eventDispatcher->dispatch( OutboxActivityEvent::NAME, $outboxEvent ); + } + } +} +?>