fix(journey): the gallery runs in trip chronology instead of upload order (#2200)

journey_photos.sort_order is nothing but the insert counter, so photos added late landed behind days they belong before. Both gallery readers (the app and the shared journey) order by capture time now, falling back to the timestamp of the stop the photo belongs to and then to upload time, through one shared SQL fragment; ties keep the old order, so existing galleries only move where chronology demands it. The order inside an entry stays the user's manual arrangement.
This commit is contained in:
Maurice
2026-09-02 19:58:13 +02:00
committed by Maurice
parent b6a86275f6
commit 5d849ec292
5 changed files with 118 additions and 5 deletions
@@ -2059,6 +2059,55 @@ describe('journey gallery', () => {
const [gallery] = svc.uploadGalleryPhotos(journey.id, user.id, [{ path: 'journey/a.jpg' }]);
expect(svc.deleteGalleryPhoto(gallery.id, stranger.id)).toBeNull();
});
// #2200: the gallery used to come out in upload order, so pictures caught up
// with after the trip landed behind the ones added while it was running.
it('JOURNEY-SVC-PHOTO-008: the gallery reads in capture order, not upload order', () => {
const { user } = createUser(testDb);
const journey = svc.createJourney(user.id, { title: 'J' });
const shot = (path: string, takenAt: string) => {
const [row] = svc.uploadGalleryPhotos(journey.id, user.id, [{ path }]);
testDb.prepare('UPDATE trek_photos SET taken_at = ? WHERE id = ?').run(takenAt, row.photo_id);
};
shot('journey/day3.jpg', '2026-05-03T18:00:00.000Z');
shot('journey/day1.jpg', '2026-05-01T08:30:00.000Z');
shot('journey/day2.jpg', '2026-05-02T12:00:00.000Z');
const gallery = svc.getJourneyFull(journey.id, user.id)!.gallery as { file_path: string }[];
expect(gallery.map((p) => p.file_path)).toEqual([
'journey/day1.jpg',
'journey/day2.jpg',
'journey/day3.jpg',
]);
});
it('JOURNEY-SVC-PHOTO-009: a photo with no capture time rides on the date of the stop it hangs on', () => {
const { user } = createUser(testDb);
const journey = svc.createJourney(user.id, { title: 'J' });
const day1 = svc.createEntry(journey.id, user.id, { entry_date: '2026-05-01', title: 'Day 1' })!;
const day2 = svc.createEntry(journey.id, user.id, { entry_date: '2026-05-02', title: 'Day 2' })!;
// Day two was sorted out first and day one caught up afterwards, with the
// EXIF gone (an iPhone upload is converted before it leaves the browser).
const [dayTwoPhoto] = svc.uploadGalleryPhotos(journey.id, user.id, [{ path: 'journey/day2.jpg' }]);
const [dayOnePhoto] = svc.uploadGalleryPhotos(journey.id, user.id, [{ path: 'journey/day1.jpg' }]);
const [loose] = svc.uploadGalleryPhotos(journey.id, user.id, [{ path: 'journey/loose.jpg' }]);
svc.linkPhotoToEntry(day2.id, dayTwoPhoto.id, user.id);
svc.linkPhotoToEntry(day1.id, dayOnePhoto.id, user.id);
// Pin the loose photo's upload time so the run does not depend on today's date.
testDb
.prepare('UPDATE journey_photos SET created_at = ? WHERE id = ?')
.run(Date.parse('2026-06-01T00:00:00Z'), loose.id);
const gallery = svc.getJourneyFull(journey.id, user.id)!.gallery as { file_path: string }[];
expect(gallery.map((p) => p.file_path)).toEqual([
'journey/day1.jpg',
'journey/day2.jpg',
'journey/loose.jpg',
]);
});
});
describe('per-user journey preferences', () => {
@@ -635,6 +635,30 @@ describe('getPublicJourney', () => {
expect((result.entries[0] as Record<string, unknown>).photos).toEqual([]); // inline photos withheld too
});
// #2200: the reader of a shared journey gets the same chronology as the owner,
// so the public gallery cannot fall back to upload order.
it('JOURNEY-SHARE-031: the public gallery reads in capture order, not upload order', () => {
const { user } = createUser(testDb);
const journey = createJourney(testDb, user.id);
const day1 = createJourneyEntry(testDb, journey.id, user.id, {
type: 'entry', title: 'Day 1', entry_date: '2026-05-01',
});
const day2 = createJourneyEntry(testDb, journey.id, user.id, {
type: 'entry', title: 'Day 2', entry_date: '2026-05-02',
});
const late = insertJourneyPhoto(day2.id, { filePath: '/photos/day2.jpg' });
insertJourneyPhoto(day1.id, { filePath: '/photos/day1.jpg' });
testDb.prepare('UPDATE trek_photos SET taken_at = ? WHERE id = ?').run('2026-05-02T16:00:00.000Z', late);
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
share_timeline: true, share_gallery: true, share_map: true,
});
const gallery = svc.getPublicJourney(token)!.gallery as Record<string, unknown>[];
expect(gallery.map(p => p.file_path)).toEqual(['/photos/day1.jpg', '/photos/day2.jpg']);
});
it('JOURNEY-SHARE-030: cartoApiKey resolves owner setting → admin instance default → empty (#2054)', () => {
const { user } = createUser(testDb);
const journey = createJourney(testDb, user.id);