feat: add GET/POST /user/privacy to read and set privacy settings#332
Merged
Conversation
Exposes whatsmeow's privacy settings through two endpoints:
GET /user/privacy returns the account's current settings
POST /user/privacy {Name,Value} updates a single setting
Both follow the existing handler pattern: per-token auth, "no session" when the
client isn't connected, and a request-scoped context with a 30s timeout.
Input is validated before it reaches the server. validatePrivacySetting checks
that the name is supported and the value is allowed for that name, using the
matrix documented in whatsmeow's types. The exposed set is deliberately the
seven settings that whatsmeow's (*Client).SetPrivacySetting round-trips into the
returned/cached PrivacySettings. The protocol also defines messages/defense/
stickers, but whatsmeow's setter has no switch case for them (the change is sent
to the server yet not reflected back), so they are intentionally rejected and a
test locks that boundary.
Purely additive: two new routes, no change to existing behavior. Covered by unit
tests for the validation matrix and an integration test that drives both routes
through the real router and auth middleware. Docs added to API.md and the
OpenAPI spec.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces endpoints to get and set user privacy settings (GET /user/privacy and POST /user/privacy). It includes input validation against supported WhatsApp privacy settings, handler implementations, route registration, comprehensive unit tests, and updated API documentation in both API.md and the OpenAPI specification. I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
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.
What
Exposes whatsmeow's privacy settings through two endpoints, following the same shape as the existing
/user/*handlers:GET/user/privacyPOST/user/privacy{"Name":"...","Value":"..."}Example
Validation
Input is checked before it reaches the server.
validatePrivacySettingverifies the name is supported and the value is allowed for that name, using the matrix documented in whatsmeow'stypes(groupadd/last/status/profile→all|contacts|contact_blacklist|none,readreceipts→all|none,online→all|match_last_seen,calladd→all|known).The exposed set is deliberately the seven settings that whatsmeow's
(*Client).SetPrivacySettinground-trips into the returned/cachedPrivacySettings. The protocol also definesmessages/defense/stickers, but whatsmeow's setter has no switch case for them — a change would be sent to the server yet not reflected back in the response or cache — so they're intentionally rejected. A test locks that boundary (using values that are valid per the matrix, to prove the rejection is by name, not value). Easy to extend if whatsmeow adds those cases upstream.Testing
TestValidatePrivacySetting— 20 cases (valid combos, invalid values, the deliberately-excluded names, unknown/empty).TestPrivacyEndpoints— drivesGETandPOSTthrough the real router + auth middleware, asserting both routes are wired (not 404) and auth passes (not 401).go vet ./...,go test ./..., and aGOOS=linuxbuild/test-binary all green.Notes
API.mdandstatic/api/spec.yml.+308 / -0.