From 7e173327149d86443969940481c8e13285bc245c Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 31 Dec 2020 17:50:40 -0500 Subject: [PATCH] Implement marking all as read for Miniflux --- lib/REST/Miniflux/V1.php | 10 ++++++++++ tests/cases/REST/Miniflux/TestV1.php | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/lib/REST/Miniflux/V1.php b/lib/REST/Miniflux/V1.php index 12f509a..9ad2882 100644 --- a/lib/REST/Miniflux/V1.php +++ b/lib/REST/Miniflux/V1.php @@ -489,6 +489,16 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { return new EmptyResponse(204); } + protected function markUserByNum(array $path): ResponseInterface { + // this function is restricted to the logged-in user + $user = Arsse::$user->propertiesGet(Arsse::$user->id, false); + if (((int) $path[1]) !== $user['num']) { + return new ErrorResponse("403", 403); + } + Arsse::$db->articleMark(Arsse::$user->id, ['read' => true], (new Context)->hidden(false)); + return new EmptyResponse(204); + } + protected function getCategories(): ResponseInterface { $out = []; $meta = Arsse::$user->propertiesGet(Arsse::$user->id, false); diff --git a/tests/cases/REST/Miniflux/TestV1.php b/tests/cases/REST/Miniflux/TestV1.php index 3851ab3..255d9a5 100644 --- a/tests/cases/REST/Miniflux/TestV1.php +++ b/tests/cases/REST/Miniflux/TestV1.php @@ -400,6 +400,13 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertMessage(new ErrorResponse("403", 403), $this->req("DELETE", "/users/2112")); } + public function testMarkAllArticlesAsRead(): void { + \Phake::when(Arsse::$db)->articleMark->thenReturn(true); + $this->assertMessage(new ErrorResponse("403", 403), $this->req("PUT", "/users/1/mark-all-as-read")); + $this->assertMessage(new EmptyResponse(204), $this->req("PUT", "/users/42/mark-all-as-read")); + \Phake::verify(Arsse::$db)->articleMark("john.doe@example.com", ['read' => true], (new Context)->hidden(false)); + } + public function testListCategories(): void { \Phake::when(Arsse::$db)->folderList->thenReturn(new Result($this->v([ ['id' => 1, 'name' => "Science"],