Create events for post_remote and post_remote_end hook

This commit is contained in:
Art4 2025-03-14 15:35:53 +00:00
parent abe35732d8
commit 9aeb68231d
6 changed files with 22 additions and 3 deletions

View 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',

View 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';

View 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;

View 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) {

View 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'],

View 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'],