]> git.mxchange.org Git - friendica.git/commitdiff
Add events for follow, revoke_follow, block and unblock hooks
authorArt4 <art4@wlabs.de>
Thu, 13 Mar 2025 14:02:35 +0000 (14:02 +0000)
committerArt4 <art4@wlabs.de>
Thu, 13 Mar 2025 14:02:35 +0000 (14:02 +0000)
src/Core/Hooks/HookEventBridge.php
src/Core/Protocol.php
src/Event/ArrayFilterEvent.php
src/Model/Contact.php
tests/Unit/Core/Hooks/HookEventBridgeTest.php
tests/Unit/Event/ArrayFilterEventTest.php

index 6b652cf4f08d6e7a4af31fe944d6c6a6b0f6a124..39da9a13d08247b92915249afcf05fe509555c46 100644 (file)
@@ -62,7 +62,11 @@ final class HookEventBridge
                ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW        => 'support_follow',
                ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'support_revoke_follow',
                ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE         => 'support_probe',
-               ArrayFilterEvent::UNFOLLOW                        => 'unfollow',
+               ArrayFilterEvent::FOLLOW_CONTACT                  => 'follow',
+               ArrayFilterEvent::UNFOLLOW_CONTACT                => 'unfollow',
+               ArrayFilterEvent::REVOKE_FOLLOW_CONTACT           => 'revoke_follow',
+               ArrayFilterEvent::BLOCK_CONTACT                   => 'block',
+               ArrayFilterEvent::UNBLOCK_CONTACT                 => 'unblock',
                HtmlFilterEvent::HEAD                             => 'head',
                HtmlFilterEvent::FOOTER                           => 'footer',
                HtmlFilterEvent::PAGE_HEADER                      => 'page_header',
@@ -105,7 +109,11 @@ final class HookEventBridge
                        ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW        => 'onArrayFilterEvent',
                        ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
                        ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE         => 'onArrayFilterEvent',
-                       ArrayFilterEvent::UNFOLLOW                        => 'onArrayFilterEvent',
+                       ArrayFilterEvent::FOLLOW_CONTACT                  => 'onArrayFilterEvent',
+                       ArrayFilterEvent::UNFOLLOW_CONTACT                => 'onArrayFilterEvent',
+                       ArrayFilterEvent::REVOKE_FOLLOW_CONTACT           => 'onArrayFilterEvent',
+                       ArrayFilterEvent::BLOCK_CONTACT                   => 'onArrayFilterEvent',
+                       ArrayFilterEvent::UNBLOCK_CONTACT                 => 'onArrayFilterEvent',
                        HtmlFilterEvent::HEAD                             => 'onHtmlFilterEvent',
                        HtmlFilterEvent::FOOTER                           => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_HEADER                      => 'onHtmlFilterEvent',
index 61427d10173a8cf7cb3c2d52ce082beb0a936edb..ef57c22f1897138c9fe034464d22c1970158fde1 100644 (file)
@@ -187,7 +187,7 @@ class Protocol
                $eventDispatcher = DI::eventDispatcher();
 
                $hook_data = $eventDispatcher->dispatch(
-                       new ArrayFilterEvent(ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, $hook_data),
+                       new ArrayFilterEvent(ArrayFilterEvent::UNFOLLOW_CONTACT, $hook_data),
                )->getArray();
 
                return $hook_data['result'];
@@ -223,7 +223,12 @@ class Protocol
                        'uid'     => $owner['uid'],
                        'result'  => null,
                ];
-               Hook::callAll('revoke_follow', $hook_data);
+
+               $eventDispatcher = DI::eventDispatcher();
+
+               $hook_data = $eventDispatcher->dispatch(
+                       new ArrayFilterEvent(ArrayFilterEvent::REVOKE_FOLLOW_CONTACT, $hook_data),
+               )->getArray();
 
                return $hook_data['result'];
        }
@@ -261,7 +266,12 @@ class Protocol
                        'uid'     => $uid,
                        'result'  => null,
                ];
-               Hook::callAll('block', $hook_data);
+
+               $eventDispatcher = DI::eventDispatcher();
+
+               $hook_data = $eventDispatcher->dispatch(
+                       new ArrayFilterEvent(ArrayFilterEvent::BLOCK_CONTACT, $hook_data),
+               )->getArray();
 
                return $hook_data['result'];
        }
@@ -300,7 +310,12 @@ class Protocol
                        'uid'     => $uid,
                        'result'  => null,
                ];
-               Hook::callAll('unblock', $hook_data);
+
+               $eventDispatcher = DI::eventDispatcher();
+
+               $hook_data = $eventDispatcher->dispatch(
+                       new ArrayFilterEvent(ArrayFilterEvent::UNBLOCK_CONTACT, $hook_data),
+               )->getArray();
 
                return $hook_data['result'];
        }
index 9664071714411faed301d0e5d260eb0090af25d1..b4ec1122720cfb93503b6653b2dda2a1171315ac 100644 (file)
@@ -62,7 +62,15 @@ final class ArrayFilterEvent extends Event
 
        public const PROTOCOL_SUPPORTS_PROBE = 'friendica.data.protocol_supports_probe';
 
-       public const UNFOLLOW = 'friendica.data.unfollow';
+       public const FOLLOW_CONTACT = 'friendica.data.follow_contact';
+
+       public const UNFOLLOW_CONTACT = 'friendica.data.unfollow_contact';
+
+       public const REVOKE_FOLLOW_CONTACT = 'friendica.data.revoke_follow_contact';
+
+       public const BLOCK_CONTACT = 'friendica.data.block_contact';
+
+       public const UNBLOCK_CONTACT = 'friendica.data.unblock_contact';
 
        private array $array;
 
index cced0ed6263f303b063447b046e0e94bc67024c5..e94ef46964b37a5ffc7930d00152e3d4e4fecf25 100644 (file)
@@ -22,6 +22,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 use Friendica\Network\HTTPClient\Client\HttpClientOptions;
 use Friendica\Network\HTTPException\NotFoundException;
@@ -3144,7 +3145,11 @@ class Contact
 
                $arr = ['url' => $url, 'uid' => $uid, 'contact' => []];
 
-               Hook::callAll('follow', $arr);
+               $eventDispatcher = DI::eventDispatcher();
+
+               $arr = $eventDispatcher->dispatch(
+                       new ArrayFilterEvent(ArrayFilterEvent::FOLLOW_CONTACT, $arr),
+               )->getArray();
 
                if (empty($arr)) {
                        $result['message'] = DI::l10n()->t('The contact could not be added. Please check the relevant network credentials in your Settings -> Social Networks page.');
index 93d62965c3c77c1a58dfb4b8dea31e0e4aadf48e..f1b10ed3c778a3c034d8f8be0d16757d6447a107 100644 (file)
@@ -51,7 +51,11 @@ class HookEventBridgeTest extends TestCase
                        ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW        => 'onArrayFilterEvent',
                        ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
                        ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE         => 'onArrayFilterEvent',
-                       ArrayFilterEvent::UNFOLLOW                        => 'onArrayFilterEvent',
+                       ArrayFilterEvent::FOLLOW_CONTACT                  => 'onArrayFilterEvent',
+                       ArrayFilterEvent::UNFOLLOW_CONTACT                => 'onArrayFilterEvent',
+                       ArrayFilterEvent::REVOKE_FOLLOW_CONTACT           => 'onArrayFilterEvent',
+                       ArrayFilterEvent::BLOCK_CONTACT                   => 'onArrayFilterEvent',
+                       ArrayFilterEvent::UNBLOCK_CONTACT                 => 'onArrayFilterEvent',
                        HtmlFilterEvent::HEAD                             => 'onHtmlFilterEvent',
                        HtmlFilterEvent::FOOTER                           => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_HEADER                      => 'onHtmlFilterEvent',
@@ -279,7 +283,11 @@ class HookEventBridgeTest extends TestCase
                        [ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'support_follow'],
                        [ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'support_revoke_follow'],
                        [ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'support_probe'],
-                       [ArrayFilterEvent::UNFOLLOW, 'unfollow'],
+                       [ArrayFilterEvent::FOLLOW_CONTACT, 'follow'],
+                       [ArrayFilterEvent::UNFOLLOW_CONTACT, 'unfollow'],
+                       [ArrayFilterEvent::REVOKE_FOLLOW_CONTACT, 'revoke_follow'],
+                       [ArrayFilterEvent::BLOCK_CONTACT, 'block'],
+                       [ArrayFilterEvent::UNBLOCK_CONTACT, 'unblock'],
                ];
        }
 
index 2d396e67609c7a0ce13fb115024c36f446ceba57..be576995c774202ae004fbac42b0ce0676d8363f 100644 (file)
@@ -47,6 +47,11 @@ class ArrayFilterEventTest extends TestCase
                        [ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'friendica.data.protocol_supports_follow'],
                        [ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'friendica.data.protocol_supports_revoke_follow'],
                        [ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'friendica.data.protocol_supports_probe'],
+                       [ArrayFilterEvent::FOLLOW_CONTACT, 'friendica.data.follow_contact'],
+                       [ArrayFilterEvent::UNFOLLOW_CONTACT, 'friendica.data.unfollow_contact'],
+                       [ArrayFilterEvent::REVOKE_FOLLOW_CONTACT, 'friendica.data.revoke_follow_contact'],
+                       [ArrayFilterEvent::BLOCK_CONTACT, 'friendica.data.block_contact'],
+                       [ArrayFilterEvent::UNBLOCK_CONTACT, 'friendica.data.unblock_contact'],
                ];
        }