From 04431885aa31832c0eedfb3104ab648222a00b6b Mon Sep 17 00:00:00 2001 From: Phablulo Date: Sun, 16 Jan 2022 22:55:18 -0300 Subject: [PATCH] [PLUGIN][PinnedNotes] Fix ActivityPub config --- .../PinnedNotes/Controller/PinnedNotes.php | 22 ++++++++++++++++++ plugins/PinnedNotes/PinnedNotes.php | 23 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/plugins/PinnedNotes/Controller/PinnedNotes.php b/plugins/PinnedNotes/Controller/PinnedNotes.php index 60a3eefe91..2a3ecd52c1 100644 --- a/plugins/PinnedNotes/Controller/PinnedNotes.php +++ b/plugins/PinnedNotes/Controller/PinnedNotes.php @@ -27,10 +27,13 @@ use App\Core\DB\DB; use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Router\Router; +use App\Entity\Actor; +use App\Entity\LocalUser; use App\Util\Common; use App\Util\Exception\ClientException; use App\Util\Exception\NoSuchNoteException; use App\Util\Exception\RedirectException; +use Component\Collection\Collection; use Component\Collection\Util\Controller\FeedController; use Plugin\PinnedNotes\Entity as E; use Symfony\Component\Form\Extension\Core\Type\SubmitType; @@ -38,6 +41,25 @@ use Symfony\Component\HttpFoundation\Request; class PinnedNotes extends FeedController { + public function listPinsByNickname(Request $request, string $nickname) + { + $actor = LocalUser::getByNickname($request->attributes->get('nickname'))->getActor(); + return $this->listPins($request, $actor->getId()); + } + + public function listPinsById(Request $request, int $id) + { + return $this->listPins($request, $id); + } + + public function listPins(Request $request, int $id) + { + $locale = Common::currentLanguage()->getLocale(); + $actor = DB::findOneBy(Actor::class, ['id' => $id]); + $page = (int) ($request->query->get('page') ?? 1); + return Collection::query('pinned:true actor:' . $id, $page, $locale, $actor); + } + public function togglePin(Request $request, int $id) { $user = Common::ensureLoggedIn(); diff --git a/plugins/PinnedNotes/PinnedNotes.php b/plugins/PinnedNotes/PinnedNotes.php index 75e538af62..90ebc06085 100644 --- a/plugins/PinnedNotes/PinnedNotes.php +++ b/plugins/PinnedNotes/PinnedNotes.php @@ -41,6 +41,7 @@ use App\Entity\LocalUser; use App\Entity\Note; use App\Util\Common; use App\Util\Formatting; +use App\Util\Nickname; use Component\Collection\Collection; use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\ORM\Query\Expr; @@ -57,6 +58,19 @@ class PinnedNotes extends Plugin { // Pin and unpin notes $r->connect(id: 'toggle_note_pin', uri_path: '/object/note/{id<\d+>}/pin', target: [C\PinnedNotes::class, 'togglePin']); + // list of user pins, by id and nickname + // it's meant to be used by the ActivityPub plugin + $r->connect( + id: 'list_pinned_notes_by_id', + uri_path: '/actor/{id<\d+>}/pinned_notes', + target: [C\PinnedNotes::class, 'listPinsById'], + ); + $r->connect( + id: 'list_pinned_notes_by_nickname', + uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}/pinned_notes', + target: [C\PinnedNotes::class, 'listPinsByNickname'], + ); + return Event::next; } @@ -142,7 +156,14 @@ class PinnedNotes extends Plugin $note_id = end($uri_parts); $is_pinned = !\is_null(DB::findOneBy(E\PinnedNotes::class, ['actor_id' => $actor->getId(), 'note_id' => $note_id], return_null: true)); - $type->set('pinned', $is_pinned); + $type->set('featured', $is_pinned); + } elseif ($type_name === 'Person') { + $actor = \Plugin\ActivityPub\ActivityPub::getActorByUri($type->get('id')); + $router_args = ['id' => $actor->getId()]; + $router_type = Router::ABSOLUTE_URL; + $action_url = Router::url('list_pinned_notes_by_id', $router_args, $router_type); + + $type->set('featured', $action_url); } return Event::next; }