fix(playlists): update timestamp of recently viewed items

This commit is contained in:
4gray committed 2026-02-16 22:16:12 +01:00
1 parent 52a618fd0f
commit 0623baa4b7
2 files changed
+49 -7

No files matched your search

@@ -62,15 +62,37 @@ export const withRecentItems = function () {
pipe(
switchMap(async ({ contentId, playlist }) => {
// contentId is actually xtream_id, need to look up the database content.id
const playlistId = playlist().id;
const content = await dbService.getContentByXtreamId(
contentId,
playlist().id
playlistId
);
if (content) {
await dbService.addRecentItem(
content.id,
playlist().id
playlistId
);
// Reload after add/update so re-watched items
// immediately move to the top in recently-viewed.
const items =
await dbService.getRecentItems(playlistId);
patchState(store, {
recentItems: items.map((item) => ({
id: item.id,
title: item.title,
type: item.type as
| 'live'
| 'movie'
| 'series',
poster_url: item.poster_url,
content_id: item.id,
playlist_id: playlistId,
viewed_at: item.viewed_at || '',
xtream_id: item.xtream_id,
category_id: item.category_id,
})),
});
}
})
)
+25 -5
View File
@@ -9,7 +9,7 @@ import {
createPlaylistObject,
} from 'm3u-utils';
import { NgxIndexedDBService } from 'ngx-indexed-db';
import { combineLatest, EMPTY, map, switchMap } from 'rxjs';
import { combineLatest, map, switchMap } from 'rxjs';
import {
Channel,
DbStores,
@@ -397,14 +397,34 @@ export class PlaylistsService {
}
return this.getPlaylistById(portalId).pipe(
switchMap((portal) => {
// Check if item already exists in recently viewed
if (portal.recentlyViewed?.some((i: any) => i.id === item.id)) {
return EMPTY;
const nowIso = new Date().toISOString();
const recentItems = portal.recentlyViewed ?? [];
const existingIndex = recentItems.findIndex(
(i: any) => String(i?.id) === String(item.id)
);
if (existingIndex >= 0) {
const updatedRecentItems = [...recentItems];
updatedRecentItems[existingIndex] = {
...updatedRecentItems[existingIndex],
...item,
added_at: nowIso,
};
return this.dbService.update(DbStores.Playlists, {
...portal,
recentlyViewed: updatedRecentItems,
});
}
return this.dbService.update(DbStores.Playlists, {
...portal,
recentlyViewed: [...(portal.recentlyViewed ?? []), item],
recentlyViewed: [
...recentItems,
{
...item,
added_at: (item as any).added_at ?? nowIso,
},
],
});
})
);