INTEGRATION.md

5.8 KB · raw

rendered · source

1# D8 — Feedback HTTP Submission · Integration23Wires the existing `FeedbackBody` "Send" (currently a local `sent` flag) to a4real HTTP POST, with Sending / Sent / Error(+retry) states.56## Files in this draft78| Draft file | Destination |9|---|---|10| `FeedbackState.kt` | `app/src/main/java/com/peachpasswords/feedback/FeedbackState.kt` (new) |11| `FeedbackRepository.kt` | `app/src/main/java/com/peachpasswords/feedback/FeedbackRepository.kt` (new) |12| `FeedbackBody.kt` | replaces the private `FeedbackBody` in `ui/settings/SettingsCardBodies.kt` (do NOT add as a separate file) |13| `SettingsViewModel.feedback.snippet.kt` | additions to `ui/settings/SettingsViewModel.kt` (do NOT add as a separate file) |1415New package `com.peachpasswords.feedback` — create the directory.1617## Endpoint assumption (mirrors the browser source)1819Source of truth: `~/projects/peach-browser/src/background/messages.ts`, the20`SUBMIT_FEEDBACK` case (around line 1081) and `FEEDBACK_ENDPOINT` (line 127).2122- The browser ships **`FEEDBACK_ENDPOINT = ""`** and treats empty as a **no-op23  success** (`if (!FEEDBACK_ENDPOINT) return { ok: true }`). The Android repo24  mirrors this: `FeedbackRepository.FEEDBACK_ENDPOINT = ""` and `submit()`25  returns normally (→ `Sent`) when it's blank. So the full UI flow works today26  with no live backend.27- Payload (exact field names from the browser):28  `{ category, message, version, browser, source }`, POSTed as29  `application/json`. The browser sends `source: "peach-extension"`; this draft30  sends `source: "peach-android"` and `browser: "android"`. `version` is31  `BuildConfig.VERSION_NAME`.32- **TODO for orchestrator:** when a real feedback URL exists, set the33  `FEEDBACK_ENDPOINT` constant in `FeedbackRepository.kt`. The browser also runs34  `isAllowedCanaryWebhookUrl()` SSRF validation before fetching; that guard was35  not ported (the Android constant is compile-time, not user-supplied). If the36  endpoint ever becomes configurable, port that validation too.3738## HTTP client3940No new dependency. The project already bundles **OkHttp 4.12.0**41(`app/build.gradle` line 100) and uses it in42`sync/ChirpSyncTransport.kt`. `FeedbackRepository` uses `OkHttpClient` +43`Request` + `RequestBody`, and `org.json.JSONObject` (Android platform, no dep)44for the body. The brief mentioned `HttpURLConnection` as a fallback "unless the45project already bundles an HTTP client" — it does, so OkHttp is used.4647## DI wiring4849`FeedbackRepository` is annotated `@Singleton` with an `@Inject constructor()`50that takes no arguments, so **Hilt constructs it automatically — no `@Binds` /51`@Provides` module entry is needed** (unlike `VaultStorage`, which needs a52`@Binds` only because it's an interface). Just add it to the VM constructor.5354In `SettingsViewModel.kt`, add the parameter to the existing `@Inject`55constructor:5657```kotlin58@HiltViewModel59class SettingsViewModel @Inject constructor(60    private val vault: VaultRepository,61    private val license: LicenseRepository,62    private val feedback: FeedbackRepository,          // ← add63    @ApplicationContext private val appContext: Context,64) : ViewModel() {65```6667Then paste the `_feedbackState` flow + `sendFeedback()` + `resetFeedback()` from68`SettingsViewModel.feedback.snippet.kt` into the class body.6970### Imports to add to `SettingsViewModel.kt`71`MutableStateFlow`, `StateFlow`, `asStateFlow`, `launch` are already imported.72Add:73```kotlin74import com.peachpasswords.feedback.FeedbackRepository75import com.peachpasswords.feedback.FeedbackState76```7778## Composable wiring (`SettingsCardBodies.kt`)79801. **Call site** — change line 78 from:81   ```kotlin82           CardId.Feedback -> FeedbackBody(fg)83   ```84   to:85   ```kotlin86           CardId.Feedback -> FeedbackBody(fg, vm)87   ```88   (`vm: SettingsViewModel` is already a `CardBody` parameter.)89902. **Body** — replace the whole private `FeedbackBody(fg: Color)` (currently91   lines 581-623, the block under the `Feedback` comment banner) with the92   `FeedbackBody(fg: Color, vm: SettingsViewModel)` from `FeedbackBody.kt`. It93   reuses the file's existing private helpers (`SubLabel`, `Pill`, `Hint`) and94   does NOT use `SubtleButton` (it inlines a Send/Retry button so it can carry a95   disabled state) — `SubtleButton` is unaffected and still used elsewhere.9697### Imports to add to `SettingsCardBodies.kt`98Already present: `collectAsState`, `Row`, `Alignment`, `size`, `LocalContext`99(unused here). Add:100```kotlin101import androidx.compose.material3.CircularProgressIndicator102import androidx.compose.runtime.DisposableEffect103import com.peachpasswords.feedback.FeedbackState104import com.peachpasswords.ui.theme.LocalPeachAccent105```106(`androidx.compose.foundation.layout.size` and `...layout.Row` and107`...Alignment` are already imported.)108109## State → UI mapping (per brief §7)110111- `Sending` → Send button disabled + 16dp accent `CircularProgressIndicator`;112  category pills and textarea also disabled.113- `Sent` → the existing "Thank you" glass card (unchanged visual).114- `Error` → inline message in `PeachColors.Breach` below the button; button text115  becomes "Retry" and re-enables (retry path).116- `Idle` → default form.117118State resets to `Idle` via `resetFeedback()` in a `DisposableEffect` when the119card leaves composition.120121## Risks / assumptions122123- **Blank-message guard is duplicated**: the composable already gates Send on124  `message.isNotBlank()`, and `submit()` also throws on blank (matching the125  browser's `message_empty`). Harmless; the repo guard protects non-UI callers.126- **No SSRF/allowlist validation** ported (constant URL, not user input). Note127  above if the endpoint becomes configurable.128- `version`/`browser`/`source` field values are best-effort interpretations of129  the browser payload for the Android platform; confirm with backend if/when the130  endpoint goes live.131- Verify `BuildConfig` import resolves: namespace is `com.peachpasswords`, so132  `com.peachpasswords.BuildConfig.VERSION_NAME` is correct.