fix(stalker): merge late connection saves

This commit is contained in:
4gray committed 2026-08-09 18:01:13 +02:00
1 parent ffae919cc8
commit 37575c8d88
10 files changed
+202 -29

No files matched your search

@@ -115,7 +115,9 @@ describe('PlaylistInfoComponent', () => {
disableClose: false,
};
stalkerConnectionEditor = {
applyResolvedConnection: jest.fn().mockResolvedValue(undefined),
applyResolvedConnection: jest.fn(
async (playlist: PlaylistMeta) => playlist
),
resolveConnection: jest.fn(
async (updatedPlaylist: PlaylistMeta) => ({
status: STALKER_PLAYLIST_CONNECTION_EDITOR_STATUS.RESOLVED,
@@ -841,6 +843,14 @@ describe('PlaylistInfoComponent', () => {
stalkerSessionIdentity: 'new-fingerprint',
},
};
const currentPlaylist = {
...resolvedPlaylist,
title: 'Newer title',
epgUrls: ['https://new.example.com/epg.xml'],
};
stalkerConnectionEditor.applyResolvedConnection.mockResolvedValueOnce(
currentPlaylist
);
let finishDiscovery:
| ((value: {
status: 'resolved';
@@ -869,10 +879,12 @@ describe('PlaylistInfoComponent', () => {
expect(
stalkerConnectionEditor.applyResolvedConnection
).toHaveBeenCalledWith(resolvedPlaylist);
).toHaveBeenCalledWith(resolvedPlaylist, {
preserveCurrentMetadata: true,
});
expect(store.dispatch).toHaveBeenCalledWith(
PlaylistActions.updatePlaylistMeta({
playlist: resolvedPlaylist,
playlist: currentPlaylist,
persist: false,
})
);
@@ -891,6 +903,14 @@ describe('PlaylistInfoComponent', () => {
stalkerSessionIdentity: 'new-fingerprint',
},
};
const currentPlaylist = {
...resolvedPlaylist,
title: 'Newer title',
epgUrls: ['https://new.example.com/epg.xml'],
};
stalkerConnectionEditor.applyResolvedConnection.mockResolvedValueOnce(
currentPlaylist
);
let finishDiscovery:
| ((value: {
status: 'resolved';
@@ -919,10 +939,12 @@ describe('PlaylistInfoComponent', () => {
expect(
stalkerConnectionEditor.applyResolvedConnection
).toHaveBeenCalledWith(resolvedPlaylist);
).toHaveBeenCalledWith(resolvedPlaylist, {
preserveCurrentMetadata: true,
});
expect(store.dispatch).toHaveBeenCalledWith(
PlaylistActions.updatePlaylistMeta({
playlist: resolvedPlaylist,
playlist: currentPlaylist,
persist: false,
})
);
@@ -397,6 +397,7 @@ export class PlaylistInfoComponent {
}
let resolvedStalkerConnection = false;
let preserveCurrentMetadata = false;
let normalizedPlaylist: PlaylistMetaUpdate =
this.normalizeStalkerPlaylistMeta(
this.normalizeXtreamPlaylistMeta(submittedPlaylist)
@@ -425,6 +426,8 @@ export class PlaylistInfoComponent {
}
normalizedPlaylist = result.playlist;
resolvedStalkerConnection = true;
preserveCurrentMetadata =
this.dialogClosing || this.destroyRef.destroyed;
} else {
normalizedPlaylist = preserveStalkerConnection(
this.playlist,
@@ -443,9 +446,14 @@ export class PlaylistInfoComponent {
}
if (resolvedStalkerConnection) {
await this.stalkerConnectionEditor.applyResolvedConnection(
normalizedPlaylist
);
normalizedPlaylist = preserveCurrentMetadata
? await this.stalkerConnectionEditor.applyResolvedConnection(
normalizedPlaylist,
{ preserveCurrentMetadata: true }
)
: await this.stalkerConnectionEditor.applyResolvedConnection(
normalizedPlaylist
);
}
// Resolved Stalker edits cross an awaited, atomic persistence
@@ -34,12 +34,20 @@ interface StalkerPlaylistConnectionResultMap {
export type StalkerPlaylistConnectionResult =
StalkerPlaylistConnectionResultMap[keyof StalkerPlaylistConnectionResultMap];
export interface StalkerResolvedConnectionApplyOptions {
/** Merge only connection/session fields into the current persisted row. */
preserveCurrentMetadata?: boolean;
}
export interface StalkerPlaylistConnectionEditor {
resolveConnection(
playlist: PlaylistMeta
): Promise<StalkerPlaylistConnectionResult>;
/** Atomically persists a resolved edit, then synchronizes in-run state. */
applyResolvedConnection(playlist: PlaylistMetaUpdate): Promise<void>;
applyResolvedConnection(
playlist: PlaylistMetaUpdate,
options?: StalkerResolvedConnectionApplyOptions
): Promise<PlaylistMetaUpdate>;
}
export const STALKER_PLAYLIST_CONNECTION_EDITOR =