neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
docs/android.md: plan for the Android client and its /api/v1
339eba2 · gmorell · 2026-12-03 01:09
Files changed
added
docs/android.md
+215
−0
@@ -0,0 +1,215 @@
| 1 | +# Android app — plan | |
| 2 | + | |
| 3 | +A native client for recourse, in the same family as the sibling apps. The | |
| 4 | +shape of this doc is `../party-slut/docs/android.md`, the newest family plan. | |
| 5 | +Where it is silent, do what `../movie_monster/android` (the newest app, and the | |
| 6 | +one whose pairing flow this copies) and `../pin_flip/android` do. The server | |
| 7 | +half follows `../rosin_hunter_3000`: a bearer-only `/api/v1` nest with its own | |
| 8 | +JSON-401 middleware. | |
| 9 | + | |
| 10 | +Status: built (§6). §8 says where the result differs from the plan below, | |
| 11 | +which is otherwise kept as it was written. | |
| 12 | + | |
| 13 | +## 1. Goals | |
| 14 | + | |
| 15 | +Reading and writing a forum on a phone, with the web's rules: | |
| 16 | + | |
| 17 | +- **Browse** categories as the web does, in either layout, honouring the | |
| 18 | + account's **Layout** preference from the API (`preferred_view`): | |
| 19 | + - **Classic** — the category tree, then a topic list per category. | |
| 20 | + - **Focus** — a rail of categories across the top and the selected | |
| 21 | + category's topics as tiles; opening one reads it full screen, and a | |
| 22 | + sideways swipe steps to the previous/next topic in the tile order, the | |
| 23 | + phone's version of the web filmstrip and its arrow keys. | |
| 24 | +- **Read** a topic: posts rendered from the server's own markdown output, | |
| 25 | + tags, reactions, who posted. Reading marks it read and counts a view by | |
| 26 | + exactly the web's rules (§2a). | |
| 27 | +- **Write**: reply, start a topic (with tags), react, bookmark, watch a | |
| 28 | + category, edit a topic's tags where the web allows it. | |
| 29 | +- **Find**: tags (index and per tag), search, bookmarks, notifications | |
| 30 | + (mark one / all read). | |
| 31 | +- **Profile**: avatar (upload / remove), Layout, default sort, reaction | |
| 32 | + notifications, devices; unpair this phone. | |
| 33 | +- **Email verification**: an unverified account (when the server requires | |
| 34 | + verification) is read-only in the app exactly as on the web — write controls | |
| 35 | + hidden, a banner saying why, and a *Resend* button. | |
| 36 | + | |
| 37 | +Out of scope: everything under `/admin` and the `manage` CLI (categories, | |
| 38 | +reaction types, invites, users) stays web/CLI; editing and deleting posts | |
| 39 | +(the web keeps it; the app links out); sign-up; iOS; offline reading. | |
| 40 | + | |
| 41 | +## 2. What the server has today, and what it needs | |
| 42 | + | |
| 43 | +Every page is server-rendered minijinja + htmx behind a cookie session. There | |
| 44 | +is an `api_tokens` table (plaintext tokens), a `/api-tokens` page that mints | |
| 45 | +them, and `/api/profile` behind a middleware that takes either a bearer token | |
| 46 | +or the cookie. There is no JSON API beyond that one call. | |
| 47 | + | |
| 48 | +### 2a. `/api/v1` | |
| 49 | + | |
| 50 | +`.nest("/api/v1", api::router(state))`, the router built in the library | |
| 51 | +(`src/api/mod.rs`) so tests drive the real thing. Its own middleware is | |
| 52 | +bearer-only and answers 401 as JSON — `rosin_hunter_3000`'s | |
| 53 | +`api_auth_middleware`: a cookie must not authorize a cross-origin JSON API | |
| 54 | +with no CSRF protection of its own. The legacy `/api/profile` is left alone. | |
| 55 | + | |
| 56 | +Conventions (party-slut §2a, which kept bigtrippr's): | |
| 57 | + | |
| 58 | +- snake_case keys, ISO-8601 UTC instants, UUIDv7 ids. | |
| 59 | +- One error envelope: `{"error": {"code", "message", "details"}}`. | |
| 60 | +- `User-Agent: Recourse-Android/<versionName>`. | |
| 61 | +- Anything the viewer can't see is a `404`, whether or not it exists. | |
| 62 | +- Permission flags (`may_write`, `can_reply`, `can_edit_tags`, …) are | |
| 63 | + computed by the server; the app only shows or hides. | |
| 64 | +- Handlers are thin. Visibility (`CategoryTree::can_view` / | |
| 65 | + `visible_category_ids` with the viewer's trust level and staff flag), | |
| 66 | + min-trust tag minting, the verification gate (`may_write`), the view | |
| 67 | + throttle and read tracking (`record_topic_view`), the sort preference | |
| 68 | + (`resolve_sort`) and the listings (`category_topics`, `decorate`, | |
| 69 | + `visible_tags`, search) are the functions the web handlers call. Writes that | |
| 70 | + are more than one row — new topic, reply, tags, reaction, bookmark, watch, | |
| 71 | + preferences, avatar — move into `src/actions.rs` and the web handlers are | |
| 72 | + changed to call them too (party-slut §8, "one place for follow-on work"). | |
| 73 | + | |
| 74 | +Endpoints, mapped from the web routes (full list in `docs/api.md`): | |
| 75 | + | |
| 76 | +| Area | Endpoints | | |
| 77 | +|---|---| | |
| 78 | +| Me | `GET me`, `PATCH me` (layout, sort, reaction notifications), `PUT/DELETE me/avatar`, `POST me/verification` (resend) | | |
| 79 | +| Devices | `GET me/devices`, `DELETE me/devices/{id}`, `DELETE sessions/current` | | |
| 80 | +| Browse | `GET categories`, `GET categories/{slug}?sort=`, `PUT categories/{slug}/watch` | | |
| 81 | +| Topics | `GET topics/{id}`, `POST categories/{slug}/topics`, `POST topics/{id}/posts`, `PUT topics/{id}/tags` | | |
| 82 | +| Posts | `PUT posts/{id}/reaction`, `PUT posts/{id}/bookmark` | | |
| 83 | +| Find | `GET tags`, `GET tags/{slug}`, `GET search?q=`, `GET bookmarks` | | |
| 84 | +| Notifications | `GET notifications`, `GET notifications/unread`, `POST notifications/{id}/read`, `POST notifications/read` | | |
| 85 | + | |
| 86 | +Toggles take the desired state (`{"bookmarked": true}`), not "flip it" — a | |
| 87 | +retried request whose answer was lost lands on the same value | |
| 88 | +(movie_monster's `favorite`). The web's toggles compute the desired state and | |
| 89 | +call the same action. | |
| 90 | + | |
| 91 | +### 2b. Tokens | |
| 92 | + | |
| 93 | +Migration 000018 changes `api_tokens` in place: `token` becomes `token_hash` | |
| 94 | +(SHA-256 hex, as the verification tokens already are, and as party-slut and | |
| 95 | +the Phoenix apps do — rosin and movie_monster store plaintext, and hashing is | |
| 96 | +the one to copy). Existing rows are hashed in the migration, so tokens already | |
| 97 | +handed out keep working. | |
| 98 | + | |
| 99 | +- Token format `recourse_<64 hex>`, shown once, at pairing. | |
| 100 | +- 90-day sliding expiry for new device tokens, extended at most once a day — | |
| 101 | + the same "refresh only when stale" rule as `last_used_at`. A token created | |
| 102 | + before this migration with no expiry keeps none. | |
| 103 | +- Deactivated accounts already fail validation. | |
| 104 | +- **Devices page** (`/devices`, replacing `/api-tokens`, which redirects): | |
| 105 | + list (label, created, last used, expires), rename, revoke, and *Pair a | |
| 106 | + device*, which mints a token and shows it once as a QR of | |
| 107 | + `recourse://pair?base=<origin>&token=<token>` (movie_monster's | |
| 108 | + `devices/pair.html`, SVG from the `qrcode` crate) plus the two fields as | |
| 109 | + text. `base` is `PUBLIC_URL` when set, else the forwarded/Host headers. | |
| 110 | + | |
| 111 | +### 2c. Sign-in | |
| 112 | + | |
| 113 | +QR pairing only, as movie_monster: recourse's sign-in is a password or NEIAM | |
| 114 | +OIDC, and neither belongs in the app (pin_flip's password endpoint exists | |
| 115 | +because pin_flip has no other path; recourse can always pair from a signed-in | |
| 116 | +browser). The app scans the QR — or the phone opens the `recourse://` link | |
| 117 | +itself, or the two fields are typed — calls `GET /api/v1/me`, and stores the | |
| 118 | +pair only once that answers. | |
| 119 | + | |
| 120 | +No App Links, so no `/.well-known/assetlinks.json`: recourse sends no | |
| 121 | +magic-link email for the app to claim, and pairing uses the custom scheme. | |
| 122 | + | |
| 123 | +### 2d. Live updates | |
| 124 | + | |
| 125 | +Polling, as party-slut: lists load on open and on pull-to-refresh; the unread | |
| 126 | +badge is `GET notifications/unread` on resume. | |
| 127 | + | |
| 128 | +### 2e. Push | |
| 129 | + | |
| 130 | +**Not in v1.** party-slut's push works because its web side already sent | |
| 131 | +VAPID Web Push and UnifiedPush hands the app an endpoint of the same shape. | |
| 132 | +recourse has no web push — no subscriptions table, no sender, no VAPID keys — | |
| 133 | +so there is nothing to post a UnifiedPush endpoint *to*, and building the | |
| 134 | +sender is a server feature of its own that should land on the web first. Every | |
| 135 | +other sibling (gitgud, movie_monster, rosin) scopes push out for the same | |
| 136 | +reason. When recourse grows web push, party-slut §2e is the recipe. | |
| 137 | + | |
| 138 | +## 3. The app | |
| 139 | + | |
| 140 | +Copied from movie_monster (itself pin_flip's stack), so the family still | |
| 141 | +builds from one Gradle cache: | |
| 142 | + | |
| 143 | +- `android/` next to the server, package `org.neiam.recourse.app`, launcher | |
| 144 | + label "recourse", one `:app` module, single activity, Compose + Material 3, | |
| 145 | + no DI. | |
| 146 | +- Kotlin 2.0.20, AGP 8.5.2, Compose BOM 2024.09.00, minSdk 26 / target 34, | |
| 147 | + `gradle/libs.versions.toml` copied from movie_monster's and kept in step. | |
| 148 | +- Retrofit 2.11 + OkHttp 4.12 + kotlinx.serialization (`ignoreUnknownKeys`), | |
| 149 | + Coil 2.7 (+ `coil-svg`: letter avatars are SVG), navigation-compose, | |
| 150 | + zxing-embedded for the QR, `security-crypto` for the token store. | |
| 151 | +- `TokenStore` in EncryptedSharedPreferences, excluded from backup by | |
| 152 | + `data_extraction_rules.xml`; any 401 clears it and returns to pairing. | |
| 153 | +- Theme: the web's daisyUI themes from `assets/tailwind.config.js`, token for | |
| 154 | + token, via the family's OKLCh `AppTheme` (movie_monster/dms), with | |
| 155 | + **System** following the OS between `light` and `dark` exactly as the web's | |
| 156 | + picker does; B612 for type. | |
| 157 | +- Post bodies: the server's sanitized `cooked` HTML through `HtmlCompat` in a | |
| 158 | + `TextView` — the web's own markdown output, rather than a second markdown | |
| 159 | + renderer in the app that would disagree with it. | |
| 160 | +- Screens: pair → home (Classic tree or Focus rail/tiles) → category → topic | |
| 161 | + (reader, swipe to step in Focus) → reply / new topic → tags, tag, search, | |
| 162 | + bookmarks, notifications → profile (avatar, layout, sort, notifications, | |
| 163 | + verification, devices). | |
| 164 | + | |
| 165 | +## 4. (No SMS) | |
| 166 | + | |
| 167 | +party-slut §4 reads a sign-in code from an SMS. recourse has no code sign-in. | |
| 168 | + | |
| 169 | +## 5. Build, test, release | |
| 170 | + | |
| 171 | +- `android/Dockerfile`, `android/README.md`, `android/DESCRIPTION.md`: copied | |
| 172 | + from party-slut (the family Dockerfile with its `android-test` stage) and | |
| 173 | + renamed. | |
| 174 | +- `.forgejo/workflows/android.yml`: party-slut's — `test` job | |
| 175 | + (`--target android-test`), `publish` on master needing `ANDROID_KEYSTORE` / | |
| 176 | + `ANDROID_KEYSTORE_PASS` and skipping cleanly without them, upload to | |
| 177 | + `$FORGE_URL/pkg/fdroid/$REPOSITORY/upload`. versionCode = run number. | |
| 178 | +- Root `.dockerignore` excludes `android/`. | |
| 179 | +- Justfile: `apk`, `apk-install`, `apk-test`, `adb-devices`, `fixtures`, and | |
| 180 | + the private `gradle` recipe that finds a JDK 17–21 (system `java` is 25). | |
| 181 | +- **Contract tests**: `tests/api_db.rs` (needs `TEST_DATABASE_URL`, skipped | |
| 182 | + without it) drives `/api/v1` through the real router and, with | |
| 183 | + `WRITE_ANDROID_FIXTURES=1` (`just fixtures`), writes the responses to | |
| 184 | + `android/app/src/test/resources/api/*.json`; `ContractTest.kt` decodes every | |
| 185 | + one with the app's own `Json`. | |
| 186 | +- Server tests: visibility through the API (hidden category, topic, tag, | |
| 187 | + search hit, bookmark, notification), unverified writes 403, revoked and | |
| 188 | + expired tokens 401, cookie not accepted, view throttle and read tracking. | |
| 189 | +- Launcher icon: `ic_icon` adaptive icon in `res/mipmap-*` — the layout | |
| 190 | + `../icon-studio` exports and `../dms` ships — so an icon-studio export over | |
| 191 | + `android/app/src/main/res` replaces the placeholder without touching the | |
| 192 | + manifest. | |
| 193 | + | |
| 194 | +## 6. Order of work | |
| 195 | + | |
| 196 | +1. Tokens hashed + sliding expiry, bearer `/api/v1` middleware, `GET me`, | |
| 197 | + Devices page with the QR. Pairing works end to end. | |
| 198 | +2. Shared actions (`src/actions.rs`), web handlers moved onto them. | |
| 199 | +3. Read endpoints, then write endpoints; `docs/api.md`; DB tests + fixtures. | |
| 200 | +4. App: pairing, theme, Classic browse, topic, writes, Focus, find screens, | |
| 201 | + profile. | |
| 202 | +5. Dockerfile, workflow, Justfile. | |
| 203 | + | |
| 204 | +## 7. Decided | |
| 205 | + | |
| 206 | +- Package `org.neiam.recourse.app`, scheme `recourse://`. | |
| 207 | +- Pair only; every `/api/v1` route needs a token. The app does not browse | |
| 208 | + anonymously — the web does that. | |
| 209 | +- Layout and sort are the account's, read from `GET me` and saved with | |
| 210 | + `PATCH me`, so phone and browser agree. Switching layout on the phone saves | |
| 211 | + it, as the profile radio does on the web; there is no per-screen override. | |
| 212 | + | |
| 213 | +## 8. As built | |
| 214 | + | |
| 215 | +See the bottom of this file once built. |
Parents: 0c61284