]> git.mxchange.org Git - friendica.git/commitdiff
API: Set "dismissed" instead of "seen"
authorMichael <heluecht@pirati.ca>
Tue, 28 Dec 2021 20:38:18 +0000 (20:38 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 28 Dec 2021 20:38:18 +0000 (20:38 +0000)
database.sql
doc/database/db_notification.md
include/api.php
src/Module/Api/Mastodon/Notifications.php
src/Module/Api/Mastodon/Notifications/Clear.php
src/Module/Api/Mastodon/Notifications/Dismiss.php
src/Navigation/Notifications/Collection/Notifications.php
src/Navigation/Notifications/Entity/Notification.php
src/Navigation/Notifications/Repository/Notification.php
static/dbstructure.config.php

index d1c73cc048f3f606932d629760f3f8145188cd47..175c48b8c3f88e4c069e3627703c44dedd2cac93 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2021.12-rc (Siberian Iris)
--- DB_UPDATE_VERSION 1446
+-- DB_UPDATE_VERSION 1447
 -- ------------------------------------------
 
 
@@ -824,7 +824,8 @@ CREATE TABLE IF NOT EXISTS `notification` (
        `target-uri-id` int unsigned COMMENT 'Item-uri id of the related post',
        `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
        `created` datetime COMMENT '',
-       `seen` boolean DEFAULT '0' COMMENT '',
+       `seen` boolean DEFAULT '0' COMMENT 'Seen on the desktop',
+       `dismissed` boolean DEFAULT '0' COMMENT 'Dismissed via the API',
         PRIMARY KEY(`id`),
         UNIQUE INDEX `uid_vid_type_actor-id_target-uri-id` (`uid`,`vid`,`type`,`actor-id`,`target-uri-id`),
         INDEX `vid` (`vid`),
index ff059c344fe720cb75e1357bb79df6c7dbbba465..7c7dc3a543d9dc78a8f61f2c69672341fc4aef7c 100644 (file)
@@ -16,7 +16,8 @@ Fields
 | target-uri-id | Item-uri id of the related post                                                | int unsigned       | YES  |     | NULL    |                |
 | parent-uri-id | Item-uri id of the parent of the related post                                  | int unsigned       | YES  |     | NULL    |                |
 | created       |                                                                                | datetime           | YES  |     | NULL    |                |
-| seen          |                                                                                | boolean            | YES  |     | 0       |                |
+| seen          | Seen on the desktop                                                            | boolean            | YES  |     | 0       |                |
+| dismissed     | Dismissed via the API                                                          | boolean            | YES  |     | 0       |                |
 
 Indexes
 ------------
index 4df1b7abae517137b0ce04172e472b5115f1628d..21d95e1c199deb1da81004d364589e649e34605c 100644 (file)
@@ -24,8 +24,6 @@
  */
 
 use Friendica\App;
-use Friendica\Content\Text\BBCode;
-use Friendica\Content\Text\HTML;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
@@ -33,7 +31,6 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
-use Friendica\Model\Mail;
 use Friendica\Model\Photo;
 use Friendica\Model\Post;
 use Friendica\Model\Profile;
@@ -45,7 +42,6 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Network\HTTPException\NotFoundException;
 use Friendica\Network\HTTPException\UnauthorizedException;
 use Friendica\Object\Image;
-use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Images;
 use Friendica\Util\Strings;
 
index 7527286e09eb2c093c529fe8655a88aea85d381d..786afec5b71a0b4e9d413ef2a5573958963b19aa 100644 (file)
@@ -68,7 +68,7 @@ class Notifications extends BaseApi
 
                $params = ['order' => ['id' => true]];
 
-               $condition = ['uid' => $uid, 'seen' => false];
+               $condition = ['uid' => $uid, 'dismissed' => false];
 
                if (!empty($request['account_id'])) {
                        $contact = Contact::getById($request['account_id'], ['url']);
index d997a7fd445636a5482e747f9db7bd8fdf8a7e11..ca2d43272d06ef29a205f2d192ba79562a5095f2 100644 (file)
@@ -35,7 +35,7 @@ class Clear extends BaseApi
                self::checkAllowedScope(self::SCOPE_WRITE);
                $uid = self::getCurrentUserID();
 
-               DI::notification()->setAllSeenForUser($uid);
+               DI::notification()->setAllDismissedForUser($uid);
 
                System::jsonExit([]);
        }
index 277a34d5cb931d5e68bbf60b769b5ee2a83cb89d..a56aa710dd8888e815a27f7fb6fa774a9f6f4013 100644 (file)
@@ -42,7 +42,7 @@ class Dismiss extends BaseApi
                }
 
                $Notification = DI::notification()->selectOneForUser($uid, $this->parameters['id']);
-               $Notification->setSeen();
+               $Notification->setDismissed();
                DI::notification()->save($Notification);
 
                System::jsonExit([]);
index f383b4ccb0321ba4824869930668aa6f00f067a3..40d4a03bb7fb1330f620f4dbda8d024418bc4f08 100644 (file)
@@ -40,4 +40,11 @@ class Notifications extends BaseCollection
                        $Notification->setSeen();
                });
        }
+
+       public function setDismissed(): Notifications
+       {
+               return $this->map(function (Entity\Notification $Notification) {
+                       $Notification->setDismissed();
+               });
+       }
 }
index 3f491f98c05d030678b2240060b919065d6d0fc8..e24db4e64b27a6aca2b9ad926a74da6208b0bce6 100644 (file)
@@ -39,6 +39,8 @@ class Notification extends BaseEntity
        protected $created;
        /** @var bool */
        protected $seen;
+       /** @var bool */
+       protected $dismissed;
 
        /**
         * Please do not use this constructor directly, instead use one of the method of the Notification factory.
@@ -52,9 +54,10 @@ class Notification extends BaseEntity
         * @param DateTime|null $created
         * @param bool          $seen
         * @param int|null      $id
+        * @param bool          $dismissed
         * @see \Friendica\Navigation\Notifications\Factory\Notification
         */
-       public function __construct(int $uid, string $verb, int $type, int $actorId, int $targetUriId = null, int $parentUriId = null, DateTime $created = null, bool $seen = false, int $id = null)
+       public function __construct(int $uid, string $verb, int $type, int $actorId, int $targetUriId = null, int $parentUriId = null, DateTime $created = null, bool $seen = false, int $id = null, bool $dismissed = false)
        {
                $this->uid         = $uid;
                $this->verb        = $verb;
@@ -65,10 +68,16 @@ class Notification extends BaseEntity
                $this->created     = $created;
                $this->seen        = $seen;
                $this->id          = $id;
+               $this->dismissed   = $dismissed;
        }
 
        public function setSeen()
        {
                $this->seen = true;
        }
+
+       public function setDismissed()
+       {
+               $this->dismissed = true;
+       }
 }
index 154461e2362041c0e933689f174209270af4fbec..8dac7935433ea2b790fc2ab0b1b30c5168c6b8c2 100644 (file)
@@ -110,6 +110,13 @@ class Notification extends BaseRepository
                return $this->db->update(self::$table_name, ['seen' => true], $condition);
        }
 
+       public function setAllDismissedForUser(int $uid, array $condition = []): bool
+       {
+               $condition = DBA::mergeConditions($condition, ['uid' => $uid]);
+
+               return $this->db->update(self::$table_name, ['dismissed' => true], $condition);
+       }
+
        /**
         * @param Entity\Notification $Notification
         * @return Entity\Notification
@@ -125,6 +132,7 @@ class Notification extends BaseRepository
                        'target-uri-id' => $Notification->targetUriId,
                        'parent-uri-id' => $Notification->parentUriId,
                        'seen'          => $Notification->seen,
+                       'dismissed'     => $Notification->dismissed,
                ];
 
                if ($Notification->id) {
index 1c3b296ca3fed1363570bb4d3b2615b113666049..3fbce08d40cf2e9a3c2a7f9ae414002ccef0d351 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1446);
+       define('DB_UPDATE_VERSION', 1447);
 }
 
 return [
@@ -880,7 +880,8 @@ return [
                        "target-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Item-uri id of the related post"],
                        "parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Item-uri id of the parent of the related post"],
                        "created" => ["type" => "datetime", "comment" => ""],
-                       "seen" => ["type" => "boolean", "default" => "0", "comment" => ""],
+                       "seen" => ["type" => "boolean", "default" => "0", "comment" => "Seen on the desktop"],
+                       "dismissed" => ["type" => "boolean", "default" => "0", "comment" => "Dismissed via the API"],
                ],
                "indexes" => [
                        "PRIMARY" => ["id"],