fix(web): prevent unrelated assets from appearing in tag view (#26816)

This commit is contained in:
Michel Heusschen
2026-03-10 17:43:30 +01:00
committed by GitHub
parent 56b8e1b8a9
commit 45eff1c663
5 changed files with 15 additions and 0 deletions

View File

@@ -286,6 +286,17 @@ describe('TimelineManager', () => {
expect(timelineManager.assetCount).toEqual(1);
});
it('ignores new assets that do not match the tag filter', async () => {
await timelineManager.updateOptions({ tagId: 'tag-1' });
const matching = deriveLocalDateTimeFromFileCreatedAt(timelineAssetFactory.build({ tags: ['tag-1'] }));
const unrelated = deriveLocalDateTimeFromFileCreatedAt(timelineAssetFactory.build({ tags: ['tag-2'] }));
timelineManager.upsertAssets([matching, unrelated]);
expect(await getAssets(timelineManager)).toEqual([matching]);
});
// disabled due to the wasm Justified Layout import
it('ignores trashed assets when isTrashed is true', async () => {
const asset = deriveLocalDateTimeFromFileCreatedAt(timelineAssetFactory.build({ isTrashed: false }));

View File

@@ -596,6 +596,7 @@ export class TimelineManager extends VirtualScrollManager {
isMismatched(this.#options.visibility, asset.visibility) ||
isMismatched(this.#options.isFavorite, asset.isFavorite) ||
isMismatched(this.#options.isTrashed, asset.isTrashed) ||
(this.#options.tagId && asset.tags && !asset.tags.includes(this.#options.tagId)) ||
(this.#options.assetFilter !== undefined && !this.#options.assetFilter.has(asset.id))
);
}

View File

@@ -18,6 +18,7 @@ export type Direction = 'earlier' | 'later';
export type TimelineAsset = {
id: string;
ownerId: string;
tags?: string[];
ratio: number;
thumbhash: string | null;
localDateTime: TimelineDateTime;

View File

@@ -170,6 +170,7 @@ export const toTimelineAsset = (unknownAsset: AssetResponseDto | TimelineAsset):
return {
id: assetResponse.id,
ownerId: assetResponse.ownerId,
tags: assetResponse.tags?.map((tag) => tag.id),
ratio,
thumbhash: assetResponse.thumbhash,
localDateTime,

View File

@@ -37,6 +37,7 @@ export const timelineAssetFactory = Sync.makeFactory<TimelineAsset>({
id: Sync.each(() => faker.string.uuid()),
ratio: Sync.each((i) => 0.2 + ((i * 0.618_034) % 3.8)), // deterministic random float between 0.2 and 4.0
ownerId: Sync.each(() => faker.string.uuid()),
tags: [],
thumbhash: Sync.each(() => faker.string.alphanumeric(28)),
localDateTime: Sync.each(() => fromISODateTimeUTCToObject(faker.date.past().toISOString())),
fileCreatedAt: Sync.each(() => fromISODateTimeUTCToObject(faker.date.past().toISOString())),