Live location sharing: fix safari timestamps pt 2 (#8443)
* handle safari cocoa core data timestamps Signed-off-by: Kerry Archibald <kerrya@element.io> * actually fix safari timestamp issue properly Signed-off-by: Kerry Archibald <kerrya@element.io> * actually fix safari timestamp issue properly Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
fddbc429a9
commit
e233cf5061
3 changed files with 11 additions and 7 deletions
|
@ -114,7 +114,8 @@ export const getGeoUri = (position: GenericPosition): string => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mapGeolocationPositionToTimedGeo = (position: GeolocationPosition): TimedGeoUri => {
|
export const mapGeolocationPositionToTimedGeo = (position: GeolocationPosition): TimedGeoUri => {
|
||||||
return { timestamp: position.timestamp, geoUri: getGeoUri(genericPositionFromGeolocation(position)) };
|
const genericPosition = genericPositionFromGeolocation(position);
|
||||||
|
return { timestamp: genericPosition.timestamp, geoUri: getGeoUri(genericPosition) };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,7 +37,6 @@ import {
|
||||||
} from "../test-utils";
|
} from "../test-utils";
|
||||||
import {
|
import {
|
||||||
makeBeaconInfoEvent,
|
makeBeaconInfoEvent,
|
||||||
makeGeolocationPosition,
|
|
||||||
mockGeolocation,
|
mockGeolocation,
|
||||||
watchPositionMockImplementation,
|
watchPositionMockImplementation,
|
||||||
} from "../test-utils/beacon";
|
} from "../test-utils/beacon";
|
||||||
|
@ -70,7 +69,6 @@ describe('OwnBeaconStore', () => {
|
||||||
const room2Id = '$room2:server.org';
|
const room2Id = '$room2:server.org';
|
||||||
|
|
||||||
// returned by default geolocation mocks
|
// returned by default geolocation mocks
|
||||||
const defaultLocation = makeGeolocationPosition({});
|
|
||||||
const defaultLocationUri = 'geo:54.001927,-8.253491;u=1';
|
const defaultLocationUri = 'geo:54.001927,-8.253491;u=1';
|
||||||
|
|
||||||
// beacon_info events
|
// beacon_info events
|
||||||
|
@ -245,7 +243,7 @@ describe('OwnBeaconStore', () => {
|
||||||
expect(mockClient.sendEvent).not.toHaveBeenCalled();
|
expect(mockClient.sendEvent).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does geolocation and sends location immediatley when user has live beacons', async () => {
|
it('does geolocation and sends location immediately when user has live beacons', async () => {
|
||||||
localStorageGetSpy.mockReturnValue(JSON.stringify([
|
localStorageGetSpy.mockReturnValue(JSON.stringify([
|
||||||
alicesRoom1BeaconInfo.getId(),
|
alicesRoom1BeaconInfo.getId(),
|
||||||
alicesRoom2BeaconInfo.getId(),
|
alicesRoom2BeaconInfo.getId(),
|
||||||
|
@ -261,12 +259,12 @@ describe('OwnBeaconStore', () => {
|
||||||
expect(mockClient.sendEvent).toHaveBeenCalledWith(
|
expect(mockClient.sendEvent).toHaveBeenCalledWith(
|
||||||
room1Id,
|
room1Id,
|
||||||
M_BEACON.name,
|
M_BEACON.name,
|
||||||
makeBeaconContent(defaultLocationUri, defaultLocation.timestamp, alicesRoom1BeaconInfo.getId()),
|
makeBeaconContent(defaultLocationUri, now, alicesRoom1BeaconInfo.getId()),
|
||||||
);
|
);
|
||||||
expect(mockClient.sendEvent).toHaveBeenCalledWith(
|
expect(mockClient.sendEvent).toHaveBeenCalledWith(
|
||||||
room2Id,
|
room2Id,
|
||||||
M_BEACON.name,
|
M_BEACON.name,
|
||||||
makeBeaconContent(defaultLocationUri, defaultLocation.timestamp, alicesRoom2BeaconInfo.getId()),
|
makeBeaconContent(defaultLocationUri, now, alicesRoom2BeaconInfo.getId()),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,11 +34,16 @@ describe('geolocation utilities', () => {
|
||||||
let geolocation;
|
let geolocation;
|
||||||
const defaultPosition = makeGeolocationPosition({});
|
const defaultPosition = makeGeolocationPosition({});
|
||||||
|
|
||||||
|
// 14.03.2022 16:15
|
||||||
|
const now = 1647270879403;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
geolocation = mockGeolocation();
|
geolocation = mockGeolocation();
|
||||||
|
jest.spyOn(Date, 'now').mockReturnValue(now);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
jest.spyOn(Date, 'now').mockRestore();
|
||||||
jest.spyOn(logger, 'error').mockRestore();
|
jest.spyOn(logger, 'error').mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -136,7 +141,7 @@ describe('geolocation utilities', () => {
|
||||||
describe('mapGeolocationPositionToTimedGeo()', () => {
|
describe('mapGeolocationPositionToTimedGeo()', () => {
|
||||||
it('maps geolocation position correctly', () => {
|
it('maps geolocation position correctly', () => {
|
||||||
expect(mapGeolocationPositionToTimedGeo(defaultPosition)).toEqual({
|
expect(mapGeolocationPositionToTimedGeo(defaultPosition)).toEqual({
|
||||||
timestamp: 1647256791840, geoUri: 'geo:54.001927,-8.253491;u=1',
|
timestamp: now, geoUri: 'geo:54.001927,-8.253491;u=1',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue