From d1211e69010afc0f85c781662540ad20c7055f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Andersson?= Date: Sun, 22 Nov 2020 19:26:20 +0100 Subject: [PATCH] Only show playlists where the user is allowed to add tracks when trying to add tracks (#329) * Only show playlists where the user is allowed to add tracks * Expose user_id from library and use it to reduce api calls --- src/library.rs | 2 +- src/playlist.rs | 3 +++ src/ui/contextmenu.rs | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/library.rs b/src/library.rs index d584ed3..5aa9fc6 100644 --- a/src/library.rs +++ b/src/library.rs @@ -33,7 +33,7 @@ pub struct Library { pub playlists: Arc>>, pub shows: Arc>>, pub is_done: Arc>, - user_id: Option, + pub user_id: Option, ev: EventManager, spotify: Arc, pub cfg: Arc, diff --git a/src/playlist.rs b/src/playlist.rs index 04477f7..81bf32a 100644 --- a/src/playlist.rs +++ b/src/playlist.rs @@ -19,6 +19,7 @@ pub struct Playlist { pub snapshot_id: String, pub num_tracks: usize, pub tracks: Option>, + pub collaborative: bool } impl Playlist { @@ -128,6 +129,7 @@ impl From<&SimplifiedPlaylist> for Playlist { snapshot_id: list.snapshot_id.clone(), num_tracks, tracks: None, + collaborative: list.collaborative, } } } @@ -141,6 +143,7 @@ impl From<&FullPlaylist> for Playlist { snapshot_id: list.snapshot_id.clone(), num_tracks: list.tracks.total as usize, tracks: None, + collaborative: list.collaborative } } } diff --git a/src/ui/contextmenu.rs b/src/ui/contextmenu.rs index bb11554..e8f4a61 100644 --- a/src/ui/contextmenu.rs +++ b/src/ui/contextmenu.rs @@ -38,9 +38,12 @@ impl ContextMenu { track: Track, ) -> Modal { let mut list_select: SelectView = SelectView::new().autojump(); + let current_user_id = library.user_id.as_ref().unwrap(); for list in library.items().iter() { - list_select.add_item(list.name.clone(), list.clone()); + if current_user_id == &list.owner_id || list.collaborative { + list_select.add_item(list.name.clone(), list.clone()); + } } list_select.set_on_submit(move |s, selected| {