feat(journey): let a shared journey read newest-first

A journey shared while the trip is still running is read like a blog: the family
following along wants the latest entry at the top, not to scroll past three weeks
to find it (#1614). The owner sets it per share link, because it is a property of
how the link is meant to be read rather than of the journey, and the reader can
flip it either way.

Off by default, so an already-published link does not reorder itself under its
readers.

Only the reading order changes. Day colours and stop numbers stay chronological,
so the timeline still matches the map when the feed is upside down — which is why
the day index is looked up rather than taken from the render loop. Reuses
memories.newest/oldest, already translated in all 23 locales.
This commit is contained in:
Maurice
2026-08-18 20:41:24 +02:00
committed by Maurice
parent e809808572
commit 11686be264
7 changed files with 85 additions and 6 deletions
+11
View File
@@ -3970,6 +3970,17 @@ function runMigrations(db: Database.Database): void {
// Answering "which photos of this journey have coordinates" without a scan.
db.exec('CREATE INDEX IF NOT EXISTS idx_trek_photos_geo ON trek_photos(lat, lng) WHERE lat IS NOT NULL AND lng IS NOT NULL');
},
// A journey shared while the trip is still running reads like a blog, and a
// blog puts the newest entry first (#1614). The owner decides per share link,
// because it is a property of how the link is meant to be read, not of the
// journey. Off by default: an already-published link must not reorder itself
// under its readers.
() => {
const cols = db.prepare("SELECT name FROM pragma_table_info('journey_share_tokens')").all() as Array<{ name: string }>;
if (!cols.some(c => c.name === 'newest_first')) {
db.exec('ALTER TABLE journey_share_tokens ADD COLUMN newest_first INTEGER NOT NULL DEFAULT 0');
}
},
];
if (currentVersion < migrations.length) {
@@ -7,6 +7,8 @@ interface JourneySharePermissions {
share_timeline?: boolean;
share_gallery?: boolean;
share_map?: boolean;
/** Read the journey newest-first, like a blog, rather than in trip order. */
newest_first?: boolean;
}
interface JourneyShareTokenInfo {
@@ -15,6 +17,7 @@ interface JourneyShareTokenInfo {
share_timeline: boolean;
share_gallery: boolean;
share_map: boolean;
newest_first: boolean;
}
/**
@@ -45,18 +48,19 @@ export class JourneyShareService {
share_timeline = true,
share_gallery = true,
share_map = true,
newest_first = false,
} = permissions;
const existing = this.db.prepare('SELECT token FROM journey_share_tokens WHERE journey_id = ?').get(journeyId) as { token: string } | undefined;
if (existing) {
this.db.prepare('UPDATE journey_share_tokens SET share_timeline = ?, share_gallery = ?, share_map = ? WHERE journey_id = ?')
.run(share_timeline ? 1 : 0, share_gallery ? 1 : 0, share_map ? 1 : 0, journeyId);
this.db.prepare('UPDATE journey_share_tokens SET share_timeline = ?, share_gallery = ?, share_map = ?, newest_first = ? WHERE journey_id = ?')
.run(share_timeline ? 1 : 0, share_gallery ? 1 : 0, share_map ? 1 : 0, newest_first ? 1 : 0, journeyId);
return { token: existing.token, created: false };
}
const token = crypto.randomBytes(24).toString('base64url');
this.db.prepare('INSERT INTO journey_share_tokens (journey_id, token, created_by, share_timeline, share_gallery, share_map) VALUES (?, ?, ?, ?, ?, ?)')
.run(journeyId, token, createdBy, share_timeline ? 1 : 0, share_gallery ? 1 : 0, share_map ? 1 : 0);
this.db.prepare('INSERT INTO journey_share_tokens (journey_id, token, created_by, share_timeline, share_gallery, share_map, newest_first) VALUES (?, ?, ?, ?, ?, ?, ?)')
.run(journeyId, token, createdBy, share_timeline ? 1 : 0, share_gallery ? 1 : 0, share_map ? 1 : 0, newest_first ? 1 : 0);
return { token, created: true };
}
@@ -69,6 +73,7 @@ export class JourneyShareService {
share_timeline: !!row.share_timeline,
share_gallery: !!row.share_gallery,
share_map: !!row.share_map,
newest_first: !!row.newest_first,
};
}
@@ -219,6 +224,7 @@ export class JourneyShareService {
share_timeline: shareTimeline,
share_gallery: shareGallery,
share_map: shareMap,
newest_first: !!row.newest_first,
},
};
}