Skip to content

Commit 1c4ea8f

Browse files
committed
fix: home hubs showing watched items in certain cases
1 parent 3700979 commit 1c4ea8f

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

src/routes.rs

+56
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,65 @@ pub fn route() -> Router {
6767
async fn test(req: &mut Request, _depot: &mut Depot, res: &mut Response) {
6868
let params: PlexParams = req.extract().await.unwrap();
6969
let plex_client = PlexClient::from_request(req, params.clone());
70+
71+
// not sure anymore why i have this lol
72+
let content_directory_id_size =
73+
params.clone().content_directory_id.unwrap().len();
74+
if content_directory_id_size > usize::try_from(1).unwrap() {
75+
let upstream_res = plex_client.request(req).await.unwrap();
76+
let container = from_reqwest_response(upstream_res).await.unwrap();
77+
res.render(container);
78+
}
79+
80+
if params.clone().content_directory_id.unwrap()[0]
81+
!= params.clone().pinned_content_directory_id.unwrap()[0]
82+
{
83+
// We only fill the first one.
84+
let mut container: MediaContainerWrapper<MediaContainer> =
85+
MediaContainerWrapper::default();
86+
container.content_type =
87+
get_content_type_from_headers(req.headers_mut());
88+
container.media_container.size = Some(0);
89+
container.media_container.allow_sync = Some(true);
90+
container.media_container.identifier =
91+
Some("com.plexapp.plugins.library".to_string());
92+
return res.render(container);
93+
}
94+
95+
// first directory, load everything here because we wanna reemiiiixxx
96+
97+
for id in params.clone().content_directory_id.unwrap() {
98+
add_query_param_salvo(
99+
req,
100+
"contentDirectoryID".to_string(),
101+
id,
102+
);
103+
let u = plex_client.request(req).await.unwrap();
104+
let mut c: MediaContainerWrapper<MediaContainer> =
105+
from_reqwest_response(u).await.unwrap();
106+
}
107+
108+
// Hack, as the list could be smaller when removing watched items. So we request more.
109+
if let Some(original_count) = params.clone().count {
110+
add_query_param_salvo(
111+
req,
112+
"count".to_string(),
113+
(original_count * 2).to_string(),
114+
);
115+
}
116+
70117
let upstream_res = plex_client.request(req).await.unwrap();
71118
let mut container: MediaContainerWrapper<MediaContainer> =
72119
from_reqwest_response(upstream_res).await.unwrap();
120+
121+
TransformBuilder::new(plex_client, params.clone())
122+
.with_transform(HubStyleTransform)
123+
.with_transform(HubMixTransform)
124+
.with_transform(HubChildrenLimitTransform {
125+
limit: params.clone().count.unwrap(),
126+
})
127+
.apply_to(&mut container)
128+
.await;
73129
res.render(container);
74130
}
75131

src/transform.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -438,24 +438,20 @@ impl Transform for HubMixTransform {
438438
let mut new_hubs: Vec<MetaData> = vec![];
439439
// let mut library_section_id: Vec<Option<u32>> = vec![]; //librarySectionID
440440
for mut hub in item.children_mut() {
441-
let mut children = hub.children();
442441
if !config.include_watched {
443-
children.retain(|x| !x.is_watched());
442+
hub.children_mut().retain(|x| !x.is_watched());
444443
}
445444

446445
// we only process collection hubs
447446
if !hub.is_collection_hub() {
448-
hub.set_children(children);
449447
new_hubs.push(hub.to_owned());
450448
continue
451449
}
452450

453451
let p = new_hubs.iter().position(|v| v.title == hub.title);
454-
// dbg!(&hub.context);
455452
if hub.r#type != "clip" {
456453
hub.r#type = "mixed".to_string();
457454
}
458-
459455
match p {
460456
Some(v) => {
461457
new_hubs[v].key = merge_children_keys(
@@ -465,15 +461,13 @@ impl Transform for HubMixTransform {
465461
let c = new_hubs[v].children();
466462
new_hubs[v].set_children(
467463
c.into_iter()
468-
.interleave(children)
464+
.interleave(hub.children())
469465
.collect::<Vec<MetaData>>(),
470466
);
471467
}
472468
None => new_hubs.push(hub.to_owned()),
473469
}
474-
// dbg!(&new_hubs.get(0).unwrap().title);
475470
}
476-
// dbg!(&new_hubs.len());
477471
item.set_children_mut(&mut new_hubs);
478472
}
479473
}

0 commit comments

Comments
 (0)