[PLUGIN][PinnedNotes] Fix ActivityPub config

This commit is contained in:
Phablulo Joel 2022-01-16 22:55:18 -03:00 committed by Hugo Sales
parent b8a35f9d6d
commit 04431885aa
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 44 additions and 1 deletions

View File

@ -27,10 +27,13 @@ use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Router\Router; use App\Core\Router\Router;
use App\Entity\Actor;
use App\Entity\LocalUser;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use App\Util\Exception\NoSuchNoteException; use App\Util\Exception\NoSuchNoteException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Component\Collection\Collection;
use Component\Collection\Util\Controller\FeedController; use Component\Collection\Util\Controller\FeedController;
use Plugin\PinnedNotes\Entity as E; use Plugin\PinnedNotes\Entity as E;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@ -38,6 +41,25 @@ use Symfony\Component\HttpFoundation\Request;
class PinnedNotes extends FeedController 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) public function togglePin(Request $request, int $id)
{ {
$user = Common::ensureLoggedIn(); $user = Common::ensureLoggedIn();

View File

@ -41,6 +41,7 @@ use App\Entity\LocalUser;
use App\Entity\Note; use App\Entity\Note;
use App\Util\Common; use App\Util\Common;
use App\Util\Formatting; use App\Util\Formatting;
use App\Util\Nickname;
use Component\Collection\Collection; use Component\Collection\Collection;
use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
@ -57,6 +58,19 @@ class PinnedNotes extends Plugin
{ {
// Pin and unpin notes // Pin and unpin notes
$r->connect(id: 'toggle_note_pin', uri_path: '/object/note/{id<\d+>}/pin', target: [C\PinnedNotes::class, 'togglePin']); $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; return Event::next;
} }
@ -142,7 +156,14 @@ class PinnedNotes extends Plugin
$note_id = end($uri_parts); $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)); $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; return Event::next;
} }