Skip to content

Commit

Permalink
connect: provide all recently played tracks to autoplay request
Browse files Browse the repository at this point in the history
- removes previously added workaround
  • Loading branch information
photovoltex committed Dec 19, 2024
1 parent 7d7e786 commit 309ca8d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
5 changes: 2 additions & 3 deletions connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl SpircTask {
// finish after we received our last item of a type
next_context = async {
self.context_resolver.get_next_context(|| {
self.connect_state.prev_autoplay_track_uris()
self.connect_state.recent_track_uris()
}).await
}, if allow_context_resolving && self.context_resolver.has_next() => {
let update_state = self.handle_next_context(next_context);
Expand Down Expand Up @@ -1105,8 +1105,6 @@ impl SpircTask {
cmd: SpircLoadCommand,
context: Option<Context>,
) -> Result<(), Error> {
self.context_resolver.clear();

self.connect_state
.reset_context(ResetContext::WhenDifferent(&cmd.context_uri));

Expand All @@ -1128,6 +1126,7 @@ impl SpircTask {
debug!("context <{current_context_uri}> didn't change, no resolving required")
} else {
debug!("resolving context for load command");
self.context_resolver.clear();
self.context_resolver.add(ResolveContext::from_uri(
&cmd.context_uri,
fallback,
Expand Down
13 changes: 1 addition & 12 deletions connect/src/state/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl ConnectState {
}
}

let mut page = match first_page {
let page = match first_page {
None => Err(StateError::ContextHasNoTracks)?,
Some(p) => p,
};
Expand Down Expand Up @@ -253,17 +253,6 @@ impl ConnectState {
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
9 changes: 3 additions & 6 deletions connect/src/state/tracks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,14 @@ impl<'ct> ConnectState {
}
}

pub fn prev_autoplay_track_uris(&self) -> Vec<String> {
pub fn recent_track_uris(&self) -> Vec<String> {
let mut prev = self
.prev_tracks()
.iter()
.flat_map(|t| t.is_autoplay().then_some(t.uri.clone()))
.map(|t| t.uri.clone())
.collect::<Vec<_>>();

if self.current_track(|t| t.is_autoplay()) {
prev.push(self.current_track(|t| t.uri.clone()));
}

prev.push(self.current_track(|t| t.uri.clone()));
prev
}

Expand Down

0 comments on commit 309ca8d

Please sign in to comment.