Skip to content

Commit

Permalink
Add LIKE, UNLIKE, DISLIKE, UNDISLIKE rotor feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Rirusha committed Mar 29, 2024
1 parent 8bce7a4 commit ca9446c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
28 changes: 18 additions & 10 deletions src/client/player/player.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ();
});
Expand All @@ -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;
});
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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
);
}
}
}
16 changes: 14 additions & 2 deletions src/client/talkers/yam_talker.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand All @@ -279,20 +285,26 @@ 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);
}
});
}

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);
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/client/utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dislike_button.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/like_button.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/widgets/views/stations_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ca9446c

Please sign in to comment.