Skip to content

Commit

Permalink
Fix issue when marking special group "Unread" as read in Fever API
Browse files Browse the repository at this point in the history
This special group has the ID 0 and do not match any valid group
in Miniflux database.
  • Loading branch information
fguillot committed Jan 9, 2017
1 parent bef6e10 commit 31bf071
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
17 changes: 11 additions & 6 deletions app/models/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@ function change_item_status($user_id, $item_id, $status)
->table(TABLE)
->eq('user_id', $user_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))) {
return false;
}

return Database::getInstance('db')
$query = Database::getInstance('db')
->table(TABLE)
->eq('user_id', $user_id)
->eq('status', $current_status)
->save(array('status' => $new_status));
->eq('status', $current_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)
Expand All @@ -54,7 +59,7 @@ function change_item_ids_status($user_id, array $item_ids, $status)
->table(TABLE)
->eq('user_id', $user_id)
->in('id', $item_ids)
->save(array('status' => $status));
->update(array('status' => $status));
}

function update_feed_items($user_id, $feed_id, array $items, $rtl = false)
Expand Down
23 changes: 16 additions & 7 deletions fever/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,22 @@ function auth()
list($user, $authenticated, $response) = auth();

if ($authenticated && ctype_digit($_POST['id']) && ctype_digit($_POST['before'])) {
Model\ItemGroup\change_items_status(
$user['id'],
$_POST['id'],
Model\Item\STATUS_UNREAD,
Model\Item\STATUS_READ,
$_POST['before']
);
if ($_POST['id'] == 0) {
Model\Item\change_items_status(
$user['id'],
Model\Item\STATUS_UNREAD,
Model\Item\STATUS_READ,
$_POST['before']
);
} else {
Model\ItemGroup\change_items_status(
$user['id'],
$_POST['id'],
Model\Item\STATUS_UNREAD,
Model\Item\STATUS_READ,
$_POST['before']
);
}
}

response($response);
Expand Down

0 comments on commit 31bf071

Please sign in to comment.