Fix issue when marking special group "Unread" as read in Fever API

This special group has the ID 0 and do not match any valid group
in Miniflux database.
This commit is contained in:
Frederic Guillot 2017-01-09 17:57:31 -05:00
parent bef6e1032e
commit 31bf0711ee
2 changed files with 27 additions and 13 deletions

View File

@ -24,20 +24,25 @@ function change_item_status($user_id, $item_id, $status)
->table(TABLE) ->table(TABLE)
->eq('user_id', $user_id) ->eq('user_id', $user_id)
->eq('id', $item_id) ->eq('id', $item_id)
->save(array('status' => $status)); ->update(array('status' => $status));
} }
function change_items_status($user_id, $current_status, $new_status) function change_items_status($user_id, $current_status, $new_status, $before = null)
{ {
if (! in_array($new_status, array(STATUS_READ, STATUS_UNREAD, STATUS_REMOVED))) { if (! in_array($new_status, array(STATUS_READ, STATUS_UNREAD, STATUS_REMOVED))) {
return false; return false;
} }
return Database::getInstance('db') $query = Database::getInstance('db')
->table(TABLE) ->table(TABLE)
->eq('user_id', $user_id) ->eq('user_id', $user_id)
->eq('status', $current_status) ->eq('status', $current_status);
->save(array('status' => $new_status));
if ($before !== null) {
$query->lte('updated', $before);
}
return $query->update(array('status' => $new_status));
} }
function change_item_ids_status($user_id, array $item_ids, $status) function change_item_ids_status($user_id, array $item_ids, $status)
@ -54,7 +59,7 @@ function change_item_ids_status($user_id, array $item_ids, $status)
->table(TABLE) ->table(TABLE)
->eq('user_id', $user_id) ->eq('user_id', $user_id)
->in('id', $item_ids) ->in('id', $item_ids)
->save(array('status' => $status)); ->update(array('status' => $status));
} }
function update_feed_items($user_id, $feed_id, array $items, $rtl = false) function update_feed_items($user_id, $feed_id, array $items, $rtl = false)

View File

@ -243,13 +243,22 @@ route('write_groups', function () {
list($user, $authenticated, $response) = auth(); list($user, $authenticated, $response) = auth();
if ($authenticated && ctype_digit($_POST['id']) && ctype_digit($_POST['before'])) { if ($authenticated && ctype_digit($_POST['id']) && ctype_digit($_POST['before'])) {
Model\ItemGroup\change_items_status( if ($_POST['id'] == 0) {
$user['id'], Model\Item\change_items_status(
$_POST['id'], $user['id'],
Model\Item\STATUS_UNREAD, Model\Item\STATUS_UNREAD,
Model\Item\STATUS_READ, Model\Item\STATUS_READ,
$_POST['before'] $_POST['before']
); );
} else {
Model\ItemGroup\change_items_status(
$user['id'],
$_POST['id'],
Model\Item\STATUS_UNREAD,
Model\Item\STATUS_READ,
$_POST['before']
);
}
} }
response($response); response($response);