]> git.mxchange.org Git - friendica.git/commitdiff
Issue 11469: Repect desktop notification settings
authorMichael <heluecht@pirati.ca>
Sun, 29 May 2022 09:20:06 +0000 (09:20 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 29 May 2022 09:20:06 +0000 (09:20 +0000)
mod/settings.php
src/Content/Conversation.php
src/Model/Subscription.php
src/Module/Notifications/Ping.php
src/Navigation/Notifications/Repository/Notify.php

index 04a9e3fd3b40fbc30703e6cd8079e3fb7a4f1772..612907ac2eaa92d19accf4086832a6b93b079fcb 100644 (file)
@@ -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)
 {
index f49fab51ccda86b08ceaf44548c9822bed47d308..79067d3f32ad35fd0eaf1c8c38f005dfffb5787a 100644 (file)
@@ -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;
index 0d8f346d18281dfd80035b4b1c0c14c2f7fe2768..cb14ae2b5f8939779e1059b23abf6783b4a6ef0a 100644 (file)
@@ -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);
                }
 
index b0412b5dcb7598a66050faea92c25b80f7c5d44d..7dc215826024dd0ccfa6a5b17c631542fec5c9db 100644 (file)
@@ -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;
                                }
index c114375be7775331687318c9106dafa4ac8682cd..33922280028900029ae82099ecfef6ea1d048c57 100644 (file)
@@ -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]);