From a27ffda59f76d4be6a10963c5d6365675e650268 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Wed, 30 Nov 2022 14:23:20 -0500 Subject: [PATCH 1/4] Add dismissed field to Mastodon API Notification types --- src/Factory/Api/Mastodon/Notification.php | 4 +++- src/Object/Api/Mastodon/Notification.php | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Factory/Api/Mastodon/Notification.php b/src/Factory/Api/Mastodon/Notification.php index 32ea681da..ec6581cc5 100644 --- a/src/Factory/Api/Mastodon/Notification.php +++ b/src/Factory/Api/Mastodon/Notification.php @@ -70,7 +70,9 @@ class Notification extends BaseFactory $status = null; } - return new MstdnNotification($Notification->id, $type, $Notification->created, $account, $status); + $dismissed = $Notification->dismissed; + + return new MstdnNotification($Notification->id, $type, $Notification->created, $account, $status, $dismissed); } /** diff --git a/src/Object/Api/Mastodon/Notification.php b/src/Object/Api/Mastodon/Notification.php index a54eda45d..aeec92413 100644 --- a/src/Object/Api/Mastodon/Notification.php +++ b/src/Object/Api/Mastodon/Notification.php @@ -56,6 +56,8 @@ class Notification extends BaseDataTransferObject protected $type; /** @var string (Datetime) */ protected $created_at; + /** @var bool */ + protected $dismissed; /** @var Account */ protected $account; /** @var Status|null */ @@ -66,12 +68,13 @@ class Notification extends BaseDataTransferObject * * @throws HttpException\InternalServerErrorException|Exception */ - public function __construct(int $id, string $type, \DateTime $created_at, Account $account = null, Status $status = null) + public function __construct(int $id, string $type, \DateTime $created_at, Account $account = null, Status $status = null, bool $dismissed = false) { $this->id = (string)$id; $this->type = $type; $this->created_at = $created_at->format(DateTimeFormat::JSON); $this->account = $account->toArray(); + $this->dismissed = $dismissed; if (!empty($status)) { $this->status = $status->toArray(); From a2559d6241bec6a37947f2d7e034479fbbcc875c Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Wed, 30 Nov 2022 14:24:46 -0500 Subject: [PATCH 2/4] Add 'include_all' parameter on Mastodon API endpoint Maintains old functionality of only returning non-dismissed notifications while adding ability to get list of dismissed and non-dismissed notifications --- src/Module/Api/Mastodon/Notifications.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Module/Api/Mastodon/Notifications.php b/src/Module/Api/Mastodon/Notifications.php index 4ab71d88f..0ea6b72e2 100644 --- a/src/Module/Api/Mastodon/Notifications.php +++ b/src/Module/Api/Mastodon/Notifications.php @@ -63,12 +63,16 @@ class Notifications extends BaseApi 'exclude_types' => [], // Array of types to exclude (follow, favourite, reblog, mention, poll, follow_request) 'account_id' => 0, // Return only notifications received from this account 'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users. - 'count' => 0, // Unknown parameter + 'count' => 0, + 'include_all' => false // Include dismissed and undismissed ], $request); $params = ['order' => ['id' => true]]; $condition = ['uid' => $uid, 'dismissed' => false]; + if($request['include_all']) { + $condition = ['uid' => $uid]; + } if (!empty($request['account_id'])) { $contact = Contact::getById($request['account_id'], ['url']); From b51b537711a9128c381d6a24cfa43f2dfd8b6a3e Mon Sep 17 00:00:00 2001 From: Hank G Date: Wed, 30 Nov 2022 14:38:53 -0500 Subject: [PATCH 3/4] Update src/Factory/Api/Mastodon/Notification.php Co-authored-by: Hypolite Petovan --- src/Factory/Api/Mastodon/Notification.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Factory/Api/Mastodon/Notification.php b/src/Factory/Api/Mastodon/Notification.php index ec6581cc5..c85cfac78 100644 --- a/src/Factory/Api/Mastodon/Notification.php +++ b/src/Factory/Api/Mastodon/Notification.php @@ -70,9 +70,7 @@ class Notification extends BaseFactory $status = null; } - $dismissed = $Notification->dismissed; - - return new MstdnNotification($Notification->id, $type, $Notification->created, $account, $status, $dismissed); + return new MstdnNotification($Notification->id, $type, $Notification->created, $account, $status, $Notification->dismissed); } /** From f61dbf76a76901cec90d8407ce3618979208a960 Mon Sep 17 00:00:00 2001 From: Hank G Date: Wed, 30 Nov 2022 14:39:00 -0500 Subject: [PATCH 4/4] Update src/Module/Api/Mastodon/Notifications.php Co-authored-by: Hypolite Petovan --- src/Module/Api/Mastodon/Notifications.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Api/Mastodon/Notifications.php b/src/Module/Api/Mastodon/Notifications.php index 0ea6b72e2..844736259 100644 --- a/src/Module/Api/Mastodon/Notifications.php +++ b/src/Module/Api/Mastodon/Notifications.php @@ -70,7 +70,7 @@ class Notifications extends BaseApi $params = ['order' => ['id' => true]]; $condition = ['uid' => $uid, 'dismissed' => false]; - if($request['include_all']) { + if ($request['include_all']) { $condition = ['uid' => $uid]; }