From: Michael Date: Sun, 29 May 2022 09:20:06 +0000 (+0000) Subject: Issue 11469: Repect desktop notification settings X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1dccc3150816c603b112130d2bdd43b41b22d8ed;p=friendica.git Issue 11469: Repect desktop notification settings --- diff --git a/mod/settings.php b/mod/settings.php index 04a9e3fd3b..612907ac2e 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -23,25 +23,16 @@ use Friendica\App; use Friendica\BaseModule; use Friendica\Content\Feature; use Friendica\Content\Nav; -use Friendica\Core\ACL; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Renderer; -use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Model\Group; use Friendica\Model\Item; -use Friendica\Model\Notification; -use Friendica\Model\Profile; use Friendica\Model\User; -use Friendica\Model\Verb; use Friendica\Module\BaseSettings; use Friendica\Module\Security\Login; -use Friendica\Protocol\Activity; use Friendica\Protocol\Email; -use Friendica\Util\Temporal; -use Friendica\Worker\Delivery; function settings_init(App $a) { diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php index f49fab51cc..79067d3f32 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -37,7 +37,6 @@ use Friendica\Core\Theme; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Item as ItemModel; -use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Model\User; @@ -48,7 +47,6 @@ use Friendica\Protocol\Activity; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Profiler; -use Friendica\Util\Proxy; use Friendica\Util\Strings; use Friendica\Util\Temporal; use Psr\Log\LoggerInterface; diff --git a/src/Model/Subscription.php b/src/Model/Subscription.php index 0d8f346d18..cb14ae2b5f 100644 --- a/src/Model/Subscription.php +++ b/src/Model/Subscription.php @@ -143,17 +143,7 @@ class Subscription { $type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification); - $desktop_notification = !in_array($type, [Notification::TYPE_RESHARE, Notification::TYPE_LIKE]); - - if (DI::pConfig()->get($Notification->uid, 'system', 'notify_like') && ($type == Notification::TYPE_LIKE)) { - $desktop_notification = true; - } - - if (DI::pConfig()->get($Notification->uid, 'system', 'notify_announce') && ($type == Notification::TYPE_RESHARE)) { - $desktop_notification = true; - } - - if ($desktop_notification) { + if (DI::notify()->NotifyOnDesktop($Notification, $type)) { DI::notify()->createFromNotification($Notification); } diff --git a/src/Module/Notifications/Ping.php b/src/Module/Notifications/Ping.php index b0412b5dcb..7dc2158260 100644 --- a/src/Module/Notifications/Ping.php +++ b/src/Module/Notifications/Ping.php @@ -187,6 +187,9 @@ class Ping extends BaseModule $owner = User::getOwnerDataById(local_user()); $navNotifications = array_map(function (Entity\Notification $notification) use ($owner) { + if (!DI::notify()->NotifyOnDesktop($notification)) { + return null; + } if (($notification->type == Post\UserNotification::TYPE_NONE) && in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])) { return null; } diff --git a/src/Navigation/Notifications/Repository/Notify.php b/src/Navigation/Notifications/Repository/Notify.php index c114375be7..3392228002 100644 --- a/src/Navigation/Notifications/Repository/Notify.php +++ b/src/Navigation/Notifications/Repository/Notify.php @@ -26,6 +26,7 @@ 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; @@ -37,6 +38,7 @@ 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; @@ -59,6 +61,9 @@ class Notify extends BaseRepository /** @var IManageConfigValues */ protected $config; + /** @var IManagePersonalConfigValues */ + private $pConfig; + /** @var Emailer */ protected $emailer; @@ -67,11 +72,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; @@ -651,6 +657,27 @@ class Notify extends BaseRepository return false; } + public function NotifyOnDesktop(Entity\Notification $Notification, string $type = null): bool + { + if (is_null($type)) { + $type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification); + } + + if (!in_array($type, [Notification::TYPE_RESHARE, Notification::TYPE_LIKE])) { + 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; + } + + return false; + } + public function createFromNotification(Entity\Notification $Notification) { $this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]);