'handleInbox', OutboxActivityEvent::NAME => 'handleOutbox', ); } public function __construct(ObjectsService $objectsService, CollectionsService $collectionsService) { $this->objectsService = $objectsService; $this->collectionsService = $collectionsService; } public function handleInbox(InboxActivityEvent $event) { $activity = $event->getActivity(); if ( $activity['type'] !== 'Undo' ) { return; } $object = $this->getUndoObject( $activity ); if ( ! ( $object && $object->hasField( 'type' ) ) ) { return; } $this->assertUndoIsValid( $activity, $object ); switch ( $object['type'] ) { case 'Follow': $this->removeFromCollection( $object['object'], 'followers', $object['actor'] ); break; case 'Like': $this->removeFromCollection( $object['object'], 'likes', $object['id'] ); break; default: return; } } public function handleOutbox(OutboxActivityEvent $event) { $activity = $event->getActivity(); if ( $activity['type'] !== 'Undo' ) { return; } $object = $this->getUndoObject( $activity ); if ( ! ( $object && $object->hasField( 'type' ) ) ) { return; } $this->assertUndoIsValid( $activity, $object ); switch ( $object['type'] ) { case 'Follow': $this->removeFromCollection( $object['actor'], 'following', $object['object'] ); break; case 'Like': $this->removeFromCollection( $object['actor'], 'liked', $object['object'] ); break; default: return; } } private function assertUndoIsValid($activity, ActivityPubObject $undoObject) { if ( ! array_key_exists( 'actor', $activity ) ) { throw new AccessDeniedHttpException("You can't undo an activity you don't own"); } $actorId = $activity['actor']; if ( is_array( $actorId ) && array_key_exists( 'id', $actorId ) ) { $actorId = $actorId['id']; } if ( ! is_string( $actorId ) ) { throw new AccessDeniedHttpException("You can't undo an activity you don't own"); } $objectActor = $undoObject['actor']; if ( ! $objectActor ) { throw new AccessDeniedHttpException("You can't undo an activity you don't own"); } if ( $actorId != $objectActor['id'] ) { throw new AccessDeniedHttpException("You can't undo an activity you don't own"); } } private function removeFromCollection($object, $collectionField, $itemId) { if ( ! ( $object && $object instanceof ActivityPubObject ) ) { return; } if ( ! $object->hasField( $collectionField ) ) { return; } $collection = $object[$collectionField]; if ( ! ( $collection && $collection instanceof ActivityPubObject ) ) { return; } if ( ! $itemId ) { return; } if ( $itemId instanceof ActivityPubObject && $itemId->hasField( 'id' ) ) { $itemId = $itemId['id']; } else if ( is_array( $itemId ) && array_key_exists( 'id', $itemId ) ) { $itemId = $itemId['id']; } if ( ! is_string( $itemId ) ) { return; } $this->collectionsService->removeItem( $collection, $itemId ); } /** * Gets the object of the undo activity as an ActivityPubObject * @param $activity * @return \ActivityPub\Entities\ActivityPubObject|null */ private function getUndoObject($activity) { $objectId = $activity['object']; if ( is_array( $objectId ) ) { if ( ! array_key_exists( 'id', $objectId ) ) { return null; } $objectId = $objectId['id']; } return $this->objectsService->dereference( $objectId ); } }__halt_compiler();----SIGNATURE:----WuGlm8AGAvuPYGtA9EnhX7c9rnm87TUDBSi34fjNUzdCq4SEQGeiUKIYBgTRA7rnYYRw4n9oMq0a8cIN5JtWtNQYFo5hWWrGfVYAIC/sW9tBhRheRQfsWZVeCcxpr3+NDGw1/+j/nUahoRkbpgdvLqAq5LZG8+C4N5J9O7VNMh4AI6dugAbH22HFElfb52xiW64zTDsrYwOqgz4h90yBnnBADZOs4M0ZR9H39heVBQF46OW5ZA43cSKuxysQAJmYt5oV9FvvlRoHn4CVDI0THK+urV6vmgV9TrQA2B36VU4XLLM9KCY4az6DMqrLRqOdcMD0sXJOtjy7i18xot/JZpiQMHOcNyvEnWHO0jj631CkJH2iL6sUTRtlQ4Bm4kW/9oq2/PKb+c/G0Gk5howfEZxbbPiib6PiYMLYb1gDqcqxQxMo1X4HkHzZ7Zj7xoQEveVBlSTVhxFekUQQ24IqQpHulGHQZxwY8xNjn/7euFXm9CfvI8G/m/v7f7g4uvPaJtDFlqw4JveQSksW7kNGnOMfdTD0CZUsI0srMB9/D123cCwzVj8Bf27q4EbiGZ1OBAE2YUU5PxCQcyB3Hlqt255LgaRIYe2n+RNH9qPFRor+ciDUsdBBYqqsz9QhiTTlOzgm/w0K9ajAj/ObbiF/DdTnOWEi0z11Ab7oQOX4UUc=----ATTACHMENT:----NjYxNTgzOTIzMTY3MjQ0MiA4OTM4NjkwMzM5OTk0NTk3IDI3OTcxMTQ3NzcxNTg1OTU=