use Friendica\App\BaseURL;
use Friendica\BaseRepository;
+use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Plaintext;
use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\Database;
use Friendica\Database\DBA;
+use Friendica\Factory\Api\Mastodon\Notification as NotificationFactory;
use Friendica\Model;
use Friendica\Navigation\Notifications\Collection;
use Friendica\Navigation\Notifications\Entity;
use Friendica\Navigation\Notifications\Exception;
use Friendica\Navigation\Notifications\Factory;
use Friendica\Network\HTTPException;
+use Friendica\Object\Api\Mastodon\Notification;
use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Emailer;
/** @var IManageConfigValues */
protected $config;
+ /** @var IManagePersonalConfigValues */
+ private $pConfig;
+
/** @var Emailer */
protected $emailer;
protected static $table_name = 'notify';
- public function __construct(Database $database, LoggerInterface $logger, L10n $l10n, BaseURL $baseUrl, IManageConfigValues $config, 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, Factory\Notify $factory = null)
{
$this->l10n = $l10n;
$this->baseUrl = $baseUrl;
$this->config = $config;
+ $this->pConfig = $pConfig;
$this->emailer = $emailer;
$this->notification = $notification;
/**
* @param array $condition
* @param array $params
+ *
* @return Entity\Notify
* @throws HTTPException\NotFoundException
*/
/**
* @param int $id
+ *
* @return Entity\Notify
* @throws HTTPException\NotFoundException
*/
/**
* @param Entity\Notify $Notify
+ *
* @return Entity\Notify
* @throws HTTPException\NotFoundException
* @throws HTTPException\InternalServerErrorException
$item_post_type = Model\Item::postType($item, $l10n);
- $content = Plaintext::getPost($item, 70);
- if (!empty($content['text'])) {
- $title = '"' . trim(str_replace("\n", " ", $content['text'])) . '"';
- } else {
- $title = '';
+ $body = BBCode::toPlaintext($item['body'], false);
+ $title = Plaintext::shorten($body, 70);
+ if (!empty($title)) {
+ $title = '"' . trim(str_replace("\n", " ", $title)) . '"';
}
// First go for the general message
$itemlink = $params['link'];
break;
- case Model\Notification\Type::POKE:
- $subject = $l10n->t('%1$s %2$s poked you', $subjectPrefix, $params['source_name']);
-
- $preamble = $l10n->t('%1$s poked you at %2$s', $params['source_name'], $sitename);
- $epreamble = $l10n->t('%1$s [url=%2$s]poked you[/url].',
- '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
- $params['link']
- );
-
- $subject = str_replace('poked', $l10n->t($params['activity']), $subject);
- $preamble = str_replace('poked', $l10n->t($params['activity']), $preamble);
- $epreamble = str_replace('poked', $l10n->t($params['activity']), $epreamble);
-
- $sitelink = $l10n->t('Please visit %s to view and/or reply to the conversation.');
- $tsitelink = sprintf($sitelink, $siteurl);
- $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
- $itemlink = $params['link'];
- break;
-
case Model\Notification\Type::INTRO:
$itemlink = $params['link'];
$subject = $l10n->t('%s Introduction received', $subjectPrefix);
case Model\Notification\Type::SYSTEM:
switch($params['event']) {
- case "SYSTEM_REGISTER_REQUEST":
+ case 'SYSTEM_REGISTER_REQUEST':
$itemlink = $params['link'];
$subject = $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('registration request');
$sitelink = $l10n->t('Please visit %s to approve or reject the request.');
$tsitelink = sprintf($sitelink, $params['link']);
- $hsitelink = sprintf($sitelink, '<a href="'.$params['link'].'">'.$sitename.'</a><br><br>');
+ $hsitelink = sprintf($sitelink, '<a href="' . $params['link'] . '">' . $sitename . '</a><br><br>');
break;
- case "SYSTEM_DB_UPDATE_FAIL":
+
+ case 'SYSTEM_DB_UPDATE_FAIL': // @TODO Unused (only here)
break;
}
break;
return $this->storeAndSend($params, $sitelink, $tsitelink, $hsitelink, $title, $subject, $preamble, $epreamble, $body, $itemlink, $show_in_notification_page);
}
- private function storeAndSend($params, $sitelink, $tsitelink, $hsitelink, $title, $subject, $preamble, $epreamble, $body, $itemlink, $show_in_notification_page)
+ private function storeAndSend(array $params, string $sitelink, string $tsitelink, string $hsitelink, string $title, string $subject, string $preamble, string $epreamble, string $body, string $itemlink, bool $show_in_notification_page): bool
{
$item_id = $params['item']['id'] ?? 0;
$uri_id = $params['item']['uri-id'] ?? null;
DBA::insert('notify-threads', $fields);
$emailBuilder->setHeader('Message-ID', $message_id);
- $log_msg = "include/enotify: No previous notification found for this parent:\n" .
+ $log_msg = "No previous notification found for this parent:\n" .
" parent: ${params['parent']}\n" . " uid : ${params['uid']}\n";
$this->logger->info($log_msg);
} else {
return false;
}
- public function createFromNotification(Entity\Notification $Notification)
+ public function NotifyOnDesktop(Entity\Notification $Notification, string $type = null): bool
+ {
+ if (is_null($type)) {
+ $type = NotificationFactory::getType($Notification);
+ }
+
+ if (in_array($Notification->type, [Model\Post\UserNotification::TYPE_FOLLOW, Model\Post\UserNotification::TYPE_SHARED])) {
+ return true;
+ }
+
+ if ($this->pConfig->get($Notification->uid, 'system', 'notify_like') && ($type == Notification::TYPE_LIKE)) {
+ return true;
+ }
+
+ if ($this->pConfig->get($Notification->uid, 'system', 'notify_announce') && ($type == Notification::TYPE_RESHARE)) {
+ return true;
+ }
+
+ $notify_type = $this->pConfig->get($Notification->uid, 'system', 'notify_type');
+
+ // Fallback for the case when the notify type isn't set at all
+ if (is_null($notify_type) && !in_array($type, [Notification::TYPE_RESHARE, Notification::TYPE_LIKE])) {
+ return true;
+ }
+
+ if (!is_null($notify_type) && ($notify_type & $Notification->type)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public function createFromNotification(Entity\Notification $Notification): bool
{
$this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]);
return false;
}
- $content = Plaintext::getPost($item, 70);
- if (!empty($content['text'])) {
- $title = '"' . trim(str_replace("\n", " ", $content['text'])) . '"';
- } else {
- $title = $item['title'];
+ $body = BBCode::toPlaintext($item['body'], false);
+ $title = Plaintext::shorten($body, 70);
+ if (!empty($title)) {
+ $title = '"' . trim(str_replace("\n", " ", $title)) . '"';
}
// Some mail software relies on subject field for threading.