From 893e9e0ae68384800cbdaf051f2f5ebd45132ad9 Mon Sep 17 00:00:00 2001 From: MemeCornucopia <148788549+MemeCornucopia@users.noreply.github.com> Date: Tue, 30 Jan 2024 17:12:14 -0500 Subject: [PATCH 1/3] Fixed Sorting --- src/backend/accounts/user.ts | 44 +++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/backend/accounts/user.ts b/src/backend/accounts/user.ts index aaa1b227..cd701395 100644 --- a/src/backend/accounts/user.ts +++ b/src/backend/accounts/user.ts @@ -87,6 +87,11 @@ export function progressResponsesToEntries(responses: ProgressResponse[]) { } const item = items[v.tmdbId]; + // Update the item only if the new update is more recent than the current one + if (new Date(v.updatedAt).getTime() > item.updatedAt) { + item.updatedAt = new Date(v.updatedAt).getTime(); + } + if (item.type === "movie") { item.progress = { duration: Number(v.duration), @@ -95,22 +100,29 @@ export function progressResponsesToEntries(responses: ProgressResponse[]) { } if (item.type === "show" && v.season.id && v.episode.id) { - item.seasons[v.season.id] = { - id: v.season.id, - number: v.season.number ?? 0, - title: "", - }; - item.episodes[v.episode.id] = { - id: v.episode.id, - number: v.episode.number ?? 0, - title: "", - progress: { - duration: Number(v.duration), - watched: Number(v.watched), - }, - seasonId: v.season.id, - updatedAt: new Date(v.updatedAt).getTime(), - }; + if ( + !item.seasons[v.season.id] || + (item.episodes[v.episode.id] && + new Date(v.updatedAt).getTime() > + item.episodes[v.episode.id].updatedAt) + ) { + item.seasons[v.season.id] = { + id: v.season.id, + number: v.season.number ?? 0, + title: "", + }; + item.episodes[v.episode.id] = { + id: v.episode.id, + number: v.episode.number ?? 0, + title: "", + progress: { + duration: Number(v.duration), + watched: Number(v.watched), + }, + seasonId: v.season.id, + updatedAt: new Date(v.updatedAt).getTime(), + }; + } } }); From 55bb3c4574a4d1761966cecbfc5220aa01453d36 Mon Sep 17 00:00:00 2001 From: MemeCornucopia <148788549+MemeCornucopia@users.noreply.github.com> Date: Tue, 30 Jan 2024 17:33:00 -0500 Subject: [PATCH 2/3] Fixed a mistake I made. --- src/backend/accounts/user.ts | 39 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/backend/accounts/user.ts b/src/backend/accounts/user.ts index cd701395..a6208d30 100644 --- a/src/backend/accounts/user.ts +++ b/src/backend/accounts/user.ts @@ -100,29 +100,22 @@ export function progressResponsesToEntries(responses: ProgressResponse[]) { } if (item.type === "show" && v.season.id && v.episode.id) { - if ( - !item.seasons[v.season.id] || - (item.episodes[v.episode.id] && - new Date(v.updatedAt).getTime() > - item.episodes[v.episode.id].updatedAt) - ) { - item.seasons[v.season.id] = { - id: v.season.id, - number: v.season.number ?? 0, - title: "", - }; - item.episodes[v.episode.id] = { - id: v.episode.id, - number: v.episode.number ?? 0, - title: "", - progress: { - duration: Number(v.duration), - watched: Number(v.watched), - }, - seasonId: v.season.id, - updatedAt: new Date(v.updatedAt).getTime(), - }; - } + item.seasons[v.season.id] = { + id: v.season.id, + number: v.season.number ?? 0, + title: "", + }; + item.episodes[v.episode.id] = { + id: v.episode.id, + number: v.episode.number ?? 0, + title: "", + progress: { + duration: Number(v.duration), + watched: Number(v.watched), + }, + seasonId: v.season.id, + updatedAt: new Date(v.updatedAt).getTime(), + }; } }); From 22358112d337dff77623a9976f55ed8a8a32c1a5 Mon Sep 17 00:00:00 2001 From: MemeCornucopia <148788549+MemeCornucopia@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:13:11 -0500 Subject: [PATCH 3/3] Update src/backend/accounts/user.ts Co-authored-by: William Oldham --- src/backend/accounts/user.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/accounts/user.ts b/src/backend/accounts/user.ts index a6208d30..4708dd2b 100644 --- a/src/backend/accounts/user.ts +++ b/src/backend/accounts/user.ts @@ -87,7 +87,9 @@ export function progressResponsesToEntries(responses: ProgressResponse[]) { } const item = items[v.tmdbId]; - // Update the item only if the new update is more recent than the current one + + // Since each watched episode is a single array entry but with the same tmdbId, the root item updatedAt will only have the first episode's timestamp (which is not the newest). + // Here, we are setting it explicitly so the updatedAt always has the highest updatedAt from the episodes. if (new Date(v.updatedAt).getTime() > item.updatedAt) { item.updatedAt = new Date(v.updatedAt).getTime(); }