mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-07 15:54:26 +02:00
Add events for follow, revoke_follow, block and unblock hooks
This commit is contained in:
parent
4d96875656
commit
10e4f4bf36
6 changed files with 59 additions and 10 deletions
|
@ -62,7 +62,11 @@ final class HookEventBridge
|
||||||
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'support_follow',
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'support_follow',
|
||||||
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'support_revoke_follow',
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'support_revoke_follow',
|
||||||
ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => 'support_probe',
|
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::HEAD => 'head',
|
||||||
HtmlFilterEvent::FOOTER => 'footer',
|
HtmlFilterEvent::FOOTER => 'footer',
|
||||||
HtmlFilterEvent::PAGE_HEADER => 'page_header',
|
HtmlFilterEvent::PAGE_HEADER => 'page_header',
|
||||||
|
@ -105,7 +109,11 @@ final class HookEventBridge
|
||||||
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'onArrayFilterEvent',
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'onArrayFilterEvent',
|
||||||
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
|
||||||
ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => '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::HEAD => 'onHtmlFilterEvent',
|
||||||
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
||||||
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
||||||
|
|
|
@ -187,7 +187,7 @@ class Protocol
|
||||||
$eventDispatcher = DI::eventDispatcher();
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
$hook_data = $eventDispatcher->dispatch(
|
$hook_data = $eventDispatcher->dispatch(
|
||||||
new ArrayFilterEvent(ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, $hook_data),
|
new ArrayFilterEvent(ArrayFilterEvent::UNFOLLOW_CONTACT, $hook_data),
|
||||||
)->getArray();
|
)->getArray();
|
||||||
|
|
||||||
return $hook_data['result'];
|
return $hook_data['result'];
|
||||||
|
@ -223,7 +223,12 @@ class Protocol
|
||||||
'uid' => $owner['uid'],
|
'uid' => $owner['uid'],
|
||||||
'result' => null,
|
'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'];
|
return $hook_data['result'];
|
||||||
}
|
}
|
||||||
|
@ -261,7 +266,12 @@ class Protocol
|
||||||
'uid' => $uid,
|
'uid' => $uid,
|
||||||
'result' => null,
|
'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'];
|
return $hook_data['result'];
|
||||||
}
|
}
|
||||||
|
@ -300,7 +310,12 @@ class Protocol
|
||||||
'uid' => $uid,
|
'uid' => $uid,
|
||||||
'result' => null,
|
'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'];
|
return $hook_data['result'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,15 @@ final class ArrayFilterEvent extends Event
|
||||||
|
|
||||||
public const PROTOCOL_SUPPORTS_PROBE = 'friendica.data.protocol_supports_probe';
|
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;
|
private array $array;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ use Friendica\Core\Worker;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Network\HTTPException\NotFoundException;
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
|
@ -3144,7 +3145,11 @@ class Contact
|
||||||
|
|
||||||
$arr = ['url' => $url, 'uid' => $uid, '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)) {
|
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.');
|
$result['message'] = DI::l10n()->t('The contact could not be added. Please check the relevant network credentials in your Settings -> Social Networks page.');
|
||||||
|
|
|
@ -51,7 +51,11 @@ class HookEventBridgeTest extends TestCase
|
||||||
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'onArrayFilterEvent',
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'onArrayFilterEvent',
|
||||||
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
|
||||||
ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => '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::HEAD => 'onHtmlFilterEvent',
|
||||||
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
||||||
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
||||||
|
@ -279,7 +283,11 @@ class HookEventBridgeTest extends TestCase
|
||||||
[ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'support_follow'],
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'support_follow'],
|
||||||
[ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'support_revoke_follow'],
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'support_revoke_follow'],
|
||||||
[ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'support_probe'],
|
[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'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,11 @@ class ArrayFilterEventTest extends TestCase
|
||||||
[ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'friendica.data.protocol_supports_follow'],
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'friendica.data.protocol_supports_follow'],
|
||||||
[ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'friendica.data.protocol_supports_revoke_follow'],
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'friendica.data.protocol_supports_revoke_follow'],
|
||||||
[ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'friendica.data.protocol_supports_probe'],
|
[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'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue