connect: handle metadata correct

This commit is contained in:
Felix Prillwitz 2024-12-11 20:49:00 +01:00
parent d2f1dee43c
commit 673ded3d57
No known key found for this signature in database
GPG key ID: DE334B43606D1455
2 changed files with 15 additions and 5 deletions

View file

@ -202,6 +202,7 @@ impl ConnectState {
UpdateContext::Default => { UpdateContext::Default => {
let mut new_context = self.state_context_from_page( let mut new_context = self.state_context_from_page(
page, page,
context.metadata,
context.restrictions.take(), context.restrictions.take(),
Some(&context.uri), Some(&context.uri),
None, None,
@ -242,6 +243,7 @@ impl ConnectState {
UpdateContext::Autoplay => { UpdateContext::Autoplay => {
self.autoplay_context = Some(self.state_context_from_page( self.autoplay_context = Some(self.state_context_from_page(
page, page,
context.metadata,
context.restrictions.take(), context.restrictions.take(),
Some(&context.uri), Some(&context.uri),
Some(Provider::Autoplay), Some(Provider::Autoplay),
@ -275,6 +277,7 @@ impl ConnectState {
fn state_context_from_page( fn state_context_from_page(
&mut self, &mut self,
page: ContextPage, page: ContextPage,
metadata: HashMap<String, String>,
restrictions: Option<Restrictions>, restrictions: Option<Restrictions>,
new_context_uri: Option<&str>, new_context_uri: Option<&str>,
provider: Option<Provider>, provider: Option<Provider>,
@ -285,8 +288,12 @@ impl ConnectState {
.tracks .tracks
.iter() .iter()
.flat_map(|track| { .flat_map(|track| {
match self.context_to_provided_track(track, Some(new_context_uri), provider.clone()) match self.context_to_provided_track(
{ track,
Some(new_context_uri),
Some(&page.metadata),
provider.clone(),
) {
Ok(t) => Some(t), Ok(t) => Some(t),
Err(why) => { Err(why) => {
error!("couldn't convert {track:#?} into ProvidedTrack: {why}"); error!("couldn't convert {track:#?} into ProvidedTrack: {why}");
@ -299,7 +306,7 @@ impl ConnectState {
StateContext { StateContext {
tracks, tracks,
restrictions, restrictions,
metadata: page.metadata, metadata,
index: ContextIndex::new(), index: ContextIndex::new(),
} }
} }
@ -358,6 +365,7 @@ impl ConnectState {
&self, &self,
ctx_track: &ContextTrack, ctx_track: &ContextTrack,
context_uri: Option<&str>, context_uri: Option<&str>,
page_metadata: Option<&HashMap<String, String>>,
provider: Option<Provider>, provider: Option<Provider>,
) -> Result<ProvidedTrack, Error> { ) -> Result<ProvidedTrack, Error> {
let id = if !ctx_track.uri.is_empty() { let id = if !ctx_track.uri.is_empty() {
@ -388,7 +396,7 @@ impl ConnectState {
ctx_track.uid.to_string() ctx_track.uid.to_string()
}; };
let mut metadata = HashMap::new(); let mut metadata = page_metadata.cloned().unwrap_or_default();
for (k, v) in &ctx_track.metadata { for (k, v) in &ctx_track.metadata {
metadata.insert(k.to_string(), v.to_string()); metadata.insert(k.to_string(), v.to_string());
} }
@ -414,7 +422,7 @@ impl ConnectState {
} }
pub fn fill_context_from_page(&mut self, page: ContextPage) -> Result<(), Error> { pub fn fill_context_from_page(&mut self, page: ContextPage) -> Result<(), Error> {
let context = self.state_context_from_page(page, None, None, None); let context = self.state_context_from_page(page, HashMap::new(), None, None, None);
let ctx = self let ctx = self
.context .context
.as_mut() .as_mut()

View file

@ -21,6 +21,7 @@ impl ConnectState {
self.context_to_provided_track( self.context_to_provided_track(
track, track,
Some(&transfer.current_session.context.uri), Some(&transfer.current_session.context.uri),
None,
transfer.queue.is_playing_queue.then_some(Provider::Queue), transfer.queue.is_playing_queue.then_some(Provider::Queue),
) )
} }
@ -125,6 +126,7 @@ impl ConnectState {
if let Ok(queued_track) = self.context_to_provided_track( if let Ok(queued_track) = self.context_to_provided_track(
track, track,
Some(self.context_uri()), Some(self.context_uri()),
None,
Some(Provider::Queue), Some(Provider::Queue),
) { ) {
self.add_to_queue(queued_track, false); self.add_to_queue(queued_track, false);