Skip to content

Commit

Permalink
wrap suggested stream in resource loadable
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeastLT committed Nov 9, 2023
1 parent 92ef7dc commit 7f44760
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/models/meta_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct MetaDetails {
pub meta_items: Vec<ResourceLoadable<MetaItem>>,
pub meta_streams: Vec<ResourceLoadable<Vec<Stream>>>,
pub streams: Vec<ResourceLoadable<Vec<Stream>>>,
pub suggested_stream: Option<Stream>,
pub suggested_stream: Option<ResourceLoadable<Stream>>,
pub library_item: Option<LibraryItem>,
#[serde(skip_serializing)]
pub watched: Option<WatchedBitField>,
Expand Down Expand Up @@ -438,7 +438,7 @@ fn streams_update<E: Env + 'static>(
/// is that user might have played a stream from an addon which he no longer has due to some constrains (ie p2p addon),
/// that's why we have to try to find it first and verify that's it's still available.
fn suggested_stream_update(
suggested_stream: &mut Option<Stream>,
suggested_stream: &mut Option<ResourceLoadable<Stream>>,
selected: &Option<Selected>,
meta_items: &[ResourceLoadable<MetaItem>],
meta_streams: &[ResourceLoadable<Vec<Stream>>],
Expand Down Expand Up @@ -480,11 +480,7 @@ fn suggested_stream_update(
.iter()
.find(|resource| resource.request.base == stream_item.stream_transport_url)
.and_then(|resource| match &resource.content {
Some(Loadable::Ready(streams)) => Some(streams),
_ => None,
})
.and_then(|streams| {
streams
Some(Loadable::Ready(streams)) => streams
.iter()
.find(|stream| *stream == &stream_item.stream)
.or_else(|| {
Expand All @@ -497,7 +493,19 @@ fn suggested_stream_update(
.as_deref()
})
})
.cloned()
.map(|stream| ResourceLoadable {
request: resource.request.clone(),
content: Some(Loadable::Ready(stream.to_owned())),
}),
Some(Loadable::Loading) => Some(ResourceLoadable {
request: resource.request.clone(),
content: Some(Loadable::Loading),
}),
Some(Loadable::Err(error)) => Some(ResourceLoadable {
request: resource.request.clone(),
content: Some(Loadable::Err(error.clone())),
}),
_ => None,
})
})
}
Expand Down

0 comments on commit 7f44760

Please sign in to comment.