diff --git a/CHANGELOG b/CHANGELOG index d906319..25c4b2a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,8 +2,10 @@ Version 0.2.1 (2017-12-??) ========================== Bug fixes: +- Make SQLite timeouts much less likely - Accept base64-encoded passwords from TTRSS clients - Rename feeds correctly via TTRSS protocol +- Toggle marks correctly via TTRSS protocol - Be even stricter about output data types in NextCloud News Version 0.2.0 (2017-11-30) diff --git a/lib/REST/TinyTinyRSS/API.php b/lib/REST/TinyTinyRSS/API.php index 2a31304..677d1a3 100644 --- a/lib/REST/TinyTinyRSS/API.php +++ b/lib/REST/TinyTinyRSS/API.php @@ -1095,8 +1095,14 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler { $out += Arsse::$db->articleMark(Arsse::$user->id, ['starred' => (bool) $data['mode']], (new Context)->articles($articles)); break; case 2: //toggle - $out += Arsse::$db->articleMark(Arsse::$user->id, ['starred' => true], (new Context)->articles($articles)->starred(false)); - $out += Arsse::$db->articleMark(Arsse::$user->id, ['starred' => false], (new Context)->articles($articles)->starred(true)); + $on = array_column(Arsse::$db->articleList(Arsse::$user->id, (new Context)->articles($articles)->starred(true), Database::LIST_MINIMAL)->getAll(), "id"); + $off = array_column(Arsse::$db->articleList(Arsse::$user->id, (new Context)->articles($articles)->starred(false), Database::LIST_MINIMAL)->getAll(), "id"); + if ($off) { + $out += Arsse::$db->articleMark(Arsse::$user->id, ['starred' => true], (new Context)->articles($off)); + } + if ($on) { + $out += Arsse::$db->articleMark(Arsse::$user->id, ['starred' => false], (new Context)->articles($on)); + } break; default: throw new Exception("INCORRECT_USAGE"); @@ -1121,8 +1127,14 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler { $out += Arsse::$db->articleMark(Arsse::$user->id, ['read' => !$data['mode']], (new Context)->articles($articles)); break; case 2: //toggle - $out += Arsse::$db->articleMark(Arsse::$user->id, ['read' => true], (new Context)->articles($articles)->unread(true)); - $out += Arsse::$db->articleMark(Arsse::$user->id, ['read' => false], (new Context)->articles($articles)->unread(false)); + $on = array_column(Arsse::$db->articleList(Arsse::$user->id, (new Context)->articles($articles)->unread(true), Database::LIST_MINIMAL)->getAll(), "id"); + $off = array_column(Arsse::$db->articleList(Arsse::$user->id, (new Context)->articles($articles)->unread(false), Database::LIST_MINIMAL)->getAll(), "id"); + if ($off) { + $out += Arsse::$db->articleMark(Arsse::$user->id, ['read' => false], (new Context)->articles($off)); + } + if ($on) { + $out += Arsse::$db->articleMark(Arsse::$user->id, ['read' => true], (new Context)->articles($on)); + } break; default: throw new Exception("INCORRECT_USAGE"); diff --git a/tests/REST/TinyTinyRSS/TestTinyTinyAPI.php b/tests/REST/TinyTinyRSS/TestTinyTinyAPI.php index 2f7f66a..957703a 100644 --- a/tests/REST/TinyTinyRSS/TestTinyTinyAPI.php +++ b/tests/REST/TinyTinyRSS/TestTinyTinyAPI.php @@ -1255,15 +1255,19 @@ LONG_STRING; ['op' => "updateArticle", 'sid' => "PriestsOfSyrinx", 'article_ids' => "42, 2112, -1", 'field' => 4], // invalid field ['op' => "updateArticle", 'sid' => "PriestsOfSyrinx", 'article_ids' => "0, -1", 'field' => 3], // no valid IDs ]; + Phake::when(Arsse::$db)->articleList($this->anything(), (new Context)->articles([42, 2112])->starred(true), $this->anything())->thenReturn(new Result([['id' => 42]])); + Phake::when(Arsse::$db)->articleList($this->anything(), (new Context)->articles([42, 2112])->starred(false), $this->anything())->thenReturn(new Result([['id' => 2112]])); + Phake::when(Arsse::$db)->articleList($this->anything(), (new Context)->articles([42, 2112])->unread(true), $this->anything())->thenReturn(new Result([['id' => 42]])); + Phake::when(Arsse::$db)->articleList($this->anything(), (new Context)->articles([42, 2112])->unread(false), $this->anything())->thenReturn(new Result([['id' => 2112]])); Phake::when(Arsse::$db)->articleMark->thenReturn(1); Phake::when(Arsse::$db)->articleMark($this->anything(), ['starred' => false], (new Context)->articles([42, 2112]))->thenReturn(2); Phake::when(Arsse::$db)->articleMark($this->anything(), ['starred' => true], (new Context)->articles([42, 2112]))->thenReturn(4); - Phake::when(Arsse::$db)->articleMark($this->anything(), ['starred' => false], (new Context)->articles([42, 2112])->starred(true))->thenReturn(8); - Phake::when(Arsse::$db)->articleMark($this->anything(), ['starred' => true], (new Context)->articles([42, 2112])->starred(false))->thenReturn(16); + Phake::when(Arsse::$db)->articleMark($this->anything(), ['starred' => false], (new Context)->articles([42]))->thenReturn(8); + Phake::when(Arsse::$db)->articleMark($this->anything(), ['starred' => true], (new Context)->articles([2112]))->thenReturn(16); Phake::when(Arsse::$db)->articleMark($this->anything(), ['read' => true], (new Context)->articles([42, 2112]))->thenReturn(32); // false is read for TT-RSS Phake::when(Arsse::$db)->articleMark($this->anything(), ['read' => false], (new Context)->articles([42, 2112]))->thenReturn(64); - Phake::when(Arsse::$db)->articleMark($this->anything(), ['read' => true], (new Context)->articles([42, 2112])->unread(true))->thenReturn(128); - Phake::when(Arsse::$db)->articleMark($this->anything(), ['read' => false], (new Context)->articles([42, 2112])->unread(false))->thenReturn(256); + Phake::when(Arsse::$db)->articleMark($this->anything(), ['read' => true], (new Context)->articles([42]))->thenReturn(128); + Phake::when(Arsse::$db)->articleMark($this->anything(), ['read' => false], (new Context)->articles([2112]))->thenReturn(256); Phake::when(Arsse::$db)->articleMark($this->anything(), ['note' => ""], (new Context)->articles([42, 2112]))->thenReturn(512); Phake::when(Arsse::$db)->articleMark($this->anything(), ['note' => "eh"], (new Context)->articles([42, 2112]))->thenReturn(1024); $out = [ diff --git a/tests/lib/Database/SeriesArticle.php b/tests/lib/Database/SeriesArticle.php index caf6537..8226711 100644 --- a/tests/lib/Database/SeriesArticle.php +++ b/tests/lib/Database/SeriesArticle.php @@ -416,6 +416,7 @@ trait SeriesArticle { $this->compareIds([19], (new Context)->subscription(5)->unread(false)); // get starred articles $this->compareIds([1,20], (new Context)->starred(true)); + $this->compareIds([2,3,4,5,6,7,8,19], (new Context)->starred(false)); $this->compareIds([1], (new Context)->starred(true)->unread(false)); $this->compareIds([], (new Context)->starred(true)->unread(false)->subscription(5)); // get items relative to edition @@ -466,6 +467,9 @@ trait SeriesArticle { // get articles base on whether or not they have notes $this->compareIds([1,3,4,5,6,7,8,19,20], (new Context)->annotated(false)); $this->compareIds([2], (new Context)->annotated(true)); + // get specific starred articles + $this->compareIds([1], (new Context)->articles([1,2,3])->starred(true)); + $this->compareIds([2,3], (new Context)->articles([1,2,3])->starred(false)); } public function testListArticlesOfAMissingFolder() {