diff --git a/client/src/sync/tripSyncManager.ts b/client/src/sync/tripSyncManager.ts index 6e2f3ecaf..888e57f99 100644 --- a/client/src/sync/tripSyncManager.ts +++ b/client/src/sync/tripSyncManager.ts @@ -441,30 +441,7 @@ export const tripSyncManager = { await cacheFilesForTrip(trip.id, files).catch(console.error) } - // 3) Map tiles — awaited, and only when the user opted to store them. The - // places go with every run: "prepared" has to mean the offline search - // works, and the tile switch is about tens of megabytes of imagery, not - // about the megabyte a trip's places cost. - { - const wantTiles = getOfflinePrefs().cacheTiles - const tileUrl = useSettingsStore.getState().settings.map_tile_url || undefined - const cartoKey = useSettingsStore.getState().settings.carto_api_key || undefined - i = 0 - for (const trip of prepared) { - if (!isAuthed()) return { status: 'skipped', reason: 'signed-out' } - // Reported only when there is a tile phase to report. The place - // prefetch rides along quietly, the way it always did — it is a - // megabyte, not the tens the progress bar exists for. - if (wantTiles) onProgress?.({ phase: 'tiles', current: ++i, total: prepared.length, label: trip.title }) - const places = await offlineDb.places.where('trip_id').equals(trip.id).toArray() - if (wantTiles) { - await prefetchTilesForTrip(trip.id, places, tileUrl, true, cartoKey).catch(console.error) - } - await prefetchPlacesForTrip(trip.id, places, true).catch(console.error) - } - } - - if (!isAuthed()) return { status: 'skipped', reason: 'signed-out' } + if (!(await prepareOfflineMaps(prepared, onProgress))) return { status: 'skipped', reason: 'signed-out' } onProgress?.({ phase: 'done', current: prepared.length, total: prepared.length }) return { status: 'done', trips: prepared.length } } finally { @@ -478,6 +455,27 @@ export const tripSyncManager = { }, } +// Download tiles only when requested, but always cache the places needed for offline search. +async function prepareOfflineMaps(trips: Trip[], onProgress?: (p: PrepareProgress) => void): Promise { + const wantTiles = getOfflinePrefs().cacheTiles + const tileUrl = useSettingsStore.getState().settings.map_tile_url || undefined + const cartoKey = useSettingsStore.getState().settings.carto_api_key || undefined + let i = 0 + for (const trip of trips) { + if (!isAuthed()) return false + // Reported only when there is a tile phase to report. The place + // prefetch rides along quietly, the way it always did — it is a + // megabyte, not the tens the progress bar exists for. + if (wantTiles) onProgress?.({ phase: 'tiles', current: ++i, total: trips.length, label: trip.title }) + const places = await offlineDb.places.where('trip_id').equals(trip.id).toArray() + if (wantTiles) { + await prefetchTilesForTrip(trip.id, places, tileUrl, true, cartoKey).catch(console.error) + } + await prefetchPlacesForTrip(trip.id, places, true).catch(console.error) + } + return isAuthed() +} + async function prepareOfflineUi(): Promise { // The trip bundle is unusable on iOS if WebKit cannot load the planner itself. if (!isAuthed() || !isNativeIos()) return diff --git a/server/src/nest/packing/packing.mcp.ts b/server/src/nest/packing/packing.mcp.ts index b4a44724d..75139538e 100644 --- a/server/src/nest/packing/packing.mcp.ts +++ b/server/src/nest/packing/packing.mcp.ts @@ -23,6 +23,7 @@ import { packingCreateBagRequestSchema, packingCreateItemRequestSchema, packingListItemsRequestSchema, + packingSetBringersRequestSchema, packingSetSharingRequestSchema, packingUpdateBagRequestSchema, packingUpdateItemRequestSchema, @@ -299,7 +300,7 @@ export class PackingMcp { inputSchema: { tripId: idSchema, itemId: idSchema, - user_ids: z.array(idSchema).describe('User IDs of the trip members who bring this item'), + ...packingSetBringersRequestSchema.shape, }, annotations: TOOL_ANNOTATIONS_WRITE, when: packingAddonOn, diff --git a/server/tests/integration/broadcast-parity/money.cases.ts b/server/tests/integration/broadcast-parity/money.cases.ts index c4dc96738..67cceae3a 100644 --- a/server/tests/integration/broadcast-parity/money.cases.ts +++ b/server/tests/integration/broadcast-parity/money.cases.ts @@ -178,6 +178,21 @@ export const money: CaseGroup = { }, expect: ['packing:deleted', { event: 'packing:created', only: 'viewers' }], }, + { + tool: 'set_packing_item_bringers', + needs: ['packingItem', 'member'], + args: (s) => ({ + tripId: s.trip.id, + itemId: s.packingItem.id, + user_ids: s.packingItem.owner_id ? [s.packingItem.owner_id, s.member.id] : [s.member.id], + }), + rest: { + method: 'post', + path: (s) => packing(s, '/' + s.packingItem.id + '/contributors'), + body: (s) => ({ user_id: s.member.id }), + }, + expect: ['packing:updated'], + }, { // The route used to save the order and tell nobody (G14). tool: 'reorder_packing_items', diff --git a/shared/src/packing/packing.schema.ts b/shared/src/packing/packing.schema.ts index ef7bb7803..ad20981e8 100644 --- a/shared/src/packing/packing.schema.ts +++ b/shared/src/packing/packing.schema.ts @@ -128,6 +128,10 @@ export const packingAddContributorRequestSchema = z.object({ }); export type PackingAddContributorRequest = z.infer; +export const packingSetBringersRequestSchema = z.object({ + user_ids: z.array(idSchema).describe('User IDs of the trip members who bring this item'), +}); + export const packingUpdateItemRequestSchema = z.object({ name: z.string().optional(), // The legacy route accepted both boolean and 0/1 for checked — both stay valid.