X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavigation%2FNotifications%2FRepository%2FNotify.php;h=5a6bf668967fcc8d10a81824e8e1d0bb9202d80f;hb=4930737cc448bcff196a2e06065249c0ffc363d0;hp=9773b6446aed29d2275e9e2f78ed10cc481f8685;hpb=1138abe9237b9db1cf8a0ac7925de9bb55923cdb;p=friendica.git
diff --git a/src/Navigation/Notifications/Repository/Notify.php b/src/Navigation/Notifications/Repository/Notify.php
index 9773b6446a..5a6bf66896 100644
--- a/src/Navigation/Notifications/Repository/Notify.php
+++ b/src/Navigation/Notifications/Repository/Notify.php
@@ -23,19 +23,23 @@ namespace Friendica\Navigation\Notifications\Repository;
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;
@@ -58,6 +62,9 @@ class Notify extends BaseRepository
/** @var IManageConfigValues */
protected $config;
+ /** @var IManagePersonalConfigValues */
+ private $pConfig;
+
/** @var Emailer */
protected $emailer;
@@ -66,11 +73,12 @@ class Notify extends BaseRepository
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;
@@ -80,6 +88,7 @@ class Notify extends BaseRepository
/**
* @param array $condition
* @param array $params
+ *
* @return Entity\Notify
* @throws HTTPException\NotFoundException
*/
@@ -109,6 +118,7 @@ class Notify extends BaseRepository
/**
* @param int $id
+ *
* @return Entity\Notify
* @throws HTTPException\NotFoundException
*/
@@ -145,6 +155,7 @@ class Notify extends BaseRepository
/**
* @param Entity\Notify $Notify
+ *
* @return Entity\Notify
* @throws HTTPException\NotFoundException
* @throws HTTPException\InternalServerErrorException
@@ -301,11 +312,10 @@ class Notify extends BaseRepository
$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
@@ -351,25 +361,6 @@ class Notify extends BaseRepository
$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, ''.$sitename.'');
- $itemlink = $params['link'];
- break;
-
case Model\Notification\Type::INTRO:
$itemlink = $params['link'];
$subject = $l10n->t('%s Introduction received', $subjectPrefix);
@@ -471,7 +462,7 @@ class Notify extends BaseRepository
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');
@@ -489,9 +480,10 @@ class Notify extends BaseRepository
$sitelink = $l10n->t('Please visit %s to approve or reject the request.');
$tsitelink = sprintf($sitelink, $params['link']);
- $hsitelink = sprintf($sitelink, ''.$sitename.'
');
+ $hsitelink = sprintf($sitelink, '' . $sitename . '
');
break;
- case "SYSTEM_DB_UPDATE_FAIL":
+
+ case 'SYSTEM_DB_UPDATE_FAIL': // @TODO Unused (only here)
break;
}
break;
@@ -504,7 +496,7 @@ class Notify extends BaseRepository
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;
@@ -593,7 +585,7 @@ class Notify extends BaseRepository
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 {
@@ -651,7 +643,39 @@ class Notify extends BaseRepository
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]);
@@ -710,11 +734,10 @@ class Notify extends BaseRepository
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.