fix(pwa): align xtream recent clearing

This commit is contained in:
4gray committed 2026-05-21 19:45:07 +03:00
1 parent d1e057887f
commit 9097ff5bc1
4 files changed
+37 -17

No files matched your search

@@ -403,13 +403,17 @@ describe('UnifiedRecentDataService', () => {
value: undefined,
configurable: true,
});
playlistsService.getAllPlaylists.mockReturnValue(
store.select.mockReturnValue(
of([
{
_id: 'xtream-1',
title: 'Xtream PWA',
serverUrl: 'https://xtream.example.com',
},
} satisfies Partial<PlaylistMeta>,
])
);
playlistsService.getAllPlaylists.mockReturnValue(
of([
{
_id: 'm3u-1',
title: 'M3U List',
@@ -191,6 +191,16 @@ export class UnifiedRecentDataService {
if (window.electron) {
await this.dbService.clearGlobalRecentlyViewed();
} else {
const allMeta = await this.getAllMeta();
await Promise.all(
allMeta
.filter((playlist) => playlist._id)
.filter((playlist) => this.isXtreamPlaylist(playlist))
.map((playlist) =>
this.xtreamDataSource.clearRecentItems(playlist._id)
)
);
}
const playlists = (await firstValueFrom(
this.playlistsService.getAllPlaylists()
@@ -198,10 +208,6 @@ export class UnifiedRecentDataService {
await Promise.all(
playlists.map(async (playlist) => {
if (!window.electron && this.isXtreamPlaylist(playlist)) {
await this.xtreamDataSource.clearRecentItems(playlist._id);
}
if (this.isPlaylistBackedRecentPlaylist(playlist)) {
const updatedPlaylist = await firstValueFrom(
this.playlistsService.clearPlaylistRecentlyViewed(
@@ -335,4 +335,21 @@ describe('withRecentItems', () => {
}),
]);
});
it('removes recent items through the active data source in Electron mode', async () => {
store.removeRecentItem({ itemId: 3941697, playlistId: 'playlist-1' });
await new Promise((resolve) => setTimeout(resolve, 0));
expect(dataSource.removeRecentItem).toHaveBeenCalledWith(
3941697,
'playlist-1'
);
expect(databaseService.removeRecentItem).not.toHaveBeenCalled();
expect(store.recentItems()).toEqual([
expect.objectContaining({
id: 3941697,
title: 'Krypton',
}),
]);
});
});
@@ -195,17 +195,10 @@ export const withRecentItems = function () {
}>(
pipe(
switchMap(async ({ itemId, playlistId }) => {
if (window.electron) {
await dbService.removeRecentItem(
itemId,
playlistId
);
} else {
await dataSource.removeRecentItem(
itemId,
playlistId
);
}
await dataSource.removeRecentItem(
itemId,
playlistId
);
// Reload recent items to update UI
const items =
await dataSource.getRecentItems(playlistId);