Merge pull request #11123 from annando/notification-dismissed

API: Set "dismissed" instead of "seen"
This commit is contained in:
Hypolite Petovan 2021-12-28 22:29:34 +01:00 committed by GitHub
commit 5a07068049
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 13 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2021.12-rc (Siberian Iris) -- 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', `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', `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
`created` datetime COMMENT '', `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`), PRIMARY KEY(`id`),
UNIQUE INDEX `uid_vid_type_actor-id_target-uri-id` (`uid`,`vid`,`type`,`actor-id`,`target-uri-id`), UNIQUE INDEX `uid_vid_type_actor-id_target-uri-id` (`uid`,`vid`,`type`,`actor-id`,`target-uri-id`),
INDEX `vid` (`vid`), INDEX `vid` (`vid`),

View file

@ -16,7 +16,8 @@ Fields
| target-uri-id | Item-uri id of the related post | int unsigned | YES | | NULL | | | 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 | | | parent-uri-id | Item-uri id of the parent of the related post | int unsigned | YES | | NULL | |
| created | | datetime | 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 Indexes
------------ ------------

View file

@ -24,8 +24,6 @@
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
@ -33,7 +31,6 @@ use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Mail;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Profile; use Friendica\Model\Profile;
@ -45,7 +42,6 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\NotFoundException; use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Network\HTTPException\UnauthorizedException; use Friendica\Network\HTTPException\UnauthorizedException;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Util\Strings; use Friendica\Util\Strings;

View file

@ -68,7 +68,7 @@ class Notifications extends BaseApi
$params = ['order' => ['id' => true]]; $params = ['order' => ['id' => true]];
$condition = ['uid' => $uid, 'seen' => false]; $condition = ['uid' => $uid, 'dismissed' => false];
if (!empty($request['account_id'])) { if (!empty($request['account_id'])) {
$contact = Contact::getById($request['account_id'], ['url']); $contact = Contact::getById($request['account_id'], ['url']);

View file

@ -35,7 +35,7 @@ class Clear extends BaseApi
self::checkAllowedScope(self::SCOPE_WRITE); self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID(); $uid = self::getCurrentUserID();
DI::notification()->setAllSeenForUser($uid); DI::notification()->setAllDismissedForUser($uid);
System::jsonExit([]); System::jsonExit([]);
} }

View file

@ -42,7 +42,7 @@ class Dismiss extends BaseApi
} }
$Notification = DI::notification()->selectOneForUser($uid, $this->parameters['id']); $Notification = DI::notification()->selectOneForUser($uid, $this->parameters['id']);
$Notification->setSeen(); $Notification->setDismissed();
DI::notification()->save($Notification); DI::notification()->save($Notification);
System::jsonExit([]); System::jsonExit([]);

View file

@ -40,4 +40,11 @@ class Notifications extends BaseCollection
$Notification->setSeen(); $Notification->setSeen();
}); });
} }
public function setDismissed(): Notifications
{
return $this->map(function (Entity\Notification $Notification) {
$Notification->setDismissed();
});
}
} }

View file

@ -39,6 +39,8 @@ class Notification extends BaseEntity
protected $created; protected $created;
/** @var bool */ /** @var bool */
protected $seen; protected $seen;
/** @var bool */
protected $dismissed;
/** /**
* Please do not use this constructor directly, instead use one of the method of the Notification factory. * 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 DateTime|null $created
* @param bool $seen * @param bool $seen
* @param int|null $id * @param int|null $id
* @param bool $dismissed
* @see \Friendica\Navigation\Notifications\Factory\Notification * @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->uid = $uid;
$this->verb = $verb; $this->verb = $verb;
@ -65,10 +68,16 @@ class Notification extends BaseEntity
$this->created = $created; $this->created = $created;
$this->seen = $seen; $this->seen = $seen;
$this->id = $id; $this->id = $id;
$this->dismissed = $dismissed;
} }
public function setSeen() public function setSeen()
{ {
$this->seen = true; $this->seen = true;
} }
public function setDismissed()
{
$this->dismissed = true;
}
} }

View file

@ -110,6 +110,13 @@ class Notification extends BaseRepository
return $this->db->update(self::$table_name, ['seen' => true], $condition); 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 * @param Entity\Notification $Notification
* @return Entity\Notification * @return Entity\Notification
@ -125,6 +132,7 @@ class Notification extends BaseRepository
'target-uri-id' => $Notification->targetUriId, 'target-uri-id' => $Notification->targetUriId,
'parent-uri-id' => $Notification->parentUriId, 'parent-uri-id' => $Notification->parentUriId,
'seen' => $Notification->seen, 'seen' => $Notification->seen,
'dismissed' => $Notification->dismissed,
]; ];
if ($Notification->id) { if ($Notification->id) {

View file

@ -55,7 +55,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1446); define('DB_UPDATE_VERSION', 1447);
} }
return [ return [
@ -880,7 +880,8 @@ return [
"target-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Item-uri id of the related post"], "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"], "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" => ""], "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" => [ "indexes" => [
"PRIMARY" => ["id"], "PRIMARY" => ["id"],