Repository navigation
Ask for Android's announcements, and let admins aim them - #103
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 exactlyGET /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> onlymarker 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
platformsas "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
watchcurrently reaches nobody. Not in scope here.Tests
Six: the wire check above, the platform name being one the server accepts,
platformsdecoding, an absentplatformsreading as "everyone" rather than "nobody" (the older-server case),[]reaching the wire on clear, and an untouched value being omitted.