From 69fd46b73ae9d97337963cc2f515886dce0b9680 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Tue, 12 Mar 2024 02:03:30 +0100 Subject: [PATCH] Minor cleanup of todos and imports --- src/Http/Middleware/ApiHandler.php | 2 -- src/Http/Middleware/MercureHandler.php | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Http/Middleware/ApiHandler.php b/src/Http/Middleware/ApiHandler.php index 33b1772..6bc5f52 100644 --- a/src/Http/Middleware/ApiHandler.php +++ b/src/Http/Middleware/ApiHandler.php @@ -89,8 +89,6 @@ class ApiHandler */ private function apiGetSubscriptions(string|null $topic, string|null $subscription): ResponseInterface { - // TODO implement once we can enumerate topics and subscriptions - $subscriptions = $this->topicManager->getSubscriptions(); $lastEventId = $this->topicManager->getLastEventId(); $data = [ diff --git a/src/Http/Middleware/MercureHandler.php b/src/Http/Middleware/MercureHandler.php index d8456fe..22ab9d2 100644 --- a/src/Http/Middleware/MercureHandler.php +++ b/src/Http/Middleware/MercureHandler.php @@ -2,14 +2,12 @@ namespace NoccyLabs\Mercureact\Http\Middleware; -use LDAP\Result; use NoccyLabs\Mercureact\Broker\Message; use NoccyLabs\Mercureact\Broker\SseSubscriber; use NoccyLabs\Mercureact\Broker\TopicManager; use NoccyLabs\Mercureact\Configuration; use NoccyLabs\Mercureact\Http\Exception\RequestException; use NoccyLabs\Mercureact\Http\Exception\SecurityException; -use NoccyLabs\SimpleJWT\JWTToken; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use React\EventLoop\Loop; @@ -172,12 +170,14 @@ class MercureHandler ); } + // Explicitly check for duplicate message IDs. if ($this->config->getRejectDuplicateMessages() && !empty($data['id'])) { if (in_array($data['id'], $this->seenMessageIds)) { return Response::plaintext("Duplicate message id")->withStatus(Response::STATUS_BAD_REQUEST); } array_push($this->seenMessageIds, $data['id']); - $this->seenMessageIds = array_slice($this->seenMessageIds, -100, 100); + while (count($this->seenMessageIds) > $this->seenIdHistorySize) + array_shift($this->seenMessageIds); } // Put an id in there if none already