From ca9446c88f5320ad16ec37637917176c9087d593 Mon Sep 17 00:00:00 2001 From: Vladimir Vaskov Date: Fri, 29 Mar 2024 11:08:19 +0300 Subject: [PATCH] Add LIKE, UNLIKE, DISLIKE, UNDISLIKE rotor feedback --- src/client/player/player.vala | 28 ++++++++++++++++++---------- src/client/talkers/yam_talker.vala | 16 ++++++++++++++-- src/client/utils.vala | 4 ++++ src/widgets/dislike_button.vala | 2 +- src/widgets/like_button.vala | 2 +- src/widgets/views/stations_view.vala | 1 + 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/client/player/player.vala b/src/client/player/player.vala index c7493454..01c59920 100644 --- a/src/client/player/player.vala +++ b/src/client/player/player.vala @@ -97,7 +97,7 @@ public class Cassette.Client.Player.Player : Object { } } - public double total_playback_sec { get; set; default = 0.0;} + public double total_played_seconds { get; set; default = 0.0;} public int64 playback_pos_ms { get { @@ -223,12 +223,6 @@ public class Cassette.Client.Player.Player : Object { bind_property ("mute", playbin, "mute", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE); settings.bind ("mute", this, "mute", SettingsBindFlags.DEFAULT); - playback_callback.connect (() => { - total_playback_sec += PLAY_CALLBACK_STEP; - - update_can_go (); - }); - next_track_loaded.connect (() => { update_can_go (); }); @@ -238,6 +232,10 @@ public class Cassette.Client.Player.Player : Object { playback_callback (playback_pos_sec); } + total_played_seconds += PLAY_CALLBACK_STEP; + + update_can_go (); + return Source.CONTINUE; }); } @@ -249,7 +247,7 @@ public class Cassette.Client.Player.Player : Object { void reset_play () { play_id = Uuid.string_random (); - total_playback_sec = 0.0; + total_played_seconds = 0.0; } void init (string[]? args) { @@ -351,14 +349,14 @@ public class Cassette.Client.Player.Player : Object { mode.send_play_async.begin ( play_id, natural ? ms2sec (mode.get_current_track_info ().duration_ms) : playback_pos_sec, - total_playback_sec + total_played_seconds ); if (mode is Flow) { ((Flow) mode).send_feedback.begin ( natural ? YaMAPI.Rotor.FeedbackType.TRACK_FINISHED : YaMAPI.Rotor.FeedbackType.SKIP, current_track.id, - total_playback_sec + total_played_seconds ); } @@ -526,4 +524,14 @@ public class Cassette.Client.Player.Player : Object { mode_inited (); } + + public void rotor_feedback (string feedback_type, string track_id) { + if (mode is Flow && mode.get_current_track_info ().id == track_id) { + ((Flow) mode).send_feedback.begin ( + feedback_type, + track_id, + total_played_seconds + ); + } + } } diff --git a/src/client/talkers/yam_talker.vala b/src/client/talkers/yam_talker.vala index e03b1804..f09f5ecf 100644 --- a/src/client/talkers/yam_talker.vala +++ b/src/client/talkers/yam_talker.vala @@ -254,19 +254,25 @@ namespace Cassette.Client { track_likes_end_change (content_id, true); if (content_type == LikableType.TRACK) { likes_controller.remove_disliked (content_id); + // TODO: Mode to like controller + player.rotor_feedback (Rotor.FeedbackType.LIKE, content_id); + track_dislikes_end_change (content_id, false); } } }); } - public void remove_like (LikableType content_type, string content_id) { + public void unlike (LikableType content_type, string content_id) { net_run_wout_code (() => { track_likes_start_change (content_id); bool is_ok = client.remove_like (get_likable_type (content_type), content_id); if (is_ok) { likes_controller.remove_liked (content_type, content_id); + // TODO: Mode to like controller + player.rotor_feedback (Rotor.FeedbackType.UNLIKE, content_id); + track_likes_end_change (content_id, false); } }); @@ -279,6 +285,9 @@ namespace Cassette.Client { bool is_ok = client.dislike (track_id); if (is_ok) { likes_controller.add_disliked (track_id); + // TODO: Mode to like controller + player.rotor_feedback (Rotor.FeedbackType.DISLIKE, track_id); + track_dislikes_end_change (track_id, true); likes_controller.remove_liked (LikableType.TRACK, track_id); track_likes_end_change (track_id, false); @@ -286,13 +295,16 @@ namespace Cassette.Client { }); } - public void remove_dislike (string track_id) { + public void undislike (string track_id) { net_run_wout_code (() => { track_dislikes_start_change (track_id); bool is_ok = client.remove_dislike (track_id); if (is_ok) { likes_controller.remove_disliked (track_id); + // TODO: Mode to like controller + player.rotor_feedback (Rotor.FeedbackType.UNDISLIKE, track_id); + track_dislikes_end_change (track_id, false); } }); diff --git a/src/client/utils.vala b/src/client/utils.vala index df4d5f7f..2d223c16 100644 --- a/src/client/utils.vala +++ b/src/client/utils.vala @@ -32,6 +32,10 @@ namespace Cassette.Client { public const string SKIP = "skip"; public const string TRACK_FINISHED = "trackFinished"; public const string RADIO_FINISHED = "radioFinished"; + public const string LIKE = "like"; + public const string UNLIKE = "unlike"; + public const string DISLIKE = "dislike"; + public const string UNDISLIKE = "undislike"; } namespace StationType { diff --git a/src/widgets/dislike_button.vala b/src/widgets/dislike_button.vala index edd075d3..e332fc68 100644 --- a/src/widgets/dislike_button.vala +++ b/src/widgets/dislike_button.vala @@ -135,7 +135,7 @@ namespace Cassette { threader.add (() => { if (is_disliked) { - yam_talker.remove_dislike (content_id); + yam_talker.undislike (content_id); } else { yam_talker.dislike (content_id); } diff --git a/src/widgets/like_button.vala b/src/widgets/like_button.vala index 3edf2fc0..afe3021d 100644 --- a/src/widgets/like_button.vala +++ b/src/widgets/like_button.vala @@ -164,7 +164,7 @@ namespace Cassette { threader.add (() => { if (is_liked) { - yam_talker.remove_like (object_content_type, content_id); + yam_talker.unlike (object_content_type, content_id); } else { yam_talker.like (object_content_type, content_id); } diff --git a/src/widgets/views/stations_view.vala b/src/widgets/views/stations_view.vala index 6befa98d..9b2196df 100644 --- a/src/widgets/views/stations_view.vala +++ b/src/widgets/views/stations_view.vala @@ -64,6 +64,7 @@ namespace Cassette { Gtk.FlowBox target_flow_box; switch (station.station.id.type_) { + case "micro-genre": case "genre": target_flow_box = genre_flow_box; break;