Skip to content

Commit

Permalink
fix: paused input design
Browse files Browse the repository at this point in the history
This commit fixes the design of `paused` and its usage, now controlled mainly by enums. This addresses a serious issue that on "false" it would never put the paused into the JSON.
  • Loading branch information
ThePedroo committed May 13, 2024
1 parent babaccb commit f3b8cd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion include/rest.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,17 @@ struct coglink_update_player_filters_params {
struct coglink_update_player_filters_lowPass_params *lowPass;
};

enum coglink_paused_state {
COGLINK_PAUSED_STATE_FALSE = 1,
COGLINK_PAUSED_STATE_TRUE = 2
};

struct coglink_update_player_params {
struct coglink_update_player_track_params *track;
int position;
int endTime;
int volume;
bool paused;
enum coglink_paused_state paused;
struct coglink_update_player_filters_params *filters;
};

Expand Down
8 changes: 4 additions & 4 deletions lib/rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ int coglink_update_player(struct coglink_client *c_client, struct coglink_player
if (params->track) {
pjsonb_enter_object(&jsonber, "track");

if (params->track->encoded) pjsonb_set_string(&jsonber, "encoded", params->track->encoded);
if (params->track->identifier) pjsonb_set_string(&jsonber, "identifier", params->track->identifier);
if (params->track->userData) pjsonb_set_string(&jsonber, "userData", params->track->userData);
if (params->track->encoded != NULL) pjsonb_set_string(&jsonber, "encoded", params->track->encoded);
if (params->track->identifier != NULL) pjsonb_set_string(&jsonber, "identifier", params->track->identifier);
if (params->track->userData != NULL) pjsonb_set_string(&jsonber, "userData", params->track->userData);

pjsonb_leave_object(&jsonber);
}
Expand All @@ -403,7 +403,7 @@ int coglink_update_player(struct coglink_client *c_client, struct coglink_player
}

if (params->paused) {
pjsonb_set_bool(&jsonber, "paused", params->paused);
pjsonb_set_bool(&jsonber, "paused", params->paused == COGLINK_PAUSED_STATE_TRUE ? true : false);
}

if (params->filters) {
Expand Down

0 comments on commit f3b8cd5

Please sign in to comment.