Skip to content

Commit

Permalink
[jsonapi] Include info about tracks added to queue (closes issue #1564)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejurgensen committed Dec 3, 2023
1 parent 1dec798 commit b99ddba
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/httpd_jsonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2304,18 +2304,41 @@ static int
create_reply_queue_tracks_add(struct evbuffer *evbuf, int count, int new_item_id, char shuffle)
{
json_object *reply = json_object_new_object();
json_object *items = json_object_new_array();
json_object *item;
struct query_params query_params = { 0 };
struct db_queue_item queue_item;
int ret;

json_object_object_add(reply, "count", json_object_new_int(count));
json_object_object_add(reply, "items", items);

ret = db_queue_enum_start(&query_params);
if (ret < 0)
goto error;

while ((ret = db_queue_enum_fetch(&query_params, &queue_item)) == 0 && queue_item.id > 0)
{
if (queue_item.id < new_item_id)
continue;

item = queue_item_to_json(&queue_item, shuffle);
if (!item)
goto error;

json_object_array_add(items, item);
}

ret = evbuffer_add_printf(evbuf, "%s", json_object_to_json_string(reply));
if (ret < 0)
goto error;

db_queue_enum_end(&query_params);
jparse_free(reply);
return 0;

error:
db_queue_enum_end(&query_params);
jparse_free(reply);
return -1;
}
Expand Down

0 comments on commit b99ddba

Please sign in to comment.