Skip to content

Conversation

@laevandus
Copy link
Contributor

🔗 Issue Links

Fixes: IOS-1237

🎯 Goal

Add near and withinBounds filters with local filtering support new in feeds backend

🛠 Implementation

Feeds backend added new filter operators near and within_bounds. One for matching circular regions using Haversine formula (takes Earth's curvature into account), other just matching to bounds.

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

@laevandus laevandus requested a review from a team as a code owner November 18, 2025 08:58
@laevandus laevandus added the ✅ Feature An issue or PR related to a feature label Nov 18, 2025
@github-actions
Copy link

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

///
/// - Returns: A dictionary representation of the filter in `RawJSON` format.
public func toRawJSON() -> [String: RawJSON] {
public func toRawJSONDictionary() -> [String: RawJSON] {
Copy link
Contributor Author

@laevandus laevandus Nov 18, 2025

Choose a reason for hiding this comment

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

This is used for API requests in the Feeds SDK. rawJSON above comes from the FilterValue protocol and is used by toRawJSONDictionary. All in all, toRawJSONDictionary is just a convenience for API requests.
rawJSON was moved to the protocol since then it is better to manage conformance of all the types. Discovered some mapping issues like Int was not correctly encoded to RawJSON thanks to this change (there was a big switch statement before which).

/// let center = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194)
/// let region = CircularRegion(center: center, radiusInMeters: 5000)
/// ```
public struct CircularRegion {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Naming comes from Apple's CLCircularRegion

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we move this location stuff in a separate extension? Up to you though.

Copy link
Contributor

Choose a reason for hiding this comment

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

and how are other SDKs calling this? Better to align on SDKs convention, over Apple's.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will have a chat with others about the naming and will rename if needed.

func contains(_ coordinate: CLLocationCoordinate2D) -> Bool {
let centerLocation = CLLocation(latitude: center.latitude, longitude: center.longitude)
let coordinateLocation = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)
let distance = centerLocation.distance(from: coordinateLocation)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This takes the Earth's curvature into account, same as what backend does.

/// let sw = CLLocationCoordinate2D(latitude: 40.7580, longitude: -73.9855)
/// let boundingBox = BoundingBox(northeast: ne, southwest: sw)
/// ```
public struct BoundingBox {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Naming coming from MapBox and other location related frameworks.

Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

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

LGTM ✅ Just left 2 small remarks, but feel free to merge.

/// let center = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194)
/// let region = CircularRegion(center: center, radiusInMeters: 5000)
/// ```
public struct CircularRegion {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we move this location stuff in a separate extension? Up to you though.

/// let center = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194)
/// let region = CircularRegion(center: center, radiusInMeters: 5000)
/// ```
public struct CircularRegion {
Copy link
Contributor

Choose a reason for hiding this comment

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

and how are other SDKs calling this? Better to align on SDKs convention, over Apple's.

@laevandus laevandus enabled auto-merge (squash) November 18, 2025 12:05
@sonarqubecloud
Copy link

@laevandus laevandus merged commit 22fcbcf into develop Nov 18, 2025
6 checks passed
@laevandus laevandus deleted the add-filter-near-and-within-bounds branch November 18, 2025 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✅ Feature An issue or PR related to a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants