13.5 KiB · text History 01d6190

Android app — plan

A native client for recourse, in the same family as the sibling apps. The shape of this doc is ../party-slut/docs/android.md, the newest family plan. Where it is silent, do what ../movie_monster/android (the newest app, and the one whose pairing flow this copies) and ../pin_flip/android do. The server half follows ../rosin_hunter_3000: a bearer-only /api/v1 nest with its own JSON-401 middleware.

Status: built, steps 1–5 (§6). §8 says where the result differs from the plan below, which is otherwise kept as it was written.

1. Goals

Reading and writing a forum on a phone, with the web’s rules:

  • Browse categories as the web does, in either layout, honouring the account’s Layout preference from the API (preferred_view):
    • Classic — the category tree, then a topic list per category.
    • Focus — a rail of categories across the top and the selected category’s topics as tiles; opening one reads it full screen, and a sideways swipe steps to the previous/next topic in the tile order, the phone’s version of the web filmstrip and its arrow keys.
  • Read a topic: posts rendered from the server’s own markdown output, tags, reactions, who posted. Reading marks it read and counts a view by exactly the web’s rules (§2a).
  • Write: reply, start a topic (with tags), react, bookmark, watch a category, edit a topic’s tags where the web allows it.
  • Find: tags (index and per tag), search, bookmarks, notifications (mark one / all read).
  • Profile: avatar (upload / remove), Layout, default sort, reaction notifications, devices; unpair this phone.
  • Email verification: an unverified account (when the server requires verification) is read-only in the app exactly as on the web — write controls hidden, a banner saying why, and a Resend button.

Out of scope: everything under /admin and the manage CLI (categories, reaction types, invites, users) stays web/CLI; editing and deleting posts (the web keeps it; the app links out); sign-up; iOS; offline reading.

2. What the server has today, and what it needs

Every page is server-rendered minijinja + htmx behind a cookie session. There is an api_tokens table (plaintext tokens), a /api-tokens page that mints them, and /api/profile behind a middleware that takes either a bearer token or the cookie. There is no JSON API beyond that one call.

2a. /api/v1

.nest("/api/v1", api::router(state)), the router built in the library (src/api/mod.rs) so tests drive the real thing. Its own middleware is bearer-only and answers 401 as JSON — rosin_hunter_3000’s api_auth_middleware: a cookie must not authorize a cross-origin JSON API with no CSRF protection of its own. The legacy /api/profile is left alone.

Conventions (party-slut §2a, which kept bigtrippr’s):

  • snake_case keys, ISO-8601 UTC instants, UUIDv7 ids.
  • One error envelope: {"error": {"code", "message", "details"}}.
  • User-Agent: Recourse-Android/<versionName>.
  • Anything the viewer can’t see is a 404, whether or not it exists.
  • Permission flags (may_write, can_reply, can_edit_tags, …) are computed by the server; the app only shows or hides.
  • Handlers are thin. Visibility (CategoryTree::can_view / visible_category_ids with the viewer’s trust level and staff flag), min-trust tag minting, the verification gate (may_write), the view throttle and read tracking (record_topic_view), the sort preference (resolve_sort) and the listings (category_topics, decorate, visible_tags, search) are the functions the web handlers call. Writes that are more than one row — new topic, reply, tags, reaction, bookmark, watch, preferences, avatar — move into src/actions.rs and the web handlers are changed to call them too (party-slut §8, “one place for follow-on work”).

Endpoints, mapped from the web routes (full list in docs/api.md):

Area Endpoints
Me GET me, PATCH me (layout, sort, reaction notifications), PUT/DELETE me/avatar, POST me/verification (resend)
Devices GET me/devices, DELETE me/devices/{id}, DELETE sessions/current
Browse GET categories, GET categories/{slug}?sort=, PUT categories/{slug}/watch
Topics GET topics/{id}, POST categories/{slug}/topics, POST topics/{id}/posts, PUT topics/{id}/tags
Posts PUT posts/{id}/reaction, PUT posts/{id}/bookmark
Find GET tags, GET tags/{slug}, GET search?q=, GET bookmarks
Notifications GET notifications, GET notifications/unread, POST notifications/{id}/read, POST notifications/read

Toggles take the desired state ({"bookmarked": true}), not “flip it” — a retried request whose answer was lost lands on the same value (movie_monster’s favorite). The web’s toggles compute the desired state and call the same action.

2b. Tokens

Migration 000018 changes api_tokens in place: token becomes token_hash (SHA-256 hex, as the verification tokens already are, and as party-slut and the Phoenix apps do — rosin and movie_monster store plaintext, and hashing is the one to copy). Existing rows are hashed in the migration, so tokens already handed out keep working.

  • Token format recourse_<64 hex>, shown once, at pairing.
  • 90-day sliding expiry for new device tokens, extended at most once a day — the same “refresh only when stale” rule as last_used_at. A token created before this migration with no expiry keeps none.
  • Deactivated accounts already fail validation.
  • Devices page (/devices, replacing /api-tokens, which redirects): list (label, created, last used, expires), rename, revoke, and Pair a device, which mints a token and shows it once as a QR of recourse://pair?base=<origin>&token=<token> (movie_monster’s devices/pair.html, SVG from the qrcode crate) plus the two fields as text. base is PUBLIC_URL when set, else the forwarded/Host headers.

2c. Sign-in

QR pairing only, as movie_monster: recourse’s sign-in is a password or NEIAM OIDC, and neither belongs in the app (pin_flip’s password endpoint exists because pin_flip has no other path; recourse can always pair from a signed-in browser). The app scans the QR — or the phone opens the recourse:// link itself, or the two fields are typed — calls GET /api/v1/me, and stores the pair only once that answers.

No App Links, so no /.well-known/assetlinks.json: recourse sends no magic-link email for the app to claim, and pairing uses the custom scheme.

2d. Live updates

Polling, as party-slut: lists load on open and on pull-to-refresh; the unread badge is GET notifications/unread on resume.

2e. Push

Not in v1. party-slut’s push works because its web side already sent VAPID Web Push and UnifiedPush hands the app an endpoint of the same shape. recourse has no web push — no subscriptions table, no sender, no VAPID keys — so there is nothing to post a UnifiedPush endpoint to, and building the sender is a server feature of its own that should land on the web first. Every other sibling (gitgud, movie_monster, rosin) scopes push out for the same reason. When recourse grows web push, party-slut §2e is the recipe.

3. The app

Copied from movie_monster (itself pin_flip’s stack), so the family still builds from one Gradle cache:

  • android/ next to the server, package org.neiam.recourse.app, launcher label “recourse”, one :app module, single activity, Compose + Material 3, no DI.
  • Kotlin 2.0.20, AGP 8.5.2, Compose BOM 2024.09.00, minSdk 26 / target 34, gradle/libs.versions.toml copied from movie_monster’s and kept in step.
  • Retrofit 2.11 + OkHttp 4.12 + kotlinx.serialization (ignoreUnknownKeys), Coil 2.7 (+ coil-svg: letter avatars are SVG), navigation-compose, zxing-embedded for the QR, security-crypto for the token store.
  • TokenStore in EncryptedSharedPreferences, excluded from backup by data_extraction_rules.xml; any 401 clears it and returns to pairing.
  • Theme: the web’s daisyUI themes from assets/tailwind.config.js, token for token, via the family’s OKLCh AppTheme (movie_monster/dms), with System following the OS between light and dark exactly as the web’s picker does; B612 for type.
  • Post bodies: the server’s sanitized cooked HTML through HtmlCompat in a TextView — the web’s own markdown output, rather than a second markdown renderer in the app that would disagree with it.
  • Screens: pair → home (Classic tree or Focus rail/tiles) → category → topic (reader, swipe to step in Focus) → reply / new topic → tags, tag, search, bookmarks, notifications → profile (avatar, layout, sort, notifications, verification, devices).

4. (No SMS)

party-slut §4 reads a sign-in code from an SMS. recourse has no code sign-in.

5. Build, test, release

  • android/Dockerfile, android/README.md, android/DESCRIPTION.md: copied from party-slut (the family Dockerfile with its android-test stage) and renamed.
  • .forgejo/workflows/android.yml: party-slut’s — test job (--target android-test), publish on master needing ANDROID_KEYSTORE / ANDROID_KEYSTORE_PASS and skipping cleanly without them, upload to $FORGE_URL/pkg/fdroid/$REPOSITORY/upload. versionCode = run number.
  • Root .dockerignore excludes android/.
  • Justfile: apk, apk-install, apk-test, adb-devices, fixtures, and the private gradle recipe that finds a JDK 17–21 (system java is 25).
  • Contract tests: tests/api_db.rs (needs TEST_DATABASE_URL, skipped without it) drives /api/v1 through the real router and, with WRITE_ANDROID_FIXTURES=1 (just fixtures), writes the responses to android/app/src/test/resources/api/*.json; ContractTest.kt decodes every one with the app’s own Json.
  • Server tests: visibility through the API (hidden category, topic, tag, search hit, bookmark, notification), unverified writes 403, revoked and expired tokens 401, cookie not accepted, view throttle and read tracking.
  • Launcher icon: ic_icon adaptive icon in res/mipmap-* — the layout ../icon-studio exports and ../dms ships — so an icon-studio export over android/app/src/main/res replaces the placeholder without touching the manifest.

6. Order of work

  1. Tokens hashed + sliding expiry, bearer /api/v1 middleware, GET me, Devices page with the QR. Pairing works end to end.
  2. Shared actions (src/actions.rs), web handlers moved onto them.
  3. Read endpoints, then write endpoints; docs/api.md; DB tests + fixtures.
  4. App: pairing, theme, Classic browse, topic, writes, Focus, find screens, profile.
  5. Dockerfile, workflow, Justfile.

7. Decided

  • Package org.neiam.recourse.app, scheme recourse://.
  • Pair only; every /api/v1 route needs a token. The app does not browse anonymously — the web does that.
  • Layout and sort are the account’s, read from GET me and saved with PATCH me, so phone and browser agree. Switching layout on the phone saves it, as the profile radio does on the web; there is no per-screen override.

8. As built

All five steps exist, server and app. What came out differently:

  • Paths. src/api/mod.rs is the route list; docs/api.md the reference. Marking all notifications read is POST notifications/read. Reading a removed topic is 410 removed for non-staff (the web shows a tombstone).
  • Malformed ids answer in the envelope too (ApiPath, beside party-slut’s ApiJson), and unknown /api/v1 paths are JSON 404s.
  • The web got stricter. Moving the reaction, bookmark and watch toggles onto crate::actions gave them the visibility check they lacked: before, they acted on any post or category id, hidden or deleted.
  • Tokens can’t be re-shown. movie_monster re-shows a token’s QR from its list; hashing them (party-slut) makes that impossible, so a wiped phone is a revoke and a fresh pairing. The old “expires in N days” field is gone: device tokens slide instead.
  • Classic topics don’t page. The reader always gets the list a topic was opened from, but only Focus lets a swipe move through it, matching the web (only Focus steps).
  • Layout switching is a toolbar button on the forum and category screens plus the profile control; both PATCH /me.
  • Post bodies are HtmlCompat over the server’s cooked: links work, images and code blocks render plainly.
  • Not verified on a device or emulator. Everything is built and unit-tested — the API through the real router against Postgres (just test-db), the app’s decoding against captured responses (just fixtures, just apk-test) — and the API was exercised end to end with curl against a seeded server, pairing from the Devices page. No AVD or system image is installed here, so the app itself has not been run.
  • Launcher icon is exported from ic_icon.toml with icon-studio (android/README.md, “Launcher icon”).
  • Moderation (later). The app follows the server’s moderation:
    • Locked topics show staff’s reason. When a reply rule, a lock or a staff-only category blocks something, the control is gone and the server’s sentence (reply_blocked, create_blocked) says why.
    • A moderated post shows its note in a “staff · name:” box.
    • A post hidden pending review reads “Hidden pending staff review.” (its author still sees it, marked).
    • A cooldown replaces the verify banner with “Read-only until …: reason”. Bookmarks still work then, as on the web.
    • The post menu (⋮) flags a post (POST /posts/{id}/flags).
    • Everything staff do stays on the web: moderating, locking, the queue, sanctions and addresses.