Skip to content

Commit

Permalink
connect: remove duplicate track
Browse files Browse the repository at this point in the history
  • Loading branch information
photovoltex committed Dec 19, 2024
1 parent 67ceecd commit 7d7e786
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions connect/src/state/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ impl ConnectState {
) -> Result<Option<Vec<String>>, Error> {
if context.pages.iter().all(|p| p.tracks.is_empty()) {
error!("context didn't have any tracks: {context:#?}");
return Err(StateError::ContextHasNoTracks.into());
Err(StateError::ContextHasNoTracks)?;
} else if context.uri.starts_with(LOCAL_FILES_IDENTIFIER) {
return Err(StateError::UnsupportedLocalPlayBack.into());
Err(StateError::UnsupportedLocalPlayBack)?;
}

let mut next_contexts = Vec::new();
Expand All @@ -200,7 +200,7 @@ impl ConnectState {
}
}

let page = match first_page {
let mut page = match first_page {
None => Err(StateError::ContextHasNoTracks)?,
Some(p) => p,
};
Expand Down Expand Up @@ -245,14 +245,25 @@ impl ConnectState {

self.context = Some(new_context);

if !context.url.starts_with(SEARCH_IDENTIFIER) {
if !context.url.contains(SEARCH_IDENTIFIER) {
self.player_mut().context_url = context.url;
} else {
self.player_mut().context_url.clear()
}
self.player_mut().context_uri = context.uri;
}
UpdateContext::Autoplay => {
if matches!(self.context.as_ref(), Some(ctx) if ctx.tracks.len() == 1) {
if let Some(position) = page
.tracks
.iter()
.position(|p| self.current_track(|t| t.uri == p.uri))
{
debug!("removing track (of single track context) from autoplay context");
page.tracks.remove(position);
}
}

self.autoplay_context = Some(self.state_context_from_page(
page,
context.metadata,
Expand Down

0 comments on commit 7d7e786

Please sign in to comment.