Skip to content

feat: switch notification types off per car - #774

Open
arthur-lzrs wants to merge 1 commit into
joszz:mainfrom
arthur-lzrs:feat/per-car-notification-types
Open

arthur-lzrs wants to merge 1 commit into
joszz:mainfrom
arthur-lzrs:feat/per-car-notification-types

Conversation

@arthur-lzrs

Copy link
Copy Markdown
Contributor

Summary

A device can switch a notification type off, but only for every car at once. On an account with two cars there is no way to mute, say, "door left open" for one car and keep it for the other.

With two or more cars, a Car picker above the type checklist (Settings > Notifications) now chooses whether the list is for all cars or for one:

  • A type switched off for one car stays on for the others.
  • A type switched off for all cars stays off for every car. A car's own list shows that row locked, with "Off for all cars" under it.
  • The list for all cars offers every type any car can produce; a car's own list offers the types that car can (a BEV gets no low-fuel row).
  • The summaries are still asked for once, for the device, and can then be switched off for one car.
  • A notification that names no car (the MG sign-in failing is the only one) answers to the list for all cars alone, so a car's list does not offer it.
  • Like the rest of the checklist the choice is kept per device. The push the Worker sends, the bell and the browser notifications all follow it.
  • With one car nothing changes.

How it works

  • Backend: PushSubscription.ExcludedCategoriesByVehicle, a jsonb column keyed by vehicle id. One additive migration, default {}, so rows from before want everything for every car. POST /api/push/subscribe takes an optional excludedCategoriesByVehicle; left out, it keeps what is stored, so an older page changes nothing. VehicleCategoryExclusions.Normalize keeps known types only, once each, in one order, for at most 32 cars, so an unchanged choice compares equal and a registration that changes nothing writes nothing. NotificationCategories.IsWanted takes the car's list as a fourth, optional argument, and PushSenderService passes the one for the notification's vehicle.
  • Frontend: notificationTypeExclusionsByVehicle in the UI settings (local to the device, like the other two lists), sent with every push registration. isCategoryShown and vehicleExclusionsOf carry the same rule as the server.

Type of Change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation
  • Dependency update
  • Other

Related Issues

None.

How it was tested

  • Unit tests on both sides, plus Postgres tests for the jsonb column (round trip, the same choice in another order writes nothing, a row without the column's value reads as no exclusions).
  • Demo mode with DEMO_SECOND_VEHICLE=true, in the browser, down to 320 px wide.
  • On a real account with two cars, on an iPhone, over a day: with a type switched off for one car, its pushes stopped and the other car's kept arriving.
  • The migration was applied to a copy of that database, then the previous release was started on the migrated copy: it starts normally, so going back needs no restore.

Notes for review

  • One behaviour change for accounts with several cars: the list for all cars used to offer the types of the active car only (a BEV's list had no low-fuel row even with a hybrid on the account). It now offers every type any car can produce.
  • Translations: the four new strings in nl, es and pt-PT are my own drafts, so a native check is welcome. pt (Brazilian) is checked by a native speaker.
  • A flaky test, not related: UserSettingsRepositoryPostgresTests.SavesAtTheSameMoment_KeepEveryDevicesKeys (eight concurrent saves) failed once for me when the whole suite ran under load, and passed six times in a row on its own.
  • The Worker does not log a push it sent or left out, only failures, so the filter is not visible in the logs. I left that as it is.

Checklist

  • Tests added or updated
  • Checks pass: pnpm check in frontend/, and dotnet test --project src/GarageStack.Tests plus dotnet format GarageStack.slnx --verify-no-changes at the root
  • Commit messages follow Conventional Commits (feat: ..., fix(frontend): ...)
  • If trips changed (ITripRepository): done in the demo too, with a step in TripRepositoryContractTests (not applicable)
  • If the API changed: the rewritten documentation/openapi.json is committed
  • New fields or features have demo data in src/GarageStack.Data/Demo/ (no new data needed: the demo already has notifications for both cars, and the picker shows with DEMO_SECOND_VEHICLE=true)
  • No secrets or personal data committed, and no real VIN or licence plate in test data
  • Responsive on mobile, down to 320 px wide
  • Every new UI text is an i18n key, in every file in frontend/src/locales/
  • If unraid/garagestack.xml changed: synced to joszz/unraid-community-apps after merge (not applicable, it did not change)

A device could only switch a notification type off for every car at once, so on an account
with two cars there was no way to mute, say, "door left open" for one car and keep it for the
other.

With two or more cars, a Car picker above the type checklist now chooses whether the list is
for all cars or for one. A type switched off for one car stays on for the others, and a type
switched off for all cars stays off for every car; a car's own list shows that row locked. The
list for all cars offers every type any car can produce, a car's own list the types that car
can. The choice is kept per device, like the rest of the checklist, and the bell and the
browser notifications follow it too. A notification that names no car (the MG sign-in failing)
answers to the list for all cars alone, so a car's list does not offer it.

Backend: PushSubscription gets ExcludedCategoriesByVehicle, a jsonb column keyed by vehicle id
(one additive migration, default {}). POST /api/push/subscribe takes the new optional
excludedCategoriesByVehicle; left out, it keeps what is stored, so a page that predates it
changes nothing. The values go through VehicleCategoryExclusions.Normalize (known types only,
once each, in one order, at most 32 cars), so an unchanged choice compares equal and a
registration that changes nothing writes nothing. NotificationCategories.IsWanted takes the
car's list as a fourth argument, and PushSenderService passes the one for the notification's
vehicle.

Frontend: notificationTypeExclusionsByVehicle in the UI settings, local to the device like the
other two lists, sent with every push registration. isCategoryShown and vehicleExclusionsOf
carry the same rule as the server.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant