mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 08:24:54 +00:00
Increase compatibility with misbehaving Fever clients
This commit is contained in:
parent
db5bcb78a3
commit
45a43488ee
2 changed files with 37 additions and 10 deletions
|
@ -33,15 +33,21 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
|
||||||
const PARAM_BOOL = ["groups", "feeds", "items", "favicons", "links", "unread_item_ids", "saved_item_ids"];
|
const PARAM_BOOL = ["groups", "feeds", "items", "favicons", "links", "unread_item_ids", "saved_item_ids"];
|
||||||
// GET parameters which contain meaningful values
|
// GET parameters which contain meaningful values
|
||||||
const PARAM_GET = [
|
const PARAM_GET = [
|
||||||
'api' => V::T_STRING, // this parameter requires special handling
|
'api' => V::T_STRING, // this parameter requires special handling
|
||||||
'page' => V::T_INT, // parameter for hot links
|
'page' => V::T_INT, // parameter for hot links
|
||||||
'range' => V::T_INT, // parameter for hot links
|
'range' => V::T_INT, // parameter for hot links
|
||||||
'offset' => V::T_INT, // parameter for hot links
|
'offset' => V::T_INT, // parameter for hot links
|
||||||
'since_id' => V::T_INT,
|
'since_id' => V::T_INT,
|
||||||
'max_id' => V::T_INT,
|
'max_id' => V::T_INT,
|
||||||
'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']) {
|
||||||
|
@ -244,7 +253,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setMarks(array $P, &$listUnread): bool {
|
protected function setMarks(array $P, &$listUnread): bool {
|
||||||
$listSaved = false;
|
$listSaved = false;
|
||||||
$c = new Context;
|
$c = new Context;
|
||||||
$id = $P['id'];
|
$id = $P['id'];
|
||||||
|
|
|
@ -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];
|
||||||
|
|
Loading…
Reference in a new issue