Outbox.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. /**
  20. * ActivityPub implementation for GNU social
  21. *
  22. * @package GNUsocial
  23. * @category ActivityPub
  24. *
  25. * @author Diogo Peralta Cordeiro <@diogo.site>
  26. * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org
  27. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  28. */
  29. namespace Plugin\ActivityPub\Controller;
  30. use function App\Core\I18n\_m;
  31. use App\Core\Log;
  32. use App\Core\Router;
  33. use App\Entity\Activity;
  34. use App\Entity\Actor;
  35. use App\Util\Exception\ClientException;
  36. use Component\Notification\Entity\Notification;
  37. use Plugin\ActivityPub\Util\OrderedCollectionController;
  38. use Symfony\Component\HttpFoundation\Request;
  39. /**
  40. * ActivityPub Outbox Handler
  41. *
  42. * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org
  43. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  44. */
  45. class Outbox extends OrderedCollectionController
  46. {
  47. /**
  48. * Create an Inbox Handler to receive something from someone.
  49. */
  50. public function viewOutboxByActorId(Request $request, int $gsactor_id): array
  51. {
  52. $actor = Actor::getById($gsactor_id);
  53. if (\is_null($actor)) {
  54. throw new ClientException(_m('No such actor.'), 404);
  55. } elseif (!$actor->getIsLocal()) {
  56. throw new ClientException(_m('We have no authority over a remote actor\'s outbox.'), 400);
  57. }
  58. $this->actor_id = $gsactor_id;
  59. Log::debug('ActivityPub Outbox: Received a GET request.');
  60. if ($actor->getType() !== Actor::GROUP) {
  61. $activities = Activity::getAllActivitiesByActor($actor);
  62. } else {
  63. $activities = Notification::getAllActivitiesTargetedAtActor($actor);
  64. }
  65. foreach ($activities as $act) {
  66. $this->ordered_items[] = Router::url('activity_view', ['id' => $act->getId()], ROUTER::ABSOLUTE_URL);
  67. }
  68. $this->route = 'activitypub_actor_outbox';
  69. $this->route_args = ['gsactor_id' => $actor->getId(), 'page' => $this->int('page') ?? 0];
  70. return $this->handle($request);
  71. }
  72. }