|
|
@@ -1,6 +1,6 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
|
|
|
|
// {{{ License
|
|
|
|
// {{{ License
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
@@ -24,6 +24,7 @@ namespace Plugin\DeleteNote;
|
|
|
|
use ActivityPhp\Type\AbstractObject;
|
|
|
|
use ActivityPhp\Type\AbstractObject;
|
|
|
|
use App\Core\DB\DB;
|
|
|
|
use App\Core\DB\DB;
|
|
|
|
use App\Core\Event;
|
|
|
|
use App\Core\Event;
|
|
|
|
|
|
|
|
use function App\Core\I18n\_m;
|
|
|
|
use App\Core\Modules\NoteHandlerPlugin;
|
|
|
|
use App\Core\Modules\NoteHandlerPlugin;
|
|
|
|
use App\Core\Router\RouteLoader;
|
|
|
|
use App\Core\Router\RouteLoader;
|
|
|
|
use App\Core\Router\Router;
|
|
|
|
use App\Core\Router\Router;
|
|
|
@@ -35,9 +36,6 @@ use App\Util\Exception\ClientException;
|
|
|
|
use DateTime;
|
|
|
|
use DateTime;
|
|
|
|
use Plugin\ActivityPub\Entity\ActivitypubActivity;
|
|
|
|
use Plugin\ActivityPub\Entity\ActivitypubActivity;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use function App\Core\I18n\_m;
|
|
|
|
|
|
|
|
use function is_int;
|
|
|
|
|
|
|
|
use function is_null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Delete note plugin main class.
|
|
|
|
* Delete note plugin main class.
|
|
|
@@ -75,10 +73,6 @@ class DeleteNote extends NoteHandlerPlugin
|
|
|
|
* (object)**, by the given **Actor (subject)**. Launches the
|
|
|
|
* (object)**, by the given **Actor (subject)**. Launches the
|
|
|
|
* NewNotification Event, stating who dared to call Undertaker.
|
|
|
|
* NewNotification Event, stating who dared to call Undertaker.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param \App\Entity\Actor $actor
|
|
|
|
|
|
|
|
* @param \App\Entity\Note $note
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return \App\Entity\Activity
|
|
|
|
|
|
|
|
* @throws \App\Util\Exception\ClientException
|
|
|
|
* @throws \App\Util\Exception\ClientException
|
|
|
|
* @throws \App\Util\Exception\ServerException
|
|
|
|
* @throws \App\Util\Exception\ServerException
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@@ -103,11 +97,6 @@ class DeleteNote extends NoteHandlerPlugin
|
|
|
|
* Checks whether the Note has already been deleted, only passing on the
|
|
|
|
* Checks whether the Note has already been deleted, only passing on the
|
|
|
|
* responsibility to undertaker if the Note wasn't.
|
|
|
|
* responsibility to undertaker if the Note wasn't.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param \App\Entity\Note|int $note
|
|
|
|
|
|
|
|
* @param \App\Entity\Actor|int $actor
|
|
|
|
|
|
|
|
* @param string $source
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return \App\Entity\Activity|null
|
|
|
|
|
|
|
|
* @throws \App\Util\Exception\ClientException
|
|
|
|
* @throws \App\Util\Exception\ClientException
|
|
|
|
* @throws \App\Util\Exception\DuplicateFoundException
|
|
|
|
* @throws \App\Util\Exception\DuplicateFoundException
|
|
|
|
* @throws \App\Util\Exception\NotFoundException
|
|
|
|
* @throws \App\Util\Exception\NotFoundException
|
|
|
@@ -115,10 +104,10 @@ class DeleteNote extends NoteHandlerPlugin
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function deleteNote(Note|int $note, Actor|int $actor, string $source = 'web'): ?Activity
|
|
|
|
public static function deleteNote(Note|int $note, Actor|int $actor, string $source = 'web'): ?Activity
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$actor = is_int($actor) ? Actor::getById($actor) : $actor;
|
|
|
|
$actor = \is_int($actor) ? Actor::getById($actor) : $actor;
|
|
|
|
$note = is_int($note) ? Note::getById($note) : $note;
|
|
|
|
$note = \is_int($note) ? Note::getById($note) : $note;
|
|
|
|
// Try and find if note was already deleted
|
|
|
|
// Try and find if note was already deleted
|
|
|
|
if (is_null(DB::findOneBy(Activity::class, ['verb' => 'delete', 'object_type' => 'note', 'object_id' => $note->getId()], return_null: true))) {
|
|
|
|
if (\is_null(DB::findOneBy(Activity::class, ['verb' => 'delete', 'object_type' => 'note', 'object_id' => $note->getId()], return_null: true))) {
|
|
|
|
// If none found, then undertaker has a job to do
|
|
|
|
// If none found, then undertaker has a job to do
|
|
|
|
return self::undertaker($actor, $note);
|
|
|
|
return self::undertaker($actor, $note);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@@ -130,8 +119,6 @@ class DeleteNote extends NoteHandlerPlugin
|
|
|
|
* Adds and connects the _delete_note_action_ route to
|
|
|
|
* Adds and connects the _delete_note_action_ route to
|
|
|
|
* Controller\DeleteNote::class
|
|
|
|
* Controller\DeleteNote::class
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param \App\Core\Router\RouteLoader $r
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool Event hook
|
|
|
|
* @return bool Event hook
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function onAddRoute(RouteLoader $r)
|
|
|
|
public function onAddRoute(RouteLoader $r)
|
|
|
@@ -147,31 +134,28 @@ class DeleteNote extends NoteHandlerPlugin
|
|
|
|
* Adds an anchor link to the route _delete_note_action_ in the **Note card
|
|
|
|
* Adds an anchor link to the route _delete_note_action_ in the **Note card
|
|
|
|
* template**. More specifically, in the **note_actions block**.
|
|
|
|
* template**. More specifically, in the **note_actions block**.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
|
|
|
|
|
|
|
* @param \App\Entity\Note $note
|
|
|
|
|
|
|
|
* @param array $actions
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool Event hook
|
|
|
|
|
|
|
|
* @throws \App\Util\Exception\DuplicateFoundException
|
|
|
|
* @throws \App\Util\Exception\DuplicateFoundException
|
|
|
|
* @throws \App\Util\Exception\NotFoundException
|
|
|
|
* @throws \App\Util\Exception\NotFoundException
|
|
|
|
* @throws \App\Util\Exception\ServerException
|
|
|
|
* @throws \App\Util\Exception\ServerException
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool Event hook
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions)
|
|
|
|
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (is_null($actor = Common::actor())) {
|
|
|
|
if (\is_null($actor = Common::actor())) {
|
|
|
|
return Event::next;
|
|
|
|
return Event::next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Only add action if note wasn't already deleted!
|
|
|
|
// Only add action if note wasn't already deleted!
|
|
|
|
if (is_null(DB::findOneBy(Activity::class, ['verb' => 'delete', 'object_type' => 'note', 'object_id' => $note->getId()], return_null: true))
|
|
|
|
if (\is_null(DB::findOneBy(Activity::class, ['verb' => 'delete', 'object_type' => 'note', 'object_id' => $note->getId()], return_null: true))
|
|
|
|
// And has permissions
|
|
|
|
// And has permissions
|
|
|
|
&& $actor->canAdmin($note->getActor())) {
|
|
|
|
&& $actor->canAdmin($note->getActor())) {
|
|
|
|
$delete_action_url = Router::url('delete_note_action', ['note_id' => $note->getId()]);
|
|
|
|
$delete_action_url = Router::url('delete_note_action', ['note_id' => $note->getId()]);
|
|
|
|
$query_string = $request->getQueryString();
|
|
|
|
$query_string = $request->getQueryString();
|
|
|
|
$delete_action_url .= '?from=' . mb_substr($query_string, 2);
|
|
|
|
$delete_action_url .= '?from=' . mb_substr($query_string, 2);
|
|
|
|
$actions[] = [
|
|
|
|
$actions[] = [
|
|
|
|
'title' => _m('Delete note'),
|
|
|
|
'title' => _m('Delete note'),
|
|
|
|
'classes' => '',
|
|
|
|
'classes' => '',
|
|
|
|
'url' => $delete_action_url,
|
|
|
|
'url' => $delete_action_url,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -190,7 +174,7 @@ class DeleteNote extends NoteHandlerPlugin
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
|
|
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function activitypub_handler(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
|
|
|
|
private function activitypub_handler(Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): bool
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ($type_activity->get('type') !== 'Delete'
|
|
|
|
if ($type_activity->get('type') !== 'Delete'
|
|
|
|
|| !($type_object instanceof Note)) {
|
|
|
|
|| !($type_object instanceof Note)) {
|
|
|
@@ -221,7 +205,7 @@ class DeleteNote extends NoteHandlerPlugin
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
|
|
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function onNewActivityPubActivity(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, \ActivityPhp\Type\AbstractObject $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
|
|
|
|
public function onNewActivityPubActivity(Actor $actor, AbstractObject $type_activity, AbstractObject $type_object, ?ActivitypubActivity &$ap_act): bool
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
|
|
|
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -236,7 +220,7 @@ class DeleteNote extends NoteHandlerPlugin
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
|
|
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function onNewActivityPubActivityWithObject(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
|
|
|
|
public function onNewActivityPubActivityWithObject(Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): bool
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
|
|
|
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
|
|
|
}
|
|
|
|
}
|
|
|
|