Added a hook to check if the hook needs to be forked at all

This commit is contained in:
Michael 2018-11-10 16:20:19 +00:00
parent d2460a43e5
commit d1919f0497
9 changed files with 271 additions and 41 deletions

View file

@ -21,6 +21,7 @@ use Friendica\Model\Queue;
function diaspora_install()
{
Addon::registerHook('hook_fork', 'addon/diaspora/diaspora.php', 'diaspora_hook_fork');
Addon::registerHook('post_local', 'addon/diaspora/diaspora.php', 'diaspora_post_local');
Addon::registerHook('notifier_normal', 'addon/diaspora/diaspora.php', 'diaspora_send');
Addon::registerHook('jot_networks', 'addon/diaspora/diaspora.php', 'diaspora_jot_nets');
@ -31,6 +32,7 @@ function diaspora_install()
function diaspora_uninstall()
{
Addon::unregisterHook('hook_fork', 'addon/diaspora/diaspora.php', 'diaspora_hook_fork');
Addon::unregisterHook('post_local', 'addon/diaspora/diaspora.php', 'diaspora_post_local');
Addon::unregisterHook('notifier_normal', 'addon/diaspora/diaspora.php', 'diaspora_send');
Addon::unregisterHook('jot_networks', 'addon/diaspora/diaspora.php', 'diaspora_jot_nets');
@ -253,6 +255,21 @@ function diaspora_settings_post(App $a, &$b)
}
}
function diaspora_hook_fork(&$a, &$b)
{
if ($b['name'] != 'notifier_normal') {
return;
}
$post = $b['data'];
if ($post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
!strstr($post['postopts'], 'diaspora') || ($post['parent'] != $post['id'])) {
$b['execute'] = false;
return;
}
}
function diaspora_post_local(App $a, array &$b)
{
if ($b['edit']) {