]> git.mxchange.org Git - friendica.git/commitdiff
Create events for post_remote and post_remote_end hook
authorArt4 <art4@wlabs.de>
Fri, 14 Mar 2025 15:35:53 +0000 (15:35 +0000)
committerArt4 <art4@wlabs.de>
Fri, 14 Mar 2025 15:35:53 +0000 (15:35 +0000)
src/Core/Hooks/HookEventBridge.php
src/Event/ArrayFilterEvent.php
src/Model/Event.php
src/Model/Item.php
tests/Unit/Core/Hooks/HookEventBridgeTest.php
tests/Unit/Event/ArrayFilterEventTest.php

index 1567b3e20ab6f46e4b092c4f4c07e8e3c1a7b705..18a2754e33acc77728d70e8d2a41b35eca217e59 100644 (file)
@@ -46,6 +46,8 @@ final class HookEventBridge
                ArrayFilterEvent::POST_LOCAL_START                => 'post_local_start',
                ArrayFilterEvent::POST_LOCAL                      => 'post_local',
                ArrayFilterEvent::POST_LOCAL_END                  => 'post_local_end',
+               ArrayFilterEvent::INSERT_POST_REMOTE              => 'post_remote',
+               ArrayFilterEvent::INSERT_POST_REMOTE_END          => 'post_remote_end',
                ArrayFilterEvent::PHOTO_UPLOAD_FORM               => 'photo_upload_form',
                ArrayFilterEvent::NETWORK_TO_NAME                 => 'network_to_name',
                ArrayFilterEvent::CONVERSATION_START              => 'conversation_start',
@@ -102,6 +104,8 @@ final class HookEventBridge
                        ArrayFilterEvent::POST_LOCAL_START                => 'onArrayFilterEvent',
                        ArrayFilterEvent::POST_LOCAL                      => 'onArrayFilterEvent',
                        ArrayFilterEvent::POST_LOCAL_END                  => 'onArrayFilterEvent',
+                       ArrayFilterEvent::INSERT_POST_REMOTE              => 'onArrayFilterEvent',
+                       ArrayFilterEvent::INSERT_POST_REMOTE_END          => 'onArrayFilterEvent',
                        ArrayFilterEvent::PHOTO_UPLOAD_FORM               => 'onArrayFilterEvent',
                        ArrayFilterEvent::NETWORK_TO_NAME                 => 'onArrayFilterEvent',
                        ArrayFilterEvent::CONVERSATION_START              => 'onArrayFilterEvent',
index b3be9f70fadf28d188266ad0455ececfae09bd4f..0ab06525bd31bbfed7ddd5438f47e8cfdf5e8235 100644 (file)
@@ -30,6 +30,10 @@ final class ArrayFilterEvent extends Event
 
        public const POST_LOCAL_END = 'friendica.data.post_local_end';
 
+       public const INSERT_POST_REMOTE = 'friendica.data.insert_post_remote';
+
+       public const INSERT_POST_REMOTE_END = 'friendica.data.insert_post_remote_end';
+
        public const PHOTO_UPLOAD_FORM = 'friendica.data.photo_upload_form';
 
        public const NETWORK_TO_NAME = 'friendica.data.network_to_name';
index debeb74d454534804d922ff48a4f59a1f0e429f6..125692dfe1abea810b2ff91192fa679a9611517f 100644 (file)
@@ -9,7 +9,6 @@ namespace Friendica\Model;
 
 use Friendica\Content\Feature;
 use Friendica\Content\Text\BBCode;
-use Friendica\Core\Hook;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
index 31f8a8e22eeb337298ead37dee6820ed830378df..99ebba8cae319d3b3674ae880d918f6ca95cadc1 100644 (file)
@@ -855,7 +855,9 @@ class Item
                                unset($_SESSION['uid']);
                        }
                } elseif (!$notify) {
-                       Hook::callAll('post_remote', $item);
+                       $item = $eventDispatcher->dispatch(
+                               new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_REMOTE, $item)
+                       )->getArray();
                }
 
                if (!empty($item['cancel'])) {
@@ -1112,7 +1114,11 @@ class Item
                                DI::contentItem()->copyPermissions($posted_item['thr-parent-id'], $posted_item['uri-id'], $posted_item['parent-uri-id']);
                        }
                } else {
-                       Hook::callAll('post_remote_end', $posted_item);
+                       $eventDispatcher = DI::eventDispatcher();
+
+                       $posted_item = $eventDispatcher->dispatch(
+                               new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_REMOTE_END, $posted_item)
+                       )->getArray();
                }
 
                if ($posted_item['gravity'] === self::GRAVITY_PARENT) {
index 1852248ebbd3b0e5c759ffdac59f796ca246d7bb..69c49f35137bb7a7ba8a4b42d62f97bbdbd70867 100644 (file)
@@ -35,6 +35,8 @@ class HookEventBridgeTest extends TestCase
                        ArrayFilterEvent::POST_LOCAL_START                => 'onArrayFilterEvent',
                        ArrayFilterEvent::POST_LOCAL                      => 'onArrayFilterEvent',
                        ArrayFilterEvent::POST_LOCAL_END                  => 'onArrayFilterEvent',
+                       ArrayFilterEvent::INSERT_POST_REMOTE              => 'onArrayFilterEvent',
+                       ArrayFilterEvent::INSERT_POST_REMOTE_END          => 'onArrayFilterEvent',
                        ArrayFilterEvent::PHOTO_UPLOAD_FORM               => 'onArrayFilterEvent',
                        ArrayFilterEvent::NETWORK_TO_NAME                 => 'onArrayFilterEvent',
                        ArrayFilterEvent::CONVERSATION_START              => 'onArrayFilterEvent',
@@ -314,6 +316,8 @@ class HookEventBridgeTest extends TestCase
                        [ArrayFilterEvent::POST_LOCAL_START, 'post_local_start'],
                        [ArrayFilterEvent::POST_LOCAL, 'post_local'],
                        [ArrayFilterEvent::POST_LOCAL_END, 'post_local_end'],
+                       [ArrayFilterEvent::INSERT_POST_REMOTE, 'post_remote'],
+                       [ArrayFilterEvent::INSERT_POST_REMOTE_END, 'post_remote_end'],
                        [ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'photo_upload_form'],
                        [ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'],
                        [ArrayFilterEvent::CONVERSATION_START, 'conversation_start'],
index 0e4467c1ed086df700bb4334d94a52762f7b97d5..193ccc77d8ac32b5da6b43c91ac7a7c7b1330171 100644 (file)
@@ -32,6 +32,8 @@ class ArrayFilterEventTest extends TestCase
                        [ArrayFilterEvent::POST_LOCAL_START, 'friendica.data.post_local_start'],
                        [ArrayFilterEvent::POST_LOCAL, 'friendica.data.post_local'],
                        [ArrayFilterEvent::POST_LOCAL_END, 'friendica.data.post_local_end'],
+                       [ArrayFilterEvent::INSERT_POST_REMOTE, 'friendica.data.insert_post_remote'],
+                       [ArrayFilterEvent::INSERT_POST_REMOTE_END, 'friendica.data.insert_post_remote_end'],
                        [ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'friendica.data.photo_upload_form'],
                        [ArrayFilterEvent::NETWORK_TO_NAME, 'friendica.data.network_to_name'],
                        [ArrayFilterEvent::CONVERSATION_START, 'friendica.data.conversation_start'],