[PLUGIN][ActivityPub][Favourite][Repeat][Delete] Document event handlers
This commit is contained in:
parent
8274e93ed5
commit
137723e59a
|
@ -1,6 +1,7 @@
|
||||||
**ActivityPubValidateActivityStreamsTwoData**: To extend an Activity properties that we are managing from JSON
|
**ActivityPubValidateActivityStreamsTwoData**: To extend an Activity properties that we are managing from JSON
|
||||||
* `@param string $type_name` When we handle a Type, we will send you the type identifier of the one being handleded
|
* `@param string $type_name` When we handle a Type, we will send you the type identifier of the one being handleded
|
||||||
* `@param array &$validators` attribute => Validator the array key should have the attribute name that you want to hand, the value should be a validator class
|
* `@param array &$validators` attribute => Validator the array key should have the attribute name that you want to hand, the value should be a validator class
|
||||||
|
* `@return` Returns `Event::next`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
@ -37,12 +38,13 @@ class myValidator extends \Plugin\ActivityPub\Util\ModelValidator
|
||||||
**ActivityPubAddActivityStreamsTwoData**: To add attributes to an entity that we are managing to JSON (commonly federating out via ActivityPub)
|
**ActivityPubAddActivityStreamsTwoData**: To add attributes to an entity that we are managing to JSON (commonly federating out via ActivityPub)
|
||||||
* `@param string $type_name` When we handle a Type, we will send you the type identifier of the one being handleded
|
* `@param string $type_name` When we handle a Type, we will send you the type identifier of the one being handleded
|
||||||
* `@param \ActivityPhp\Type\AbstractObject &$type_activity` The Activity in the intermediate format between Model and JSON
|
* `@param \ActivityPhp\Type\AbstractObject &$type_activity` The Activity in the intermediate format between Model and JSON
|
||||||
|
* `@return` Returns `Event::next`
|
||||||
|
|
||||||
**ActivityPubActivityStreamsTwoResponse**: To add a route to ActivityPub (the route must already exist in your plugin) (commonly being requested to ActivityPub)
|
**ActivityPubActivityStreamsTwoResponse**: To add a route to ActivityPub (the route must already exist in your plugin) (commonly being requested to ActivityPub)
|
||||||
* `@param string $route` Route identifier
|
* `@param string $route` Route identifier
|
||||||
* `@param array $vars` From your controller
|
* `@param array $vars` From your controller
|
||||||
* `@param \Plugin\ActivityPub\Util\TypeResponse &$response` The JSON (protip: ModelResponse's handler will convert entities into TypeResponse)
|
* `@param \Plugin\ActivityPub\Util\TypeResponse &$response` The JSON (protip: ModelResponse's handler will convert entities into TypeResponse)
|
||||||
|
* `@return` Returns `Event::stop` if handled, `Event::next` otherwise
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
@ -61,9 +63,30 @@ public function onActivityPubActivityStreamsTwoResponse(string $route, arrray $v
|
||||||
* `@param \ActivityPhp\Type\AbstractObject $type_activity` Activity
|
* `@param \ActivityPhp\Type\AbstractObject $type_activity` Activity
|
||||||
* `@param \ActivityPhp\Type\AbstractObject $type_object` Object
|
* `@param \ActivityPhp\Type\AbstractObject $type_object` Object
|
||||||
* `@param ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act` ActivitypubActivity
|
* `@param ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act` ActivitypubActivity
|
||||||
|
* `@return` Returns `Event::stop` if handled, `Event::next` otherwise
|
||||||
|
|
||||||
**NewActivityPubActivityWithObject**: To convert an Activity Streams 2.0 formatted activity with a known object into Entities (commonly when we receive a JSON in our inbox)
|
**NewActivityPubActivityWithObject**: To convert an Activity Streams 2.0 formatted activity with a known object into Entities (commonly when we receive a JSON in our inbox)
|
||||||
* `@param Actor $actor` Actor who authored the activity
|
* `@param Actor $actor` Actor who authored the activity
|
||||||
* `@param \ActivityPhp\Type\AbstractObject $type_activity` Activity
|
* `@param \ActivityPhp\Type\AbstractObject $type_activity` Activity
|
||||||
* `@param Entity $type_object` Object
|
* `@param Entity $type_object` Object
|
||||||
* `@param ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act` ActivitypubActivity
|
* `@param ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act` ActivitypubActivity
|
||||||
|
* `@return` Returns `Event::stop` if handled, `Event::next` otherwise
|
||||||
|
|
||||||
|
**GSVerbToActivityStreamsTwoActivityType**: Translate a GNU social internal verb to an Activity Streams 2.0 one
|
||||||
|
* `@param string $verb` GNU social's internal verb
|
||||||
|
* `@param \ActivityPhp\Type\AbstractObject &$gs_verb_to_activity_stream_two_verb` Activity Streams 2.0 verb
|
||||||
|
* `@return` Returns `Event::stop` if handled, `Event::next` otherwise
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```php
|
||||||
|
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
|
||||||
|
{
|
||||||
|
if ($verb === '{GS verb}') {
|
||||||
|
$gs_verb_to_activity_stream_two_verb = '{AS2 verb}';
|
||||||
|
return Event::stop;
|
||||||
|
}
|
||||||
|
return Event::next;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
@ -178,11 +178,19 @@ class DeleteNote extends NoteHandlerPlugin
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// ActivityPub handling and processing for Delete note is below
|
||||||
* ActivityPub handling and processing for DeleteNote start
|
|
||||||
*/
|
|
||||||
|
|
||||||
private function activitypub_handler(Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): bool
|
/**
|
||||||
|
* ActivityPub Inbox handler for Delete activities
|
||||||
|
*
|
||||||
|
* @param Actor $actor Actor who authored the activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_activity Activity Streams 2.0 Activity
|
||||||
|
* @param mixed $type_object Activity's Object
|
||||||
|
* @param null|\Plugin\ActivityPub\Entity\ActivitypubActivity $ap_act Resulting ActivitypubActivity
|
||||||
|
*
|
||||||
|
* @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
|
||||||
{
|
{
|
||||||
if ($type_activity->get('type') !== 'Delete'
|
if ($type_activity->get('type') !== 'Delete'
|
||||||
|| !($type_object instanceof Note)) {
|
|| !($type_object instanceof Note)) {
|
||||||
|
@ -190,9 +198,9 @@ class DeleteNote extends NoteHandlerPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
$activity = self::deleteNote($type_object, $actor, source: 'ActivityPub');
|
$activity = self::deleteNote($type_object, $actor, source: 'ActivityPub');
|
||||||
if (!is_null($activity)) {
|
if (!\is_null($activity)) {
|
||||||
// Store ActivityPub Activity
|
// Store ActivityPub Activity
|
||||||
$ap_act = ActivitypubActivity::create([
|
$ap_act = \Plugin\ActivityPub\Entity\ActivitypubActivity::create([
|
||||||
'activity_id' => $activity->getId(),
|
'activity_id' => $activity->getId(),
|
||||||
'activity_uri' => $type_activity->get('id'),
|
'activity_uri' => $type_activity->get('id'),
|
||||||
'created' => new DateTime($type_activity->get('published') ?? 'now'),
|
'created' => new DateTime($type_activity->get('published') ?? 'now'),
|
||||||
|
@ -203,16 +211,44 @@ class DeleteNote extends NoteHandlerPlugin
|
||||||
return Event::stop;
|
return Event::stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNewActivityPubActivity(Actor $actor, AbstractObject $type_activity, AbstractObject $type_object, ?ActivitypubActivity &$ap_act): bool
|
/**
|
||||||
|
* Convert an Activity Streams 2.0 Delete into the appropriate Delete entities
|
||||||
|
*
|
||||||
|
* @param Actor $actor Actor who authored the activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_activity Activity Streams 2.0 Activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_object Activity Streams 2.0 Object
|
||||||
|
* @param null|\Plugin\ActivityPub\Entity\ActivitypubActivity $ap_act Resulting ActivitypubActivity
|
||||||
|
*
|
||||||
|
* @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
|
||||||
{
|
{
|
||||||
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNewActivityPubActivityWithObject(Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): bool
|
/**
|
||||||
|
* Convert an Activity Streams 2.0 formatted activity with a known object into Entities
|
||||||
|
*
|
||||||
|
* @param Actor $actor Actor who authored the activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_activity Activity Streams 2.0 Activity
|
||||||
|
* @param mixed $type_object Object
|
||||||
|
* @param null|\Plugin\ActivityPub\Entity\ActivitypubActivity $ap_act Resulting ActivitypubActivity
|
||||||
|
*
|
||||||
|
* @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
|
||||||
{
|
{
|
||||||
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate GNU social internal verb 'delete' to Activity Streams 2.0 'Delete'
|
||||||
|
*
|
||||||
|
* @param string $verb GNU social's internal verb
|
||||||
|
* @param null|string $gs_verb_to_activity_stream_two_verb Resulting Activity Streams 2.0 verb
|
||||||
|
*
|
||||||
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
||||||
|
*/
|
||||||
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
|
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
|
||||||
{
|
{
|
||||||
if ($verb === 'delete') {
|
if ($verb === 'delete') {
|
||||||
|
|
|
@ -167,8 +167,18 @@ class Favourite extends NoteHandlerPlugin
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActivityPub
|
// ActivityPub handling and processing for Favourites is below
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ActivityPub Inbox handler for Like and Undo Like activities
|
||||||
|
*
|
||||||
|
* @param Actor $actor Actor who authored the activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_activity Activity Streams 2.0 Activity
|
||||||
|
* @param mixed $type_object Activity's Object
|
||||||
|
* @param null|\Plugin\ActivityPub\Entity\ActivitypubActivity $ap_act Resulting ActivitypubActivity
|
||||||
|
*
|
||||||
|
* @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, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
|
||||||
{
|
{
|
||||||
if (!\in_array($type_activity->get('type'), ['Like', 'Undo'])) {
|
if (!\in_array($type_activity->get('type'), ['Like', 'Undo'])) {
|
||||||
|
@ -224,16 +234,44 @@ class Favourite extends NoteHandlerPlugin
|
||||||
return Event::stop;
|
return Event::stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert an Activity Streams 2.0 Like or Undo Like into the appropriate Favourite and Undo Favourite entities
|
||||||
|
*
|
||||||
|
* @param Actor $actor Actor who authored the activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_activity Activity Streams 2.0 Activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_object Activity Streams 2.0 Object
|
||||||
|
* @param null|\Plugin\ActivityPub\Entity\ActivitypubActivity $ap_act Resulting ActivitypubActivity
|
||||||
|
*
|
||||||
|
* @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, \ActivityPhp\Type\AbstractObject $type_activity, \ActivityPhp\Type\AbstractObject $type_object, ?\Plugin\ActivityPub\Entity\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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert an Activity Streams 2.0 formatted activity with a known object into Entities
|
||||||
|
*
|
||||||
|
* @param Actor $actor Actor who authored the activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_activity Activity Streams 2.0 Activity
|
||||||
|
* @param mixed $type_object Object
|
||||||
|
* @param null|\Plugin\ActivityPub\Entity\ActivitypubActivity $ap_act Resulting ActivitypubActivity
|
||||||
|
*
|
||||||
|
* @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, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate GNU social internal verb 'favourite' to Activity Streams 2.0 'Like'
|
||||||
|
*
|
||||||
|
* @param string $verb GNU social's internal verb
|
||||||
|
* @param null|string $gs_verb_to_activity_stream_two_verb Resulting Activity Streams 2.0 verb
|
||||||
|
*
|
||||||
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
||||||
|
*/
|
||||||
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
|
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
|
||||||
{
|
{
|
||||||
if ($verb === 'favourite') {
|
if ($verb === 'favourite') {
|
||||||
|
|
|
@ -21,9 +21,9 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Plugin\RepeatNote;
|
namespace Plugin\RepeatNote;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -31,16 +31,17 @@ use App\Entity\Activity;
|
||||||
use App\Entity\Actor;
|
use App\Entity\Actor;
|
||||||
use App\Entity\Note;
|
use App\Entity\Note;
|
||||||
use App\Util\Common;
|
use App\Util\Common;
|
||||||
|
use App\Util\Exception\BugFoundException;
|
||||||
|
use App\Util\Exception\ClientException;
|
||||||
|
use App\Util\Exception\DuplicateFoundException;
|
||||||
use App\Util\Exception\ServerException;
|
use App\Util\Exception\ServerException;
|
||||||
use App\Util\Formatting;
|
use App\Util\Formatting;
|
||||||
use Component\Language\Entity\Language;
|
use Component\Language\Entity\Language;
|
||||||
use Component\Posting\Posting;
|
use Component\Posting\Posting;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Plugin\ActivityPub\Entity\ActivitypubActivity;
|
|
||||||
use Plugin\RepeatNote\Entity\NoteRepeat;
|
use Plugin\RepeatNote\Entity\NoteRepeat;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use function App\Core\I18n\_m;
|
|
||||||
use const SORT_REGULAR;
|
use const SORT_REGULAR;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class RepeatNote extends NoteHandlerPlugin
|
class RepeatNote extends NoteHandlerPlugin
|
||||||
{
|
{
|
||||||
|
@ -56,15 +57,10 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
* In the end, the Activity is created, and a new notification for the
|
* In the end, the Activity is created, and a new notification for the
|
||||||
* repeat Activity created
|
* repeat Activity created
|
||||||
*
|
*
|
||||||
* @param \App\Entity\Note $note
|
* @throws BugFoundException
|
||||||
* @param int $actor_id
|
* @throws ClientException
|
||||||
* @param string $source
|
* @throws DuplicateFoundException
|
||||||
*
|
* @throws ServerException
|
||||||
* @return \App\Entity\Activity|null
|
|
||||||
* @throws \App\Util\Exception\BugFoundException
|
|
||||||
* @throws \App\Util\Exception\ClientException
|
|
||||||
* @throws \App\Util\Exception\DuplicateFoundException
|
|
||||||
* @throws \App\Util\Exception\ServerException
|
|
||||||
*/
|
*/
|
||||||
public static function repeatNote(Note $note, int $actor_id, string $source = 'web'): ?Activity
|
public static function repeatNote(Note $note, int $actor_id, string $source = 'web'): ?Activity
|
||||||
{
|
{
|
||||||
|
@ -122,12 +118,7 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
* Finally, creates a new Activity, undoing the repeat, and the respective
|
* Finally, creates a new Activity, undoing the repeat, and the respective
|
||||||
* Notification is handled.
|
* Notification is handled.
|
||||||
*
|
*
|
||||||
* @param int $note_id
|
* @throws ServerException
|
||||||
* @param int $actor_id
|
|
||||||
* @param string $source
|
|
||||||
*
|
|
||||||
* @return \App\Entity\Activity|null
|
|
||||||
* @throws \App\Util\Exception\ServerException
|
|
||||||
*/
|
*/
|
||||||
public static function unrepeatNote(int $note_id, int $actor_id, string $source = 'web'): ?Activity
|
public static function unrepeatNote(int $note_id, int $actor_id, string $source = 'web'): ?Activity
|
||||||
{
|
{
|
||||||
|
@ -182,16 +173,9 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters repeats out of Conversations, and replaces a repeat with the
|
* Filters repeats out of Conversations, and replaces a repeat with the
|
||||||
* original Note on Actor feed
|
* original Note on Actor feed
|
||||||
*
|
|
||||||
* @param \App\Entity\Actor|null $actor
|
|
||||||
* @param array $notes
|
|
||||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): bool
|
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): bool
|
||||||
{
|
{
|
||||||
|
@ -212,15 +196,10 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML rendering event that adds the repeat form as a note
|
* HTML rendering event that adds the repeat form as a note
|
||||||
* action, if a user is logged in
|
* action, if a user is logged in
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
|
||||||
* @param \App\Entity\Note $note
|
|
||||||
* @param array $actions
|
|
||||||
*
|
|
||||||
* @return bool Event hook
|
* @return bool Event hook
|
||||||
*/
|
*/
|
||||||
public function onAddNoteActions(Request $request, Note $note, array &$actions): bool
|
public function onAddNoteActions(Request $request, Note $note, array &$actions): bool
|
||||||
|
@ -258,7 +237,6 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends in Note information stating who and what user actions were
|
* Appends in Note information stating who and what user actions were
|
||||||
* performed.
|
* performed.
|
||||||
|
@ -330,8 +308,6 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
* - **repeat_remove**
|
* - **repeat_remove**
|
||||||
* same as above, except that it undoes the aforementioned action
|
* same as above, except that it undoes the aforementioned action
|
||||||
*
|
*
|
||||||
* @param \App\Core\Router\RouteLoader $r
|
|
||||||
*
|
|
||||||
* @return bool Event hook
|
* @return bool Event hook
|
||||||
*/
|
*/
|
||||||
public function onAddRoute(RouteLoader $r): bool
|
public function onAddRoute(RouteLoader $r): bool
|
||||||
|
@ -343,36 +319,25 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// ActivityPub handling and processing for Repeats is below
|
||||||
* ActivityPub handling and processing for Repeat start
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the Repeat Activity
|
* ActivityPub Inbox handler for Announces and Undo Announce activities
|
||||||
*
|
*
|
||||||
* @param \App\Entity\Actor $actor
|
* @param Actor $actor Actor who authored the activity
|
||||||
* @param \ActivityPhp\Type\AbstractObject $type_activity
|
* @param \ActivityPhp\Type\AbstractObject $type_activity Activity Streams 2.0 Activity
|
||||||
* @param mixed $type_object
|
* @param mixed $type_object Activity's Object
|
||||||
* @param \Plugin\ActivityPub\Entity\ActivitypubActivity|null $ap_act
|
* @param null|\Plugin\ActivityPub\Entity\ActivitypubActivity $ap_act Resulting ActivitypubActivity
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
||||||
* @throws \App\Util\Exception\BugFoundException
|
|
||||||
* @throws \App\Util\Exception\ClientException
|
|
||||||
* @throws \App\Util\Exception\DuplicateFoundException
|
|
||||||
* @throws \App\Util\Exception\NoSuchActorException
|
|
||||||
* @throws \App\Util\Exception\ServerException
|
|
||||||
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
|
|
||||||
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
|
|
||||||
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
|
|
||||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
|
||||||
*/
|
*/
|
||||||
private function activitypub_handler(Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): bool
|
private function activitypub_handler(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
|
||||||
{
|
{
|
||||||
if (!\in_array($type_activity->get('type'), ['Announce', 'Undo'])) {
|
if (!\in_array($type_activity->get('type'), ['Announce', 'Undo'])) {
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
if ($type_activity->get('type') === 'Announce') { // Repeat
|
if ($type_activity->get('type') === 'Announce') { // Repeat
|
||||||
if ($type_object instanceof AbstractObject) {
|
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
|
||||||
if ($type_object->get('type') === 'Note') {
|
if ($type_object->get('type') === 'Note') {
|
||||||
$note = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object);
|
$note = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object);
|
||||||
$note_id = $note->getId();
|
$note_id = $note->getId();
|
||||||
|
@ -386,7 +351,7 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
} else { // Undo Repeat
|
} else { // Undo Repeat
|
||||||
if ($type_object instanceof AbstractObject) {
|
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
|
||||||
$ap_prev_repeat_act = \Plugin\ActivityPub\Util\Model\Activity::fromJson($type_object);
|
$ap_prev_repeat_act = \Plugin\ActivityPub\Util\Model\Activity::fromJson($type_object);
|
||||||
$prev_repeat_act = $ap_prev_repeat_act->getActivity();
|
$prev_repeat_act = $ap_prev_repeat_act->getActivity();
|
||||||
if ($prev_repeat_act->getVerb() === 'repeat' && $prev_repeat_act->getObjectType() === 'note') {
|
if ($prev_repeat_act->getVerb() === 'repeat' && $prev_repeat_act->getObjectType() === 'note') {
|
||||||
|
@ -412,7 +377,7 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
}
|
}
|
||||||
if (!\is_null($activity)) {
|
if (!\is_null($activity)) {
|
||||||
// Store ActivityPub Activity
|
// Store ActivityPub Activity
|
||||||
$ap_act = ActivitypubActivity::create([
|
$ap_act = \Plugin\ActivityPub\Entity\ActivitypubActivity::create([
|
||||||
'activity_id' => $activity->getId(),
|
'activity_id' => $activity->getId(),
|
||||||
'activity_uri' => $type_activity->get('id'),
|
'activity_uri' => $type_activity->get('id'),
|
||||||
'created' => new DateTime($type_activity->get('published') ?? 'now'),
|
'created' => new DateTime($type_activity->get('published') ?? 'now'),
|
||||||
|
@ -423,16 +388,44 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
return Event::stop;
|
return Event::stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNewActivityPubActivity(Actor $actor, AbstractObject $type_activity, AbstractObject $type_object, ?ActivitypubActivity &$ap_act): bool
|
/**
|
||||||
|
* Convert an Activity Streams 2.0 Announce or Undo Announce into the appropriate Repeat and Undo Repeat entities
|
||||||
|
*
|
||||||
|
* @param Actor $actor Actor who authored the activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_activity Activity Streams 2.0 Activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_object Activity Streams 2.0 Object
|
||||||
|
* @param null|\Plugin\ActivityPub\Entity\ActivitypubActivity $ap_act Resulting ActivitypubActivity
|
||||||
|
*
|
||||||
|
* @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
|
||||||
{
|
{
|
||||||
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNewActivityPubActivityWithObject(Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): bool
|
/**
|
||||||
|
* Convert an Activity Streams 2.0 formatted activity with a known object into Entities
|
||||||
|
*
|
||||||
|
* @param Actor $actor Actor who authored the activity
|
||||||
|
* @param \ActivityPhp\Type\AbstractObject $type_activity Activity Streams 2.0 Activity
|
||||||
|
* @param mixed $type_object Object
|
||||||
|
* @param null|\Plugin\ActivityPub\Entity\ActivitypubActivity $ap_act Resulting ActivitypubActivity
|
||||||
|
*
|
||||||
|
* @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
|
||||||
{
|
{
|
||||||
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate GNU social internal verb 'repeat' to Activity Streams 2.0 'Announce'
|
||||||
|
*
|
||||||
|
* @param string $verb GNU social's internal verb
|
||||||
|
* @param null|string $gs_verb_to_activity_stream_two_verb Resulting Activity Streams 2.0 verb
|
||||||
|
*
|
||||||
|
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
|
||||||
|
*/
|
||||||
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
|
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
|
||||||
{
|
{
|
||||||
if ($verb === 'repeat') {
|
if ($verb === 'repeat') {
|
||||||
|
|
Loading…
Reference in New Issue