1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Increase compatibility with misbehaving Fever clients

This commit is contained in:
J. King 2019-07-26 23:23:22 -04:00
parent db5bcb78a3
commit 45a43488ee
2 changed files with 37 additions and 10 deletions

View file

@ -42,6 +42,12 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
'with_ids' => V::T_STRING, 'with_ids' => V::T_STRING,
'group_ids' => V::T_STRING, // undocumented parameter for 'items' lookup 'group_ids' => V::T_STRING, // undocumented parameter for 'items' lookup
'feed_ids' => V::T_STRING, // undocumented parameter for 'items' lookup 'feed_ids' => V::T_STRING, // undocumented parameter for 'items' lookup
// these should be POST parameters only, but some clients misbehave
'mark' => V::T_STRING,
'as' => V::T_STRING,
'id' => V::T_INT,
'before' => V::T_DATE,
'unread_recently_read' => V::T_BOOL,
]; ];
// POST parameters, all of which contain meaningful values // POST parameters, all of which contain meaningful values
const PARAM_POST = [ const PARAM_POST = [
@ -134,6 +140,9 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
// either an 'unread_item_ids' or a // either an 'unread_item_ids' or a
// 'saved_item_ids' entry will be added later // 'saved_item_ids' entry will be added later
$listSaved = $this->setMarks($P, $listUnread); $listSaved = $this->setMarks($P, $listUnread);
} elseif ($G['mark'] && $G['as'] && is_int($G['id'])) {
// some clients send GET rather than POST parameters for marking
$listSaved = $this->setMarks($G, $listUnread);
} }
if ($G['feeds'] || $G['groups']) { if ($G['feeds'] || $G['groups']) {
if ($G['groups']) { if ($G['groups']) {

View file

@ -392,6 +392,24 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest {
} }
} }
/** @dataProvider provideMarkingContexts */
public function testSetMarksWithQuery(string $get, Context $c, array $data, array $out) {
$saved = [['id' => 1],['id' => 2],['id' => 3]];
$unread = [['id' => 4],['id' => 5],['id' => 6]];
\Phake::when(Arsse::$db)->articleList(Arsse::$user->id, (new Context)->starred(true))->thenReturn(new Result($saved));
\Phake::when(Arsse::$db)->articleList(Arsse::$user->id, (new Context)->unread(true))->thenReturn(new Result($unread));
\Phake::when(Arsse::$db)->articleMark->thenReturn(0);
\Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), (new Context)->article(2112))->thenThrow(new \JKingWeb\Arsse\Db\ExceptionInput("subjectMissing"));
$exp = new JsonResponse($out);
$act = $this->h->dispatch($this->req("api&$get"));
$this->assertMessage($exp, $act);
if ($c && $data) {
\Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, $data, $c);
} else {
\Phake::verify(Arsse::$db, \Phake::times(0))->articleMark;
}
}
public function provideMarkingContexts() { public function provideMarkingContexts() {
$markRead = ['read' => true]; $markRead = ['read' => true];
$markUnread = ['read' => false]; $markUnread = ['read' => false];