]> git.mxchange.org Git - friendica.git/blobdiff - src/Navigation/Notifications/Repository/Notification.php
Rename Repository\Notify->NotifyOnDesktop to shouldShowOnDesktop
[friendica.git] / src / Navigation / Notifications / Repository / Notification.php
index e7ef0621145822214b94962a310cd5005bfc4be5..a9630464aa576113a64d987a749f4386baf417e2 100644 (file)
@@ -112,12 +112,19 @@ class Notification extends BaseRepository
         * 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 = ["`type` & ? != 0", $this->pconfig->get($uid, 'system', 'notify_type', 3 | 72 | 4 | 16 | 32) | 128 | 256];
+               $notify_type = $this->pconfig->get($uid, 'system', 'notify_type');
+               if (!is_null($notify_type)) {
+                       $condition = ["`type` & ? != 0", $notify_type | UserNotification::TYPE_SHARED | UserNotification::TYPE_FOLLOW];
+               } else {
+                       $condition = [];
+               }
+
                if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
                        $condition = DBA::mergeConditions($condition, ['NOT `vid` IN (?, ?)', Verb::getID(\Friendica\Protocol\Activity::LIKE), Verb::getID(\Friendica\Protocol\Activity::DISLIKE)]);
                }
@@ -133,12 +140,20 @@ class Notification extends BaseRepository
         * Returns only the most recent notifications for the same conversation or contact
         *
         * @param int $uid
+        *
         * @return Collection\Notifications
         * @throws Exception
         */
        public function selectDigestForUser(int $uid): Collection\Notifications
        {
-               $values = [$uid, $this->pconfig->get($uid, 'system', 'notify_type', 3 | 72 | 4 | 16 | 32) | 128 | 256];
+               $values = [$uid];
+
+               $type_condition = '';
+               $notify_type = $this->pconfig->get($uid, 'system', 'notify_type');
+               if (!is_null($notify_type)) {
+                       $type_condition = 'AND `type` & ? != 0';
+                       $values[] = $notify_type | UserNotification::TYPE_SHARED | UserNotification::TYPE_FOLLOW;
+               }
 
                $like_condition = '';
                if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
@@ -159,7 +174,8 @@ class Notification extends BaseRepository
                WHERE `id` IN (
                    SELECT MAX(`id`)
                    FROM `notification`
-                   WHERE `uid` = ? AND `type` & ? != 0
+                   WHERE `uid` = ?
+                       $type_condition
                    $like_condition
                    $announce_condition
                    GROUP BY IFNULL(`parent-uri-id`, `actor-id`)
@@ -187,6 +203,7 @@ class Notification extends BaseRepository
         * @param int|null $min_id Retrieve models with an id no fewer than this, as close to it as possible
         * @param int|null $max_id Retrieve models with an id no greater than this, as close to it as possible
         * @param int      $limit
+        *
         * @return BaseCollection
         * @throws Exception
         * @see _selectByBoundaries
@@ -234,7 +251,7 @@ class Notification extends BaseRepository
                        $this->db->update(self::$table_name, $fields, ['id' => $Notification->id]);
                } else {
                        $fields['created'] = DateTimeFormat::utcNow();
-                       $this->db->insert(self::$table_name, $fields);
+                       $this->db->insert(self::$table_name, $fields, Database::INSERT_IGNORE);
 
                        $Notification = $this->selectOneById($this->db->lastInsertId());
                }