Skip to content

Ask for Android's announcements, and let admins aim them - #103

Merged
SiteRelEnby merged 1 commit into
mainfrom
feat/announcement-platform-targeting
Oct 14, 2026
Merged

SiteRelEnby merged 1 commit into
mainfrom
feat/announcement-platform-targeting

Conversation

@SiteRelEnby

Copy link
Copy Markdown
Collaborator

Backend PR #359 lets an announcement be aimed at particular clients, filtering on a ?platform= the client supplies. This is the Android side.

Naming ourselves

The filter is: untargeted announcements always, plus targeted ones whose list overlaps what the client named. A client that names nothing gets the untargeted set only. That is the right default for builds that predate this, but it means this app would silently never show an announcement written for it, with nothing anywhere saying why.

getAnnouncements() now sends ?platform=android - the same name the app already calls itself in its client header, and one of the four the server knows.

The default lives on the interface rather than at the call site, so a later caller cannot forget it.

Verified with a real request

Not by reading the annotation back. The platform is a Kotlin default argument on a Retrofit interface, which reaches the proxy through a synthetic method, and a default that failed to apply would look like nothing going wrong at all - no error, just an announcement that never arrives.

The test stands up a bare ServerSocket, makes the call, and asserts the request line is exactly GET /v1/announcements?platform=android. A socket rather than MockWebServer so it costs no new dependency; all it has to do is read one line and answer []. I checked it fails when the parameter is removed rather than trusting that a passing test proves something.

The admin half

Android's admin panel can already write announcements, so without this it could be targeted but not set targeting - and editing an announcement from the phone would have been the only way to touch one without seeing that it was aimed somewhere.

It now has a "Show on" section with the four platforms, a line saying who will see it, and a <platforms> only marker on targeted rows, matching the web admin page. Nothing ticked means everyone, which is both the server's default and what every existing announcement means.

The update path always sends the list rather than omitting it when empty. The server reads an omitted platforms as "leave it alone", so unticking every box had to put [] on the wire or the old targeting would quietly survive a save that looked like it removed it. That is pinned by a test, as is the inverse: an untouched targeting stays out of the patch entirely.

The watch

Deliberately not claimed. The Wear app is its own client and would name itself, so the phone collecting watch-targeted announcements on its behalf would be wrong.

The Wear app does not read announcements at all today, so an announcement aimed at watch currently reaches nobody. Not in scope here.

Tests

Six: the wire check above, the platform name being one the server accepts, platforms decoding, an absent platforms reading as "everyone" rather than "nobody" (the older-server case), [] reaching the wire on clear, and an untouched value being omitted.

The server can now aim an announcement at particular clients, and
filters on a ?platform= the client supplies. A client that names nothing
gets the untargeted set only, which is the safe default for old builds
but means this app would silently never show an announcement written for
it. The fetch now names android, the same thing the app already calls
itself in its client header.

Defaulted on the interface rather than at the call site so a later
caller cannot forget it, and verified with a real request rather than by
reading the annotation back: the platform is a Kotlin default argument
on a Retrofit interface, which reaches the proxy through a synthetic
method, and a default that failed to apply would look like nothing at
all going wrong.

The admin editor gains the other half, since it can already write
announcements and would otherwise be able to receive targeting but not
set it. A "Show on" section with the four platforms, a line saying who
will see it, and a "<platforms> only" marker on targeted rows, matching
the web admin page. Nothing ticked means everyone, which is both the
server default and what every existing announcement means.

The update path always sends the list rather than omitting it when
empty: the server reads an omitted platforms as "leave it alone", so
unticking every box had to put [] on the wire or the old targeting would
quietly survive a save that looked like it removed it.

The watch is deliberately not claimed here. The Wear app is its own
client and would name itself; it does not read announcements at all
today, so an announcement aimed at the watch currently reaches nobody
from this repo.
@SiteRelEnby
SiteRelEnby merged commit 8dbed23 into main Oct 14, 2026
1 check passed
@SiteRelEnby
SiteRelEnby deleted the feat/announcement-platform-targeting branch October 14, 2026 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant