diff --git a/apps/api/src/ingest/service.ts b/apps/api/src/ingest/service.ts index 49c6b66..0a01def 100644 --- a/apps/api/src/ingest/service.ts +++ b/apps/api/src/ingest/service.ts @@ -400,10 +400,12 @@ export class IngestService { if (!requested) return undefined; const event = await this.deps.db.event.findFirst({ where: { id: requested, organizationId }, - select: { ingestFrom: true, ingestUntil: true }, + select: { ingestFrom: true, ingestUntil: true, archivedAt: true }, }); if (!event) return undefined; if (at < event.ingestFrom || at > event.ingestUntil) return undefined; + // Put away, and another open event covers this time (the windows overlap): the pin must not keep the next match. + if (event.archivedAt && (await this.routeToEvent(organizationId, userId, at))) return undefined; if (!(await this.sameSession(requested, userId, at))) return undefined; return requested; } diff --git a/apps/api/src/library/adopt.ts b/apps/api/src/library/adopt.ts index 087b54d..88583d4 100644 --- a/apps/api/src/library/adopt.ts +++ b/apps/api/src/library/adopt.ts @@ -18,6 +18,14 @@ export async function joinedEvent(db: Db, eventId: string, ids: string[]): Promi } if ((event.autopilot as { enabled?: boolean } | null)?.enabled === true) { await db.photo.updateMany({ where: { id: { in: ids }, status: "READY", source: { not: "CLOUD" }, autopilotStatus: "NONE" }, data: { autopilotStatus: "PENDING" } }); + // Already read on the event they left: decide them again here, without running the crop a second time. + await db.$executeRaw` + UPDATE photos + SET autopilot = (autopilot::jsonb - 'curated' - 'chosen' - 'gallery') + WHERE id = ANY(${ids}::uuid[]) + AND autopilot_status = 'DONE' + AND jsonb_typeof(autopilot::jsonb) = 'object' + `; } for (const id of ids) await applyRename(db, id); } diff --git a/apps/app/src/offline/local.ts b/apps/app/src/offline/local.ts index 797e237..1f334cd 100644 --- a/apps/app/src/offline/local.ts +++ b/apps/app/src/offline/local.ts @@ -105,8 +105,10 @@ export function eventForArrival(pinnedId: string | null, events: RoutedEvent[], if (!pinnedId) return routeLocally(events, at); const pinned = events.find((e) => e.id === pinnedId); if (!pinned) { - // Agenda cache miss: keep the open pin so USB/FTP does not dump live shots into Sem evento. - return pinnedId; + // Not in the open list: archived or deleted. Another open event that covers this time gets the photo. + // An empty list has not loaded yet — keep the pin so a live card is not dropped in the inbox. + const routed = events.length ? routeLocally(events, at) : null; + return routed ?? pinnedId; } if (pinned.archivedAt) return routeLocally(events, at); const t = Date.parse(at); diff --git a/apps/app/src/offline/offline.test.ts b/apps/app/src/offline/offline.test.ts index f365433..cf64e94 100644 --- a/apps/app/src/offline/offline.test.ts +++ b/apps/app/src/offline/offline.test.ts @@ -126,8 +126,10 @@ describe("photos arriving on this computer", () => { // No capture time: keep the pin (USB already filtered by the card clock; server keeps the named folder too). expect(eventForArrival("braga", events, null)).toBe("braga"); expect(eventForArrival(null, events, null)).toBeNull(); - // Cache miss for the pin id: keep it (do not dump into Sem evento); archived pins fall through to the clock. - expect(eventForArrival("missing", events, "2026-10-10T15:30:00Z")).toBe("missing"); + // A pin that is not in the open list was archived. An empty list has not loaded: keep the pin. + expect(eventForArrival("missing", events, "2026-10-10T15:30:00Z")).toBe("other"); + expect(eventForArrival("missing", [], "2026-10-10T15:30:00Z")).toBe("missing"); + expect(eventForArrival("missing", events, "2026-09-03T15:00:00Z")).toBe("missing"); expect(eventForArrival("braga", [{ ...events[0]!, archivedAt: "2026-10-10T00:00:00Z" }, events[1]!], "2026-10-10T15:30:00Z")).toBe("other"); });