Skip to content

Conversation

@eyeinsky
Copy link
Contributor

@eyeinsky eyeinsky commented Dec 16, 2025

WPB-21366: [Backend] Add type field to search contacts endpoint response

This PR adds the type field to contacts retrieved from GET /search/contacts. To achieve this it needs to send that field to Elastic Search as that's where the search happens. The challenge (sometimes) is in how to determine whether the user is an app or not, as that depends on whether there is an according row in the apps table for the user (i.e, it's a derived field and not a field on the user row).

Leaving this as draft, as there is still work outstanding:

  • comments marked with XXX, all these should be resolved before merging
  • adapt wire-subsystems' unit tests for the new field. Started adding State [StoredApp] there to the UserStore interpreter, as consulting the apps determines a user's type

UPDATE(fisx): this PR is done with one exception: brig-index wrongly initiates type field with regular instead of app. to do better, it needs to talk to postgres, which isn't trivial. PR coming up!

Checklist

  • Add a new entry in an appropriate subdirectory of changelog.d
  • Read and follow the PR guidelines

@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label Dec 16, 2025
@eyeinsky eyeinsky force-pushed the ml/WPB-21366--add-type-field-to-search-contacts branch 2 times, most recently from fbd0b50 to c76d34c Compare December 19, 2025 16:57
@eyeinsky eyeinsky force-pushed the ml/WPB-21366--add-type-field-to-search-contacts branch 5 times, most recently from 5ec54b8 to 83fcf33 Compare December 31, 2025 11:25
@akshaymankar akshaymankar force-pushed the ml/WPB-21366--add-type-field-to-search-contacts branch 2 times, most recently from f5501ad to 38aa39c Compare January 5, 2026 13:37
@fisx fisx force-pushed the ml/WPB-21366--add-type-field-to-search-contacts branch 4 times, most recently from b9b0d18 to 8fe483f Compare January 12, 2026 12:00
@fisx fisx marked this pull request as ready for review January 12, 2026 15:35
@fisx fisx requested review from a team as code owners January 12, 2026 15:35
@battermann battermann requested a review from Copilot January 13, 2026 08:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a type field to the Contact data type returned by GET /search/contacts, enabling clients to distinguish between regular users, bots, and apps in search results. The implementation extends Elasticsearch indexing to store and query user types, and updates all profile creation and search logic to propagate this information.

Changes:

  • Added type field to Contact and UserDoc data types with corresponding JSON serialization
  • Updated mkUserProfile and mkUserProfileWithEmail functions to accept and use UserType parameter
  • Implemented getUserType helper function to determine user type based on serviceId and apps table lookup
  • Updated all test fixtures (golden tests, unit tests, integration tests) to include the new type field

Reviewed changes

Copilot reviewed 61 out of 63 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
libs/wire-api/src/Wire/API/User/Search.hs Added required contactType field to Contact data type
libs/wire-api/src/Wire/API/User.hs Modified mkUserProfile functions to accept UserType parameter
libs/wire-subsystems/src/Wire/UserSearch/Types.hs Added udType field to UserDoc and userDocToContact helper function
libs/wire-subsystems/src/Wire/UserStore/IndexUser.hs Updated indexUserToDoc to accept and store user type
libs/wire-subsystems/src/Wire/UserSubsystem/Interpreter.hs Implemented getUserType helper and integrated it into profile creation and search
libs/wire-subsystems/src/Wire/IndexedUserStore/Bulk/ElasticSearch.hs Added user type determination during bulk indexing operations
services/brig/src/Brig/User/Search/Index.hs Added type field to Elasticsearch mapping
services/brig/src/Brig/User/Search/SearchIndex.hs Refactored search to use centralized userDocToContact function
services/brig/src/Brig/User/API/Handle.hs Updated contactFromProfile to include type field
services/brig/src/Brig/Provider/API.hs Fixed bot profile creation to use UserTypeBot
services/brig/src/Brig/Index/Eval.hs Added UsageError handling and Hasql.Pool import
libs/wire-subsystems/test/unit/* Updated all unit tests to provide UserType when creating profiles
libs/wire-api/test/golden/* Updated all golden test fixtures with type field set to "regular", "bot", or "app"
integration/test/Test/Apps.hs Added integration test verifying app users have type "app" in search results
changelog.d/1-api-changes/* Added changelog entries documenting the new field and migration requirements
postgres-schema.sql Updated PostgreSQL dump version number (17.6 → 17.7)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

fisx added 15 commits January 13, 2026 12:27
There is prior art to this with email visibility and role, we're just
following the pattern. There might be a nicer way, though.
The code isn't a lot shorter this way, but there aren't two places
that make the same debatable decision to lie about user types of bots
before ES re-index.
this may be a problem, but it's unrelated; deferring to
#4944
This way, the type field is already returned in the /search/contacts
endpoint, but it will contain `regular` instead of `app` everywhere.

The change to brig-index will happen in an upcoming PR.
the only debatable one is about performance in ES re-indexing, but
there we already do the expensive thing for roles and team
visibilities, so the effect on performance should be tolerable.
@fisx fisx force-pushed the ml/WPB-21366--add-type-field-to-search-contacts branch from f8b342e to 1c097b1 Compare January 13, 2026 11:33
@fisx fisx merged commit 3a9ffec into develop Jan 13, 2026
9 of 11 checks passed
@fisx fisx deleted the ml/WPB-21366--add-type-field-to-search-contacts branch January 13, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants