# D8 — Feedback HTTP Submission · Integration Wires the existing `FeedbackBody` "Send" (currently a local `sent` flag) to a real HTTP POST, with Sending / Sent / Error(+retry) states. ## Files in this draft | Draft file | Destination | |---|---| | `FeedbackState.kt` | `app/src/main/java/com/peachpasswords/feedback/FeedbackState.kt` (new) | | `FeedbackRepository.kt` | `app/src/main/java/com/peachpasswords/feedback/FeedbackRepository.kt` (new) | | `FeedbackBody.kt` | replaces the private `FeedbackBody` in `ui/settings/SettingsCardBodies.kt` (do NOT add as a separate file) | | `SettingsViewModel.feedback.snippet.kt` | additions to `ui/settings/SettingsViewModel.kt` (do NOT add as a separate file) | New package `com.peachpasswords.feedback` — create the directory. ## Endpoint assumption (mirrors the browser source) Source of truth: `~/projects/peach-browser/src/background/messages.ts`, the `SUBMIT_FEEDBACK` case (around line 1081) and `FEEDBACK_ENDPOINT` (line 127). - The browser ships **`FEEDBACK_ENDPOINT = ""`** and treats empty as a **no-op success** (`if (!FEEDBACK_ENDPOINT) return { ok: true }`). The Android repo mirrors this: `FeedbackRepository.FEEDBACK_ENDPOINT = ""` and `submit()` returns normally (→ `Sent`) when it's blank. So the full UI flow works today with no live backend. - Payload (exact field names from the browser): `{ category, message, version, browser, source }`, POSTed as `application/json`. The browser sends `source: "peach-extension"`; this draft sends `source: "peach-android"` and `browser: "android"`. `version` is `BuildConfig.VERSION_NAME`. - **TODO for orchestrator:** when a real feedback URL exists, set the `FEEDBACK_ENDPOINT` constant in `FeedbackRepository.kt`. The browser also runs `isAllowedCanaryWebhookUrl()` SSRF validation before fetching; that guard was not ported (the Android constant is compile-time, not user-supplied). If the endpoint ever becomes configurable, port that validation too. ## HTTP client No new dependency. The project already bundles **OkHttp 4.12.0** (`app/build.gradle` line 100) and uses it in `sync/ChirpSyncTransport.kt`. `FeedbackRepository` uses `OkHttpClient` + `Request` + `RequestBody`, and `org.json.JSONObject` (Android platform, no dep) for the body. The brief mentioned `HttpURLConnection` as a fallback "unless the project already bundles an HTTP client" — it does, so OkHttp is used. ## DI wiring `FeedbackRepository` is annotated `@Singleton` with an `@Inject constructor()` that takes no arguments, so **Hilt constructs it automatically — no `@Binds` / `@Provides` module entry is needed** (unlike `VaultStorage`, which needs a `@Binds` only because it's an interface). Just add it to the VM constructor. In `SettingsViewModel.kt`, add the parameter to the existing `@Inject` constructor: ```kotlin @HiltViewModel class SettingsViewModel @Inject constructor( private val vault: VaultRepository, private val license: LicenseRepository, private val feedback: FeedbackRepository, // ← add @ApplicationContext private val appContext: Context, ) : ViewModel() { ``` Then paste the `_feedbackState` flow + `sendFeedback()` + `resetFeedback()` from `SettingsViewModel.feedback.snippet.kt` into the class body. ### Imports to add to `SettingsViewModel.kt` `MutableStateFlow`, `StateFlow`, `asStateFlow`, `launch` are already imported. Add: ```kotlin import com.peachpasswords.feedback.FeedbackRepository import com.peachpasswords.feedback.FeedbackState ``` ## Composable wiring (`SettingsCardBodies.kt`) 1. **Call site** — change line 78 from: ```kotlin CardId.Feedback -> FeedbackBody(fg) ``` to: ```kotlin CardId.Feedback -> FeedbackBody(fg, vm) ``` (`vm: SettingsViewModel` is already a `CardBody` parameter.) 2. **Body** — replace the whole private `FeedbackBody(fg: Color)` (currently lines 581-623, the block under the `Feedback` comment banner) with the `FeedbackBody(fg: Color, vm: SettingsViewModel)` from `FeedbackBody.kt`. It reuses the file's existing private helpers (`SubLabel`, `Pill`, `Hint`) and does NOT use `SubtleButton` (it inlines a Send/Retry button so it can carry a disabled state) — `SubtleButton` is unaffected and still used elsewhere. ### Imports to add to `SettingsCardBodies.kt` Already present: `collectAsState`, `Row`, `Alignment`, `size`, `LocalContext` (unused here). Add: ```kotlin import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.DisposableEffect import com.peachpasswords.feedback.FeedbackState import com.peachpasswords.ui.theme.LocalPeachAccent ``` (`androidx.compose.foundation.layout.size` and `...layout.Row` and `...Alignment` are already imported.) ## State → UI mapping (per brief §7) - `Sending` → Send button disabled + 16dp accent `CircularProgressIndicator`; category pills and textarea also disabled. - `Sent` → the existing "Thank you" glass card (unchanged visual). - `Error` → inline message in `PeachColors.Breach` below the button; button text becomes "Retry" and re-enables (retry path). - `Idle` → default form. State resets to `Idle` via `resetFeedback()` in a `DisposableEffect` when the card leaves composition. ## Risks / assumptions - **Blank-message guard is duplicated**: the composable already gates Send on `message.isNotBlank()`, and `submit()` also throws on blank (matching the browser's `message_empty`). Harmless; the repo guard protects non-UI callers. - **No SSRF/allowlist validation** ported (constant URL, not user input). Note above if the endpoint becomes configurable. - `version`/`browser`/`source` field values are best-effort interpretations of the browser payload for the Android platform; confirm with backend if/when the endpoint goes live. - Verify `BuildConfig` import resolves: namespace is `com.peachpasswords`, so `com.peachpasswords.BuildConfig.VERSION_NAME` is correct.