Skip to content

chore: refactor SearchTask - WPB-20362#4245

Open
caldrian wants to merge 91 commits intodevelopfrom
chore/refactor-searchtask-WPB-20362
Open

chore: refactor SearchTask - WPB-20362#4245
caldrian wants to merge 91 commits intodevelopfrom
chore/refactor-searchtask-WPB-20362

Conversation

@caldrian
Copy link
Contributor

@caldrian caldrian commented Feb 2, 2026

TaskWPB-20362 [iOS/Integration] - Searching for Apps specifically

Issue

Currently SearchTask's different subtasks for searching contacts is implemented in a fragile way (see tasksRemaining property). Cancelling a task can lead to an async continuation leaking.

This PR refactors the code in order to make use of Swift Concurrency for a more stable implementation.

Testing

Ideally there shouldn't be any differences from the user's perspective.


Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Make sure you use the API for UI elements that support large fonts.
  • All colors are taken from WireDesign.ColorTheme or constructed using WireDesign.BaseColorPalette.
  • New UI elements have Accessibility strings for VoiceOver.

@caldrian caldrian changed the title chore: refactor SearchTask - WPB-20362 chore: refactor SearchTask - WPB-20362x Feb 4, 2026
@caldrian caldrian changed the title chore: refactor SearchTask - WPB-20362x chore: refactor SearchTask - WPB-20362 Feb 4, 2026
@caldrian caldrian marked this pull request as ready for review February 4, 2026 06:55
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Test Results

6 711 tests   6 684 ✅  8m 52s ⏱️
  825 suites     27 💤
    5 files        0 ❌

Results for commit 9b89654.

♻️ This comment has been updated with latest results.

Summary: workflow run #21749862433
Allure report (download zip): html-report-27625-chore_refactor-searchtask-WPB-20362

@caldrian caldrian requested review from a team, KaterinaWire, Copilot and jullianm and removed request for a team February 4, 2026 11:15
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 refactors the search infrastructure to use Swift Concurrency, modernizes SearchTask/SearchDirectory APIs, and updates UI callers and tests accordingly. The goal is to make contact/directory/service search more robust and less error‑prone while preserving existing behavior from the user’s perspective.

Changes:

  • Replace the callback-based SearchTask implementation (with manual tasksRemaining tracking) by an async/await–driven version that aggregates results via SearchResult “aggregator” closures and updates the SearchUserObserverCenter directly.
  • Simplify and modernize the search entry points: SearchDirectory now creates SearchTask instances via createSearchTask / createLookupTask, SearchUserViewController performs lookups using await task.start(), and SearchResultsViewController’s result handling is streamlined.
  • Update SearchTaskTests and SearchDirectoryTests to the new concurrency APIs and result aggregation model, and slightly adjust search throttling in StartUIViewController.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
wire-ios/Wire-iOS/Sources/UserInterface/UserProfile/SearchUserViewController.swift Switched user lookup to an async SearchTask obtained from SearchDirectory.createLookupTask(with:), awaiting task.start() and then driving the profile UI from the returned SearchResult.
wire-ios/Wire-iOS/Sources/UserInterface/StartUI/StartUI/StartUIViewController.swift Adjusted the search debounce delay in updateSearchResults(for:) from 0.2s to 0.25s to slightly smooth out search triggering.
wire-ios/Wire-iOS/Sources/UserInterface/StartUI/StartUI/SearchResultsViewController.swift Simplified search result handling: pendingSearchTask is now just a Task, and handleSearchResult takes a single SearchResult and always updates the empty state.
wire-ios-sync-engine/Tests/Source/UserSession/SearchTaskTests.swift Reworked tests to use async helpers (performLocalSearch, performRemoteSearch, etc.), new async Core Data setup helpers, and direct application of SearchResultAggregator closures instead of callback-based addResultHandler.
wire-ios-sync-engine/Tests/Source/UserSession/SearchDirectoryTests.swift Ensures SearchDirectory.tearDown() clears the SearchUsersCache using the new initializer and dependencies.
wire-ios-sync-engine/Source/UserSession/Search/SearchTask.swift Major refactor: introduces SearchTask.Type, async start() orchestrating a TaskGroup of search subtasks, transforms each subtask into an async function returning a SearchResultAggregator, and removes the old manual tasksRemaining/task identifier management in favor of Swift Concurrency primitives.
wire-ios-sync-engine/Source/UserSession/Search/SearchResult.swift Adds a convenience empty initializer and a union(prependingDirectory:) helper used when prepending handle-based directory results.
wire-ios-sync-engine/Source/UserSession/Search/SearchRequest.swift Minor stylistic and spacing adjustments; SearchOptions and SearchRequest behavior remains the same.
wire-ios-sync-engine/Source/UserSession/Search/SearchDirectory.swift Converts SearchDirectory into a final Swift class with createSearchTask(with:) / createLookupTask(with:) factories and a tearDown() method that clears the search-user cache and resets the SearchUserObserverCenter.
wire-ios-data-model/Source/Notifications/SearchUserObserverCenter.swift Makes SearchUserSnapshot final and leaves the observer center behavior intact.

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

…6-4b0ae052c960d7c3bc123cf79d7c61406508c4cb' into chore/delete-search-context-WPB-20362
Base automatically changed from chore/delete-search-context-WPB-20362 to develop February 6, 2026 08:31
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 6, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants