Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit e233cf5

Browse files
author
Kerry
authored
Live location sharing: fix safari timestamps pt 2 (#8443)
* handle safari cocoa core data timestamps Signed-off-by: Kerry Archibald <[email protected]> * actually fix safari timestamp issue properly Signed-off-by: Kerry Archibald <[email protected]> * actually fix safari timestamp issue properly Signed-off-by: Kerry Archibald <[email protected]>
1 parent fddbc42 commit e233cf5

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/utils/beacon/geolocation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export const getGeoUri = (position: GenericPosition): string => {
114114
};
115115

116116
export const mapGeolocationPositionToTimedGeo = (position: GeolocationPosition): TimedGeoUri => {
117-
return { timestamp: position.timestamp, geoUri: getGeoUri(genericPositionFromGeolocation(position)) };
117+
const genericPosition = genericPositionFromGeolocation(position);
118+
return { timestamp: genericPosition.timestamp, geoUri: getGeoUri(genericPosition) };
118119
};
119120

120121
/**

test/stores/OwnBeaconStore-test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {
3737
} from "../test-utils";
3838
import {
3939
makeBeaconInfoEvent,
40-
makeGeolocationPosition,
4140
mockGeolocation,
4241
watchPositionMockImplementation,
4342
} from "../test-utils/beacon";
@@ -70,7 +69,6 @@ describe('OwnBeaconStore', () => {
7069
const room2Id = '$room2:server.org';
7170

7271
// returned by default geolocation mocks
73-
const defaultLocation = makeGeolocationPosition({});
7472
const defaultLocationUri = 'geo:54.001927,-8.253491;u=1';
7573

7674
// beacon_info events
@@ -245,7 +243,7 @@ describe('OwnBeaconStore', () => {
245243
expect(mockClient.sendEvent).not.toHaveBeenCalled();
246244
});
247245

248-
it('does geolocation and sends location immediatley when user has live beacons', async () => {
246+
it('does geolocation and sends location immediately when user has live beacons', async () => {
249247
localStorageGetSpy.mockReturnValue(JSON.stringify([
250248
alicesRoom1BeaconInfo.getId(),
251249
alicesRoom2BeaconInfo.getId(),
@@ -261,12 +259,12 @@ describe('OwnBeaconStore', () => {
261259
expect(mockClient.sendEvent).toHaveBeenCalledWith(
262260
room1Id,
263261
M_BEACON.name,
264-
makeBeaconContent(defaultLocationUri, defaultLocation.timestamp, alicesRoom1BeaconInfo.getId()),
262+
makeBeaconContent(defaultLocationUri, now, alicesRoom1BeaconInfo.getId()),
265263
);
266264
expect(mockClient.sendEvent).toHaveBeenCalledWith(
267265
room2Id,
268266
M_BEACON.name,
269-
makeBeaconContent(defaultLocationUri, defaultLocation.timestamp, alicesRoom2BeaconInfo.getId()),
267+
makeBeaconContent(defaultLocationUri, now, alicesRoom2BeaconInfo.getId()),
270268
);
271269
});
272270
});

test/utils/beacon/geolocation-test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ describe('geolocation utilities', () => {
3434
let geolocation;
3535
const defaultPosition = makeGeolocationPosition({});
3636

37+
// 14.03.2022 16:15
38+
const now = 1647270879403;
39+
3740
beforeEach(() => {
3841
geolocation = mockGeolocation();
42+
jest.spyOn(Date, 'now').mockReturnValue(now);
3943
});
4044

4145
afterEach(() => {
46+
jest.spyOn(Date, 'now').mockRestore();
4247
jest.spyOn(logger, 'error').mockRestore();
4348
});
4449

@@ -136,7 +141,7 @@ describe('geolocation utilities', () => {
136141
describe('mapGeolocationPositionToTimedGeo()', () => {
137142
it('maps geolocation position correctly', () => {
138143
expect(mapGeolocationPositionToTimedGeo(defaultPosition)).toEqual({
139-
timestamp: 1647256791840, geoUri: 'geo:54.001927,-8.253491;u=1',
144+
timestamp: now, geoUri: 'geo:54.001927,-8.253491;u=1',
140145
});
141146
});
142147
});

0 commit comments

Comments
 (0)