Skip to content

fix: report the location from the presence message in location update events - #368

Open
RaphaelFakhri wants to merge 1 commit into
ably:mainfrom
RaphaelFakhri:fix/locations-event-current-location
Open

RaphaelFakhri wants to merge 1 commit into
ably:mainfrom
RaphaelFakhri:fix/locations-event-current-location

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Description

Locations.processPresenceMessage builds each update event from the member returned by space.members.getByConnectionId(). That member comes from presence.get(), which holds the most recent presence state rather than the state at the time of the message being processed.

When a member changes location quickly, the events for the earlier updates report the latest location as currentLocation. For example, updates to location1 and then location2 produce a first event with currentLocation: 'location2' and previousLocation: null, and a second event with the same current location.

This change takes currentLocation (and the location on the event's member) from the presence message being processed.

Testing

  • Adds a Locations test where presence already holds the second location when the first update is processed. It expects each event to report its own location.
  • The test fails without the change (1 failed of 9) and passes with it (9 passed). The other unit tests still pass (119 passed), and prettier --check and eslint are clean.

Run with:

npx vitest run src/Locations.test.ts

Fixes #367

@ttypic ttypic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for contribution!

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Location update events report the latest location instead of the location from each update

2 participants