Skip to content

Commit

Permalink
Upd: restrict sticker list by type
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Aug 31, 2024
1 parent 0052cdc commit fac7756
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
17 changes: 13 additions & 4 deletions src/lib/fields.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ void stickers_reset(struct t_stickers *stickers) {
/**
* Enables all stickers
* @param stickers pointer to t_stickers struct
* @param sticker_type myMPD sticker type
*/
void stickers_enable_all(struct t_stickers *stickers) {
stickers->len = STICKER_COUNT;
for (int i = 0; i < STICKER_COUNT; i++) {
stickers->stickers[i] = i;
void stickers_enable_all(struct t_stickers *stickers, enum mympd_sticker_type sticker_type) {
switch(sticker_type) {
case STICKER_TYPE_SONG:
stickers->len = STICKER_COUNT;
for (int i = 0; i < STICKER_COUNT; i++) {
stickers->stickers[i] = i;
}
break;
default:
stickers->len = 2;
stickers->stickers[0] = STICKER_LIKE;
stickers->stickers[1] = STICKER_RATING;
}
stickers->user_defined = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void fields_clone(struct t_fields *src_fields, struct t_fields *dst_fields);
void fields_reset(struct t_fields *fields);

void stickers_reset(struct t_stickers *stickers);
void stickers_enable_all(struct t_stickers *stickers);
void stickers_enable_all(struct t_stickers *stickers, enum mympd_sticker_type sticker_type);

void mpd_tags_clone(struct t_mpd_tags *src_mpd_tags, struct t_mpd_tags *dst_mpd_tags);
void mpd_tags_reset(struct t_mpd_tags *mpd_tags);
Expand Down
2 changes: 1 addition & 1 deletion src/mympd_api/browse.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ sds mympd_api_browse_album_detail(struct t_mympd_state *mympd_state, struct t_pa
if (partition_state->mpd_state->feat.stickers == true) {
struct t_stickers sticker;
stickers_reset(&sticker);
stickers_enable_all(&sticker);
stickers_enable_all(&sticker, STICKER_TYPE_FILTER);
buffer = mympd_api_sticker_get_print(buffer, mympd_state->stickerdb, STICKER_TYPE_FILTER, expression, &sticker);
}
buffer = jsonrpc_end(buffer);
Expand Down
4 changes: 2 additions & 2 deletions src/mympd_api/playlists.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,10 +830,10 @@ sds mympd_api_playlist_content_search(struct t_partition_state *partition_state,
buffer = tojson_time(buffer, "time", last_played_max, true);
buffer = tojson_sds(buffer, "uri", last_played_song_uri, false);
buffer = sdscatlen(buffer, "}", 1);
if (partition_state->mpd_state->feat.stickers == true) {
if (partition_state->mpd_state->feat.advsticker == true) {
struct t_stickers sticker;
stickers_reset(&sticker);
stickers_enable_all(&sticker);
stickers_enable_all(&sticker, STICKER_TYPE_PLAYLIST);
buffer = mympd_api_sticker_get_print(buffer, stickerdb, STICKER_TYPE_PLAYLIST, plist, &sticker);
}
buffer = jsonrpc_end(buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/mympd_api/song.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sds mympd_api_song_details(struct t_mympd_state *mympd_state, struct t_partition
if (partition_state->mpd_state->feat.stickers == true) {
struct t_stickers sticker;
stickers_reset(&sticker);
stickers_enable_all(&sticker);
stickers_enable_all(&sticker, STICKER_TYPE_SONG);
buffer = mympd_api_sticker_get_print(buffer, mympd_state->stickerdb, STICKER_TYPE_SONG, uri, &sticker);
}

Expand Down
2 changes: 1 addition & 1 deletion src/mympd_api/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ sds mympd_api_status_current_song(struct t_mympd_state *mympd_state, struct t_pa
if (partition_state->mpd_state->feat.stickers == true) {
struct t_stickers sticker;
stickers_reset(&sticker);
stickers_enable_all(&sticker);
stickers_enable_all(&sticker, STICKER_TYPE_SONG);
buffer = mympd_api_sticker_get_print(buffer, mympd_state->stickerdb, STICKER_TYPE_SONG, uri, &sticker);
}
buffer = json_comma(buffer);
Expand Down
4 changes: 2 additions & 2 deletions src/mympd_api/sticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sds mympd_api_sticker_list(struct t_stickerdb_state *stickerdb, sds buffer, unsi
sds uri, enum mympd_sticker_type type)
{
struct t_stickers stickers;
stickers_enable_all(&stickers);
stickers_enable_all(&stickers, type);
buffer = jsonrpc_respond_start(buffer, MYMPD_API_STICKER_LIST, request_id);
buffer = mympd_api_sticker_get_print(buffer, stickerdb, type, uri, &stickers);
buffer = jsonrpc_end(buffer);
Expand Down Expand Up @@ -105,7 +105,7 @@ bool mympd_api_sticker_set_feedback(struct t_stickerdb_state *stickerdb, struct
* @param stickerdb pointer to stickerdb
* @param type MPD sticker type
* @param uri song uri
* @param stickers array of stickers to print
* @param stickers list of stickers to print
* @return pointer to the modified buffer
*/
sds mympd_api_sticker_get_print(sds buffer, struct t_stickerdb_state *stickerdb,
Expand Down

0 comments on commit fac7756

Please sign in to comment.