]> git.mxchange.org Git - friendica.git/commitdiff
Add support for notification visibility settings
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 17 Mar 2022 01:56:22 +0000 (21:56 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 17 Mar 2022 02:03:26 +0000 (22:03 -0400)
mod/settings.php
src/Module/Notifications/Ping.php
src/Navigation/Notifications/Repository/Notification.php

index 41a1436e69afe94e8c1d1cd87c241a1c49d6f587..642229de0b578428bbb9c58c2cf86b5d63519be9 100644 (file)
@@ -35,8 +35,10 @@ 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;
@@ -352,7 +354,18 @@ function settings_post(App $a)
        DI::pConfig()->set(local_user(), 'expire', 'photos', $expire_photos);
        DI::pConfig()->set(local_user(), 'expire', 'network_only', $expire_network_only);
 
+       // Reset like notifications when they are going to be shown again
+       if (!DI::pConfig()->get(local_user(), 'system', 'notify_like') && $notify_like) {
+               DI::notification()->setAllSeenForUser(local_user(), ['vid' => Verb::getID(Activity::LIKE)]);
+       }
+
        DI::pConfig()->set(local_user(), 'system', 'notify_like', $notify_like);
+
+       // Reset share notifications when they are going to be shown again
+       if (!DI::pConfig()->get(local_user(), 'system', 'notify_announce') && $notify_announce) {
+               DI::notification()->setAllSeenForUser(local_user(), ['vid' => Verb::getID(Activity::ANNOUNCE)]);
+       }
+
        DI::pConfig()->set(local_user(), 'system', 'notify_announce', $notify_announce);
 
        DI::pConfig()->set(local_user(), 'system', 'email_textonly', $email_textonly);
index 03d3ae5f77ebe7e0327edf25118e188bffab92db..7deb42fcaa75931030f73d975a2a911167582b4a 100644 (file)
@@ -87,7 +87,7 @@ class Ping extends BaseModule
 
                if (local_user()) {
                        if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) {
-                               $notifications = $this->notificationRepo->selectForUser(local_user(), ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::LIKE)], ['limit' => 50, 'order' => ['id' => true]]);
+                               $notifications = $this->notificationRepo->selectDetailedForUser(local_user());
                        } else {
                                $notifications = $this->notificationRepo->selectDigestForUser(local_user());
                        }
index 60ac82ae31817c1faa5fc050ceace9b750134b04..b9ac9e4dd41f3413babaedfe7481fd2c02a29a35 100644 (file)
@@ -24,6 +24,7 @@ namespace Friendica\Navigation\Notifications\Repository;
 use Exception;
 use Friendica\BaseCollection;
 use Friendica\BaseRepository;
+use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\Model\Verb;
@@ -41,9 +42,14 @@ class Notification extends BaseRepository
 
        protected static $table_name = 'notification';
 
-       public function __construct(Database $database, LoggerInterface $logger, Factory\Notification $factory)
+       /** @var IManagePersonalConfigValues */
+       private $pconfig;
+
+       public function __construct(IManagePersonalConfigValues $pconfig, Database $database, LoggerInterface $logger, Factory\Notification $factory)
        {
                parent::__construct($database, $logger, $factory);
+
+               $this->pconfig = $pconfig;
        }
 
        /**
@@ -100,6 +106,28 @@ class Notification extends BaseRepository
                return $this->select($condition, $params);
        }
 
+
+       /**
+        * Returns only the most recent notifications for the same conversation or contact
+        *
+        * @param int $uid
+        * @return Collection\Notifications
+        * @throws Exception
+        */
+       public function selectDetailedForUser(int $uid): Collection\Notifications
+       {
+               $condition = [];
+               if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
+                       $condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::LIKE)]);
+               }
+
+               if (!$this->pconfig->get($uid, 'system', 'notify_announce')) {
+                       $condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE)]);
+               }
+
+               return $this->selectForUser(local_user(), $condition, ['limit' => 50, 'order' => ['id' => true]]);
+       }
+
        /**
         * Returns only the most recent notifications for the same conversation or contact
         *
@@ -109,6 +137,20 @@ class Notification extends BaseRepository
         */
        public function selectDigestForUser(int $uid): Collection\Notifications
        {
+               $values = [$uid];
+
+               $like_condition = '';
+               if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
+                       $like_condition = 'AND vid != ?';
+                       $values[] = Verb::getID(\Friendica\Protocol\Activity::LIKE);
+               }
+
+               $announce_condition = '';
+               if (!$this->pconfig->get($uid, 'system', 'notify_announce')) {
+                       $announce_condition = 'AND vid != ?';
+                       $values[] = Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE);
+               }
+
                $rows = $this->db->p("
                SELECT notification.*
                FROM notification
@@ -116,12 +158,13 @@ class Notification extends BaseRepository
                    SELECT MAX(`id`)
                    FROM notification
                    WHERE uid = ?
-                   AND vid != ?
+                   $like_condition
+                   $announce_condition
                    GROUP BY IFNULL(`parent-uri-id`, `actor-id`)
                )
                ORDER BY `seen`, `id` DESC
                LIMIT 50
-               ", $uid, Verb::getID(\Friendica\Protocol\Activity::LIKE));
+               ", ...$values);
 
                $Entities = new Collection\Notifications();
                foreach ($rows as $fields) {