Skip to content

Commit

Permalink
feat: добавить новый метод в talker и приписать к старому суфикс `_…
Browse files Browse the repository at this point in the history
…old`
  • Loading branch information
Rirusha committed May 20, 2024
1 parent 572625b commit abb470b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/client/cachier/cachier.vala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace Cassette.Client.Cachier {
var pl_obj = (YaMAPI.Playlist) obj;

try {
new_obj = yam_talker.get_playlist_info (pl_obj.uid, pl_obj.kind);
new_obj = yam_talker.get_playlist_info (pl_obj.playlist_uuid);
} catch (BadStatusCodeError e) { }

} else {
Expand Down
43 changes: 41 additions & 2 deletions src/client/talkers/yam-talker.vala
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ namespace Cassette.Client {
storager.db.set_additional_data ("me", me.oid);
storager.save_object (me, false);

get_playlist_info (null, "3");
// TODO: replace with lib func
get_playlist_info_old (null, "3");
get_likes_playlist_list (null);
get_disliked_tracks_short ();

Expand All @@ -131,7 +132,8 @@ namespace Cassette.Client {
yield;
}

public Playlist? get_playlist_info (string? uid = null, string kind = "3") throws BadStatusCodeError {
// TODO: remove this
public Playlist? get_playlist_info_old (string? uid = null, string kind = "3") throws BadStatusCodeError {
Playlist? playlist_info = null;

net_run (() => {
Expand Down Expand Up @@ -168,6 +170,43 @@ namespace Cassette.Client {
return playlist_info;
}

public Playlist? get_playlist_info (string playlist_uuid) throws BadStatusCodeError {
Playlist? playlist_info = null;

net_run (() => {
playlist_info = client.playlist (playlist_uuid, false, true);

if (is_my_liked (playlist_info.uid, playlist_info.kind)) {
likes_controller.update_liked_tracks (playlist_info.tracks);
}

if (playlist_info.tracks.size != 0) {
if (playlist_info.tracks[0].track == null) {
string[] tracks_ids = new string[playlist_info.tracks.size];
for (int i = 0; i < tracks_ids.length; i++) {
tracks_ids[i] = playlist_info.tracks[i].id;
}

var track_list = client.tracks (tracks_ids);
playlist_info.set_track_list (track_list);
}
}

// Сохраняет объект, если он не сохранен в data
// Постоянными объектами занимается уже Cachier.Job
var object_location = storager.object_cache_location (playlist_info.get_type (), playlist_info.oid);
if (object_location.is_tmp && settings.get_boolean ("can-cache")) {
storager.save_object (playlist_info, true);
cachier.controller.change_state (
Cachier.ContentType.PLAYLIST,
playlist_info.oid,
Cachier.CacheingState.TEMP);
}
});

return playlist_info;
}

public Gee.ArrayList<Track>? get_tracks_info (string[] ids) {
Gee.ArrayList<Track>? track_list = null;

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/views/playlist.vala
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ namespace Cassette {

threader.add (() => {
try {
object_info = yam_talker.get_playlist_info (uid, kind);
object_info = yam_talker.get_playlist_info_old (uid, kind);
} catch (BadStatusCodeError e) {
code = e.code;
}
Expand Down

0 comments on commit abb470b

Please sign in to comment.