ArrayFilterEvent::DISPLAY_ITEM => 'display_item',
ArrayFilterEvent::CACHE_ITEM => 'put_item_in_cache',
ArrayFilterEvent::CHECK_ITEM_NOTIFICATION => 'check_item_notification',
+ ArrayFilterEvent::ENOTIFY => 'enotify',
+ ArrayFilterEvent::ENOTIFY_STORE => 'enotify_store',
+ ArrayFilterEvent::ENOTIFY_MAIL => 'enotify_mail',
ArrayFilterEvent::DETECT_LANGUAGES => 'detect_languages',
ArrayFilterEvent::RENDER_LOCATION => 'render_location',
ArrayFilterEvent::ITEM_PHOTO_MENU => 'item_photo_menu',
ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent',
ArrayFilterEvent::CACHE_ITEM => 'onArrayFilterEvent',
ArrayFilterEvent::CHECK_ITEM_NOTIFICATION => 'onArrayFilterEvent',
+ ArrayFilterEvent::ENOTIFY => 'onArrayFilterEvent',
+ ArrayFilterEvent::ENOTIFY_STORE => 'onArrayFilterEvent',
+ ArrayFilterEvent::ENOTIFY_MAIL => 'onArrayFilterEvent',
ArrayFilterEvent::DETECT_LANGUAGES => 'onArrayFilterEvent',
ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
ArrayFilterEvent::ITEM_PHOTO_MENU => 'onArrayFilterEvent',
use Friendica\Core\L10n;
use Friendica\Database\Database;
use Friendica\Database\DBA;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Factory\Api\Mastodon\Notification as NotificationFactory;
use Friendica\Model;
use Friendica\Navigation\Notifications\Collection;
use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Emailer;
+use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
/** @var Factory\Notification */
protected $notification;
+ private EventDispatcherInterface $eventDispatcher;
+
protected static $table_name = 'notify';
- public function __construct(Database $database, LoggerInterface $logger, L10n $l10n, BaseURL $baseUrl, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Emailer $emailer, Factory\Notification $notification, Factory\Notify $factory = null)
- {
+ public function __construct(
+ Database $database,
+ LoggerInterface $logger,
+ L10n $l10n,
+ BaseURL $baseUrl,
+ IManageConfigValues $config,
+ IManagePersonalConfigValues $pConfig,
+ Emailer $emailer,
+ Factory\Notification $notification,
+ EventDispatcherInterface $eventDispatcher,
+ Factory\Notify $factory = null,
+ ) {
$this->l10n = $l10n;
$this->baseUrl = $baseUrl;
$this->config = $config;
$this->pConfig = $pConfig;
$this->emailer = $emailer;
$this->notification = $notification;
+ $this->eventDispatcher = $eventDispatcher;
parent::__construct($database, $logger, $factory ?? new Factory\Notify($logger));
}
$this->db->update(self::$table_name, $fields, ['id' => $Notify->id]);
} else {
$fields['date'] = DateTimeFormat::utcNow();
- Hook::callAll('enotify_store', $fields);
+
+ $fields = $this->eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::ENOTIFY_STORE, $fields),
+ )->getArray();
$this->db->insert(self::$table_name, $fields);
$subject .= " (".$nickname."@".$hostname.")";
- $h = [
+ $hook_data = [
'params' => $params,
'subject' => $subject,
'preamble' => $preamble,
'itemlink' => $itemlink
];
- Hook::callAll('enotify', $h);
+ $hook_data = $this->eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::ENOTIFY, $hook_data),
+ )->getArray();
- $subject = $h['subject'];
+ $subject = $hook_data['subject'];
- $preamble = $h['preamble'];
- $epreamble = $h['epreamble'];
+ $preamble = $hook_data['preamble'];
+ $epreamble = $hook_data['epreamble'];
- $body = $h['body'];
+ $body = $hook_data['body'];
- $tsitelink = $h['tsitelink'];
- $hsitelink = $h['hsitelink'];
- $itemlink = $h['itemlink'];
+ $tsitelink = $hook_data['tsitelink'];
+ $hsitelink = $hook_data['hsitelink'];
+ $itemlink = $hook_data['itemlink'];
$notify_id = 0;
}
}
- $datarray = [
+ $hook_data = [
'preamble' => $preamble,
'type' => $params['type'],
'parent' => $parent_id,
'headers' => $emailBuilder->getHeaders(),
];
- Hook::callAll('enotify_mail', $datarray);
+ $hook_data = $this->eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::ENOTIFY_MAIL, $hook_data),
+ )->getArray();
$emailBuilder
- ->withHeaders($datarray['headers'])
+ ->withHeaders($hook_data['headers'])
->withRecipient($params['to_email'])
->forUser([
- 'uid' => $datarray['uid'],
+ 'uid' => $hook_data['uid'],
'language' => $params['language'],
])
- ->withNotification($datarray['subject'], $datarray['preamble'], $datarray['title'], $datarray['body'])
- ->withSiteLink($datarray['tsitelink'], $datarray['hsitelink'])
- ->withItemLink($datarray['itemlink']);
+ ->withNotification($hook_data['subject'], $hook_data['preamble'], $hook_data['title'], $hook_data['body'])
+ ->withSiteLink($hook_data['tsitelink'], $hook_data['hsitelink'])
+ ->withItemLink($hook_data['itemlink']);
// If a photo is present, add it to the email
- if (!empty($datarray['source_photo'])) {
+ if (!empty($hook_data['source_photo'])) {
$emailBuilder->withPhoto(
- $datarray['source_photo'],
- $datarray['source_link'] ?? $sitelink,
- $datarray['source_name'] ?? $sitename
+ $hook_data['source_photo'],
+ $hook_data['source_link'] ?? $sitelink,
+ $hook_data['source_name'] ?? $sitename
);
}
$email = $emailBuilder->build();
- $this->logger->debug('Send mail', $datarray);
+ $this->logger->debug('Send mail', $hook_data);
// use the Emailer class to send the message
return $this->emailer->send($email);
ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent',
ArrayFilterEvent::CACHE_ITEM => 'onArrayFilterEvent',
ArrayFilterEvent::CHECK_ITEM_NOTIFICATION => 'onArrayFilterEvent',
+ ArrayFilterEvent::ENOTIFY => 'onArrayFilterEvent',
+ ArrayFilterEvent::ENOTIFY_STORE => 'onArrayFilterEvent',
+ ArrayFilterEvent::ENOTIFY_MAIL => 'onArrayFilterEvent',
ArrayFilterEvent::DETECT_LANGUAGES => 'onArrayFilterEvent',
ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
ArrayFilterEvent::ITEM_PHOTO_MENU => 'onArrayFilterEvent',
[ArrayFilterEvent::DISPLAY_ITEM, 'display_item'],
[ArrayFilterEvent::CACHE_ITEM, 'put_item_in_cache'],
[ArrayFilterEvent::CHECK_ITEM_NOTIFICATION, 'check_item_notification'],
+ [ArrayFilterEvent::ENOTIFY, 'enotify'],
+ [ArrayFilterEvent::ENOTIFY_STORE, 'enotify_store'],
+ [ArrayFilterEvent::ENOTIFY_MAIL, 'enotify_mail'],
[ArrayFilterEvent::DETECT_LANGUAGES, 'detect_languages'],
[ArrayFilterEvent::RENDER_LOCATION, 'render_location'],
[ArrayFilterEvent::ITEM_PHOTO_MENU, 'item_photo_menu'],