Minor cleanup of todos and imports

This commit is contained in:
Chris 2024-03-12 02:03:30 +01:00
parent 8be2e81054
commit 69fd46b73a
2 changed files with 3 additions and 5 deletions

View File

@ -89,8 +89,6 @@ class ApiHandler
*/ */
private function apiGetSubscriptions(string|null $topic, string|null $subscription): ResponseInterface private function apiGetSubscriptions(string|null $topic, string|null $subscription): ResponseInterface
{ {
// TODO implement once we can enumerate topics and subscriptions
$subscriptions = $this->topicManager->getSubscriptions(); $subscriptions = $this->topicManager->getSubscriptions();
$lastEventId = $this->topicManager->getLastEventId(); $lastEventId = $this->topicManager->getLastEventId();
$data = [ $data = [

View File

@ -2,14 +2,12 @@
namespace NoccyLabs\Mercureact\Http\Middleware; namespace NoccyLabs\Mercureact\Http\Middleware;
use LDAP\Result;
use NoccyLabs\Mercureact\Broker\Message; use NoccyLabs\Mercureact\Broker\Message;
use NoccyLabs\Mercureact\Broker\SseSubscriber; use NoccyLabs\Mercureact\Broker\SseSubscriber;
use NoccyLabs\Mercureact\Broker\TopicManager; use NoccyLabs\Mercureact\Broker\TopicManager;
use NoccyLabs\Mercureact\Configuration; use NoccyLabs\Mercureact\Configuration;
use NoccyLabs\Mercureact\Http\Exception\RequestException; use NoccyLabs\Mercureact\Http\Exception\RequestException;
use NoccyLabs\Mercureact\Http\Exception\SecurityException; use NoccyLabs\Mercureact\Http\Exception\SecurityException;
use NoccyLabs\SimpleJWT\JWTToken;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Loop; use React\EventLoop\Loop;
@ -172,12 +170,14 @@ class MercureHandler
); );
} }
// Explicitly check for duplicate message IDs.
if ($this->config->getRejectDuplicateMessages() && !empty($data['id'])) { if ($this->config->getRejectDuplicateMessages() && !empty($data['id'])) {
if (in_array($data['id'], $this->seenMessageIds)) { if (in_array($data['id'], $this->seenMessageIds)) {
return Response::plaintext("Duplicate message id")->withStatus(Response::STATUS_BAD_REQUEST); return Response::plaintext("Duplicate message id")->withStatus(Response::STATUS_BAD_REQUEST);
} }
array_push($this->seenMessageIds, $data['id']); 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 // Put an id in there if none already