Differentiate between followed and created playlists

Fix #56
This commit is contained in:
KoffeinFlummi
2019-04-28 10:54:50 +02:00
parent 754d6d5c04
commit eed3edfa59
4 changed files with 20 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ pub struct Library {
pub artists: Arc<RwLock<Vec<Artist>>>,
pub playlists: Arc<RwLock<Vec<Playlist>>>,
is_done: Arc<RwLock<bool>>,
user_id: Option<String>,
ev: EventManager,
spotify: Arc<Spotify>,
pub use_nerdfont: bool,
@@ -36,12 +37,15 @@ pub struct Library {
impl Library {
pub fn new(ev: &EventManager, spotify: Arc<Spotify>, use_nerdfont: bool) -> Self {
let user_id = spotify.current_user().map(|u| u.id);
let library = Self {
tracks: Arc::new(RwLock::new(Vec::new())),
albums: Arc::new(RwLock::new(Vec::new())),
artists: Arc::new(RwLock::new(Vec::new())),
playlists: Arc::new(RwLock::new(Vec::new())),
is_done: Arc::new(RwLock::new(false)),
user_id,
ev: ev.clone(),
spotify,
use_nerdfont,
@@ -699,6 +703,13 @@ impl Library {
playlists.iter().any(|p| p.id == playlist.id)
}
pub fn is_followed_playlist(&self, playlist: &Playlist) -> bool {
self.user_id
.as_ref()
.map(|id| id != &playlist.owner_id)
.unwrap_or(false)
}
pub fn follow_playlist(&self, playlist: &Playlist) {
if !*self.is_done.read().unwrap() {
return;

View File

@@ -104,7 +104,7 @@ impl ListItem for Playlist {
}
fn display_right(&self, library: Arc<Library>) -> String {
let saved = if library.is_saved_playlist(self) {
let followed = if library.is_followed_playlist(self) {
if library.use_nerdfont {
"\u{f62b} "
} else {
@@ -113,7 +113,7 @@ impl ListItem for Playlist {
} else {
""
};
format!("{}{:>3} tracks", saved, self.tracks.len())
format!("{}{:>3} tracks", followed, self.tracks.len())
}
fn play(&mut self, queue: Arc<Queue>) {

View File

@@ -21,6 +21,7 @@ use rspotify::spotify::model::search::{
SearchAlbums, SearchArtists, SearchPlaylists, SearchTracks,
};
use rspotify::spotify::model::track::{FullTrack, SavedTrack};
use rspotify::spotify::model::user::PrivateUser;
use failure::Error;
@@ -590,6 +591,10 @@ impl Spotify {
.map(|fa| fa.artists.iter().map(|a| a.into()).collect())
}
pub fn current_user(&self) -> Option<PrivateUser> {
self.api_with_retry(|api| api.current_user())
}
pub fn load(&self, track: &Track) {
info!("loading track: {:?}", track);
self.channel