upstream V3 development https://www.gnusocial.rocks/v3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EVENTS.md 5.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. **ActivityPubValidateActivityStreamsTwoData**: To extend an Activity properties that we are managing from JSON
  2. * `@param string $type_name` When we handle a Type, we will send you the type identifier of the one being handleded
  3. * `@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
  4. * `@return` Returns `Event::next`
  5. Example:
  6. ```php
  7. public function onActivityPubValidateActivityStreamsTwoData(string $type_name, array &$validators): bool {
  8. if ($type_name === '{Type}') {
  9. $validators['attribute'] = myValidator::class;
  10. }
  11. return Event::next;
  12. }
  13. ```
  14. The Validator should be of the form:
  15. ```php
  16. class myValidator extends \Plugin\ActivityPub\Util\ModelValidator
  17. {
  18. /**
  19. * Validate Attribute's value
  20. *
  21. * @param mixed $value from JSON's attribute
  22. * @param mixed $container A {Type}
  23. * @return bool
  24. * @throws Exception
  25. */
  26. public function validate($value, $container): bool
  27. {
  28. // Validate that container is a {Type}
  29. \ActivityPhp\Type\Util::subclassOf($container, \ActivityPhp\Type\Extended\Object\{Type}::class, true);
  30. return {Validation Result};
  31. ```
  32. **ActivityPubAddActivityStreamsTwoData**: To add attributes to an entity that we are managing to JSON (commonly federating out via ActivityPub)
  33. * `@param string $type_name` When we handle a Type, we will send you the type identifier of the one being handled
  34. * `@param \ActivityPhp\Type\AbstractObject &$type_activity` The Activity in the intermediate format between Model and JSON
  35. * `@return` Returns `Event::next`
  36. **ActivityStreamsTwoContext**: To expand our ActivityStreams 2 Context
  37. * `@param array &$activity_streams_two_context` Append to the array your additional context
  38. * `@return` Returns `Event::next`
  39. **ActivityPubActivityStreamsTwoResponse**: To add a route to ActivityPub (the route must already exist in your plugin) (commonly being requested to ActivityPub)
  40. * `@param string $route` Route identifier
  41. * `@param array $vars` From your controller
  42. * `@param \Plugin\ActivityPub\Util\TypeResponse &$response` The JSON (protip: ModelResponse's handler will convert entities into TypeResponse)
  43. * `@return` Returns `Event::stop` if handled, `Event::next` otherwise
  44. Example:
  45. ```php
  46. public function onActivityPubActivityStreamsTwoResponse(string $route, arrray $vars, ?TypeResponse &$response = null): bool {
  47. if ($route === '{Object route}') {
  48. $response = \Plugin\ActivityPub\Util\ModelResponse::handle($vars[{Object}]);
  49. return Event::stop;
  50. }
  51. return Event::next;
  52. }
  53. ```
  54. **NewActivityPubActivity**: To convert an Activity Streams 2.0 formatted activity into Entities (commonly when we receive a JSON in our inbox)
  55. * `@param Actor $actor` Actor who authored the activity
  56. * `@param \ActivityPhp\Type\AbstractObject $type_activity` Activity
  57. * `@param \ActivityPhp\Type\AbstractObject $type_object` Object
  58. * `@param ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act` ActivitypubActivity
  59. * `@return` Returns `Event::stop` if handled, `Event::next` otherwise
  60. **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)
  61. * `@param Actor $actor` Actor who authored the activity
  62. * `@param \ActivityPhp\Type\AbstractObject $type_activity` Activity
  63. * `@param Entity $type_object` Object
  64. * `@param ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act` ActivitypubActivity
  65. * `@return` Returns `Event::stop` if handled, `Event::next` otherwise
  66. **GSVerbToActivityStreamsTwoActivityType**: Translate a GNU social internal verb to an Activity Streams 2.0 one
  67. * `@param string $verb` GNU social's internal verb
  68. * `@param \ActivityPhp\Type\AbstractObject &$gs_verb_to_activity_stream_two_verb` Activity Streams 2.0 verb
  69. * `@return` Returns `Event::stop` if handled, `Event::next` otherwise
  70. Example:
  71. ```php
  72. public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
  73. {
  74. if ($verb === '{GS verb}') {
  75. $gs_verb_to_activity_stream_two_verb = '{AS2 verb}';
  76. return Event::stop;
  77. }
  78. return Event::next;
  79. }
  80. ```