feat(profile): Settings surface + view preferences and link previews (#33) - #93
Merged
Merged
Conversation
…eviews Adds the Settings surface the web app has and Android lacked, reached from the Account hub at the `settings` route, structured as titled groups so the remaining preference groups only have to add UI. - `SettingsRepository` over `GET /api/user` + `PATCH /api/user/update`, with a process-scoped in-memory cache published as a flow, so the Settings screen and (later) the messages feed read the same values. - `UpdateProfileRequest` now models all fifteen fields the PATCH endpoint accepts, all optional: untouched fields are omitted from the body, so a partial update can never clobber another preference. Edit-profile keeps sending only `displayName` + `bio`. Values are sent with the natural JSON types the live `GET /api/user` payload returns, not the `string` the auto-generated spec claims. - `ViewingPreference` centralises the feed-filter wire values, taken from the live API: `GET /api/user` returns `all_messages`, and an invalid PATCH answers with the allow-list `my_messages, all_messages, followers_only, following_only`. Parsing stays tolerant of casing and shorthands so an unexpected spelling cannot silently reset a user's feed. - UI for this issue's two preferences only: the feed filter and the `showPreviews` link-preview toggle, each saved as its own partial PATCH with optimistic update and rollback on failure. Tests: repository round-trips and partial-PATCH body assertions, the four real wire values pinned in both directions, ViewModel load/save/error states, and a Compose test for the screen. Closes #33
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.
Closes #33. Part of epic #31. Scaffold that #32, #34, #35, #36 and #37 build on.
What changed
A Settings screen at route
settings, reached from a new "Settings" row on the Account hub,following the hub's existing
*Route+ stateless*Screendrill-down pattern. It renders titledgroups; only the "View preferences" group exists — no empty stubs for the sibling issues.
SettingsGroup,SettingsRadioRowandSettingsSwitchRoware public, so #32/#34/#35/#36/#37 onlyneed to add a group.
A
SettingsRepositoryoverGET /api/user+PATCH /api/user/update, deliberately separatefrom
ProfileRepository(different consumers: live preferences vs. the profile cache). It exposesobserveSettings(): Flow<UserSettings?>,refresh()andupdate(UserSettingsUpdate), is@Singletonwith a process-scoped in-memory cache matching the module's "settings are alwaysfresh, nothing cached" precedent, and republishes on every successful read/write.
All fifteen PATCH fields are modelled now (nullable, nulls omitted via the module's
explicitNulls = false), so the sibling issues only have to add UI.updateProfile(displayName, bio)is untouched and still sends exactly two keys — now covered by a regression test.UI for this issue only: the
viewingPreferenceradio group and theshowPreviewsswitch, eachsaved as its own partial PATCH, applied optimistically and rolled back on failure.
The enum is live-verified, not guessed
First pass guessed
all/mine/following/followers. I checked against the live API and thatwould have been rejected on every write. The server's own 400 gives the allow-list:
ViewingPreferencenow carries exactly those four, and the tests pin the literals and assertevery constant round-trips through its own
wire, so the two can't drift apart again.fromWirestays tolerant (case-insensitive, non-letters stripped) so an unexpected read degrades gracefully.
Verification
./gradlew :app:assembleDebug testDebugUnitTest :feature:profile:compileDebugAndroidTestKotlin→BUILD SUCCESSFUL, 711 unit tests, 0 failures. 8 repository tests (round-trips,
body.keysassertions proving a PATCH carries only the touched field, thin-body re-fetch, failure leaves the
cache intact, defaults when fields are absent), 7 mapper/enum, 9 ViewModel
(load/save/error/rollback/dismiss/no-op reselect), 1
updateProfileregression. 6 Compose testscompile but were not executed (no emulator).
Reviewer notes
onlyMine#19 (feed consumption) needs a module-dependency decision. No feature module currentlydepends on another;
:feature:messageswould needimplementation(project(":feature:profile"))to read
SettingsRepository, or the repository gets promoted to a shared module. Left alonedeliberately — this issue only exposes and persists the value; nothing consumes it yet, and the
"previews suppressed when off" behaviour is therefore not implemented here.
maxMessageLength,showPreviews,latitudeetc. asstringon the PATCH body while the live response returns int/bool/float.I send the natural JSON types, matching the response. Worth a live PATCH check when Settings: Message settings group (default visibility, max length, messages per page, advanced post settings) #32/Settings: notification tray limit (
notificationTrayLimit) #35/Settings: profile location (latitude/longitude) with runtime permission #37land.
codeis not read anywhere.ErrorDtoin:core:networkmodels only{ "error": ... }, andsafeApiCallmaps HTTP status →AppError. Wiringcodethrough meanswidening
AppErrorand touching every construction site repo-wide — out of scope here, andfiled separately.