mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-07 13:16:32 +02:00
Wrap item in INSERT_POST_LOCAL_END into separate array
This commit is contained in:
parent
1ddd5674e1
commit
9822dd25d8
4 changed files with 53 additions and 8 deletions
|
@ -1011,10 +1011,16 @@ class Item
|
|||
Tag::createImplicitMentions($post['uri-id'], $post['thr-parent-id']);
|
||||
}
|
||||
|
||||
$post = $this->eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL_END, $post)
|
||||
$hook_data = [
|
||||
'item' => $post,
|
||||
];
|
||||
|
||||
$hook_data = $this->eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL_END, $hook_data)
|
||||
)->getArray();
|
||||
|
||||
$post = $hook_data['item'] ?? $post;
|
||||
|
||||
$author = DBA::selectFirst('contact', ['thumb'], ['uid' => $post['uid'], 'self' => true]);
|
||||
|
||||
foreach ($recipients as $recipient) {
|
||||
|
|
|
@ -113,7 +113,7 @@ final class HookEventBridge
|
|||
ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_START => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL => 'onInsertPostLocalEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_END => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_END => 'onInsertPostLocalEndEvent',
|
||||
ArrayFilterEvent::INSERT_POST_REMOTE => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_REMOTE_END => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PREPARE_POST_START => 'onPreparePostStartEvent',
|
||||
|
@ -197,6 +197,20 @@ final class HookEventBridge
|
|||
$event->setArray($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the INSERT_POST_LOCAL_END event to `post_local_end` hook
|
||||
*/
|
||||
public static function onInsertPostLocalEndEvent(ArrayFilterEvent $event): void
|
||||
{
|
||||
$data = $event->getArray();
|
||||
|
||||
$item = (array) $data['item'] ?? [];
|
||||
|
||||
$data['item'] = static::callHook($event->getName(), $item);
|
||||
|
||||
$event->setArray($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the PREPARE_POST_START event to `prepare_body_init` hook
|
||||
*/
|
||||
|
|
|
@ -153,10 +153,16 @@ EOT;
|
|||
|
||||
$post['id'] = $post_id;
|
||||
|
||||
$post = $this->eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL_END, $post)
|
||||
$hook_data = [
|
||||
'item' => $post,
|
||||
];
|
||||
|
||||
$hook_data = $this->eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL_END, $hook_data)
|
||||
)->getArray();
|
||||
|
||||
$post = $hook_data['item'] ?? $post;
|
||||
|
||||
$post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]);
|
||||
|
||||
Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::POST, $post['uri-id'], $post['uid']);
|
||||
|
|
|
@ -34,7 +34,7 @@ class HookEventBridgeTest extends TestCase
|
|||
ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_START => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL => 'onInsertPostLocalEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_END => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_END => 'onInsertPostLocalEndEvent',
|
||||
ArrayFilterEvent::INSERT_POST_REMOTE => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_REMOTE_END => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PREPARE_POST_START => 'onPreparePostStartEvent',
|
||||
|
@ -214,6 +214,27 @@ class HookEventBridgeTest extends TestCase
|
|||
$event->getArray(),
|
||||
);
|
||||
}
|
||||
public function testOnInsertPostLocalEndEventCallsHookWithCorrectValue(): void
|
||||
{
|
||||
$event = new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL_END, ['item' => ['id' => -1]]);
|
||||
|
||||
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
|
||||
$reflectionProperty->setValue(null, function (string $name, array $data): array {
|
||||
$this->assertSame('post_local_end', $name);
|
||||
$this->assertSame(['id' => -1], $data);
|
||||
|
||||
return ['id' => 123];
|
||||
});
|
||||
|
||||
HookEventBridge::onInsertPostLocalEndEvent($event);
|
||||
|
||||
$this->assertSame(
|
||||
['item' => ['id' => 123]],
|
||||
$event->getArray(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testOnPreparePostStartEventCallsHookWithCorrectValue(): void
|
||||
{
|
||||
|
@ -390,8 +411,6 @@ class HookEventBridgeTest extends TestCase
|
|||
[ArrayFilterEvent::FEATURE_ENABLED, 'isEnabled'],
|
||||
[ArrayFilterEvent::FEATURE_GET, 'get'],
|
||||
[ArrayFilterEvent::INSERT_POST_LOCAL_START, 'post_local_start'],
|
||||
[ArrayFilterEvent::INSERT_POST_LOCAL, 'post_local'],
|
||||
[ArrayFilterEvent::INSERT_POST_LOCAL_END, 'post_local_end'],
|
||||
[ArrayFilterEvent::INSERT_POST_REMOTE, 'post_remote'],
|
||||
[ArrayFilterEvent::INSERT_POST_REMOTE_END, 'post_remote_end'],
|
||||
[ArrayFilterEvent::PREPARE_POST_FILTER_CONTENT, 'prepare_body_content_filter'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue