create event for avatar_lookup hook

This commit is contained in:
Art4 2025-03-14 13:31:11 +00:00
parent d34861ee96
commit 68b604812c
6 changed files with 18 additions and 4 deletions

View file

@ -68,6 +68,7 @@ final class HookEventBridge
ArrayFilterEvent::REVOKE_FOLLOW_CONTACT => 'revoke_follow', ArrayFilterEvent::REVOKE_FOLLOW_CONTACT => 'revoke_follow',
ArrayFilterEvent::BLOCK_CONTACT => 'block', ArrayFilterEvent::BLOCK_CONTACT => 'block',
ArrayFilterEvent::UNBLOCK_CONTACT => 'unblock', ArrayFilterEvent::UNBLOCK_CONTACT => 'unblock',
ArrayFilterEvent::AVATAR_LOOKUP => 'avatar_lookup',
ArrayFilterEvent::ADD_WORKER_TASK => 'proc_run', ArrayFilterEvent::ADD_WORKER_TASK => 'proc_run',
ArrayFilterEvent::STORAGE_CONFIG => 'storage_config', ArrayFilterEvent::STORAGE_CONFIG => 'storage_config',
ArrayFilterEvent::STORAGE_INSTANCE => 'storage_instance', ArrayFilterEvent::STORAGE_INSTANCE => 'storage_instance',
@ -121,6 +122,7 @@ final class HookEventBridge
ArrayFilterEvent::REVOKE_FOLLOW_CONTACT => 'onArrayFilterEvent', ArrayFilterEvent::REVOKE_FOLLOW_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::BLOCK_CONTACT => 'onArrayFilterEvent', ArrayFilterEvent::BLOCK_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::UNBLOCK_CONTACT => 'onArrayFilterEvent', ArrayFilterEvent::UNBLOCK_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::AVATAR_LOOKUP => 'onArrayFilterEvent',
ArrayFilterEvent::ADD_WORKER_TASK => 'onArrayFilterEvent', ArrayFilterEvent::ADD_WORKER_TASK => 'onArrayFilterEvent',
ArrayFilterEvent::STORAGE_CONFIG => 'onArrayFilterEvent', ArrayFilterEvent::STORAGE_CONFIG => 'onArrayFilterEvent',
ArrayFilterEvent::STORAGE_INSTANCE => 'onArrayFilterEvent', ArrayFilterEvent::STORAGE_INSTANCE => 'onArrayFilterEvent',

View file

@ -74,6 +74,8 @@ final class ArrayFilterEvent extends Event
public const UNBLOCK_CONTACT = 'friendica.data.unblock_contact'; public const UNBLOCK_CONTACT = 'friendica.data.unblock_contact';
public const AVATAR_LOOKUP = 'friendica.data.avatar_lookup';
public const ADD_WORKER_TASK = 'friendica.data.add_worker_task'; public const ADD_WORKER_TASK = 'friendica.data.add_worker_task';
public const STORAGE_CONFIG = 'friendica.data.storage_config'; public const STORAGE_CONFIG = 'friendica.data.storage_config';

View file

@ -14,7 +14,6 @@ use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
use Friendica\Content\Conversation as ConversationContent; use Friendica\Content\Conversation as ConversationContent;
use Friendica\Content\Pager; use Friendica\Content\Pager;
use Friendica\Content\Text\HTML; use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\System; use Friendica\Core\System;
@ -2205,7 +2204,11 @@ class Contact
$avatar['url'] = ''; $avatar['url'] = '';
$avatar['success'] = false; $avatar['success'] = false;
Hook::callAll('avatar_lookup', $avatar); $eventDispatcher = DI::eventDispatcher();
$avatar = $eventDispatcher->dispatch(
new ArrayFilterEvent(ArrayFilterEvent::AVATAR_LOOKUP, $avatar),
)->getArray();
if ($avatar['success'] && !empty($avatar['url'])) { if ($avatar['success'] && !empty($avatar['url'])) {
return $avatar['url']; return $avatar['url'];

View file

@ -7,8 +7,8 @@
namespace Friendica\Util; namespace Friendica\Util;
use Friendica\Core\Hook;
use Friendica\DI; use Friendica\DI;
use Friendica\Event\ArrayFilterEvent;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
@ -302,7 +302,11 @@ class Network
$avatar['url'] = ''; $avatar['url'] = '';
$avatar['success'] = false; $avatar['success'] = false;
Hook::callAll('avatar_lookup', $avatar); $eventDispatcher = DI::eventDispatcher();
$avatar = $eventDispatcher->dispatch(
new ArrayFilterEvent(ArrayFilterEvent::AVATAR_LOOKUP, $avatar),
)->getArray();
if (! $avatar['success']) { if (! $avatar['success']) {
$avatar['url'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO; $avatar['url'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;

View file

@ -57,6 +57,7 @@ class HookEventBridgeTest extends TestCase
ArrayFilterEvent::REVOKE_FOLLOW_CONTACT => 'onArrayFilterEvent', ArrayFilterEvent::REVOKE_FOLLOW_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::BLOCK_CONTACT => 'onArrayFilterEvent', ArrayFilterEvent::BLOCK_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::UNBLOCK_CONTACT => 'onArrayFilterEvent', ArrayFilterEvent::UNBLOCK_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::AVATAR_LOOKUP => 'onArrayFilterEvent',
ArrayFilterEvent::ADD_WORKER_TASK => 'onArrayFilterEvent', ArrayFilterEvent::ADD_WORKER_TASK => 'onArrayFilterEvent',
ArrayFilterEvent::STORAGE_CONFIG => 'onArrayFilterEvent', ArrayFilterEvent::STORAGE_CONFIG => 'onArrayFilterEvent',
ArrayFilterEvent::STORAGE_INSTANCE => 'onArrayFilterEvent', ArrayFilterEvent::STORAGE_INSTANCE => 'onArrayFilterEvent',
@ -295,6 +296,7 @@ class HookEventBridgeTest extends TestCase
[ArrayFilterEvent::REVOKE_FOLLOW_CONTACT, 'revoke_follow'], [ArrayFilterEvent::REVOKE_FOLLOW_CONTACT, 'revoke_follow'],
[ArrayFilterEvent::BLOCK_CONTACT, 'block'], [ArrayFilterEvent::BLOCK_CONTACT, 'block'],
[ArrayFilterEvent::UNBLOCK_CONTACT, 'unblock'], [ArrayFilterEvent::UNBLOCK_CONTACT, 'unblock'],
[ArrayFilterEvent::AVATAR_LOOKUP, 'avatar_lookup'],
[ArrayFilterEvent::ADD_WORKER_TASK, 'proc_run'], [ArrayFilterEvent::ADD_WORKER_TASK, 'proc_run'],
[ArrayFilterEvent::STORAGE_CONFIG, 'storage_config'], [ArrayFilterEvent::STORAGE_CONFIG, 'storage_config'],
[ArrayFilterEvent::STORAGE_INSTANCE, 'storage_instance'], [ArrayFilterEvent::STORAGE_INSTANCE, 'storage_instance'],

View file

@ -54,6 +54,7 @@ class ArrayFilterEventTest extends TestCase
[ArrayFilterEvent::REVOKE_FOLLOW_CONTACT, 'friendica.data.revoke_follow_contact'], [ArrayFilterEvent::REVOKE_FOLLOW_CONTACT, 'friendica.data.revoke_follow_contact'],
[ArrayFilterEvent::BLOCK_CONTACT, 'friendica.data.block_contact'], [ArrayFilterEvent::BLOCK_CONTACT, 'friendica.data.block_contact'],
[ArrayFilterEvent::UNBLOCK_CONTACT, 'friendica.data.unblock_contact'], [ArrayFilterEvent::UNBLOCK_CONTACT, 'friendica.data.unblock_contact'],
[ArrayFilterEvent::AVATAR_LOOKUP, 'friendica.data.avatar_lookup'],
[ArrayFilterEvent::ADD_WORKER_TASK, 'friendica.data.add_worker_task'], [ArrayFilterEvent::ADD_WORKER_TASK, 'friendica.data.add_worker_task'],
[ArrayFilterEvent::STORAGE_CONFIG, 'friendica.data.storage_config'], [ArrayFilterEvent::STORAGE_CONFIG, 'friendica.data.storage_config'],
[ArrayFilterEvent::STORAGE_INSTANCE, 'friendica.data.storage_instance'], [ArrayFilterEvent::STORAGE_INSTANCE, 'friendica.data.storage_instance'],