Skip to content

Commit fc946ab

Browse files
author
Kerry
authored
expose latestLocationEvent on beacon model (#2467)
1 parent 9b843da commit fc946ab

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Diff for: spec/unit/models/beacon.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ describe('Beacon', () => {
492492

493493
// the newest valid location
494494
expect(beacon.latestLocationState).toEqual(expectedLatestLocation);
495+
expect(beacon.latestLocationEvent).toEqual(locations[1]);
495496
expect(emitSpy).toHaveBeenCalledWith(BeaconEvent.LocationUpdate, expectedLatestLocation);
496497
});
497498

@@ -510,6 +511,7 @@ describe('Beacon', () => {
510511
expect(beacon.latestLocationState).toEqual(expect.objectContaining({
511512
uri: 'geo:bar',
512513
}));
514+
expect(beacon.latestLocationEvent).toEqual(newerLocation);
513515

514516
const emitSpy = jest.spyOn(beacon, 'emit').mockClear();
515517

Diff for: src/models/beacon.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.N
5555
private _beaconInfo: BeaconInfoState;
5656
private _isLive: boolean;
5757
private livenessWatchTimeout: ReturnType<typeof setTimeout>;
58-
private _latestLocationState: BeaconLocationState | undefined;
58+
private _latestLocationEvent: MatrixEvent | undefined;
5959

6060
constructor(
6161
private rootEvent: MatrixEvent,
@@ -90,7 +90,11 @@ export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.N
9090
}
9191

9292
public get latestLocationState(): BeaconLocationState | undefined {
93-
return this._latestLocationState;
93+
return this._latestLocationEvent && parseBeaconContent(this._latestLocationEvent.getContent());
94+
}
95+
96+
public get latestLocationEvent(): MatrixEvent | undefined {
97+
return this._latestLocationEvent;
9498
}
9599

96100
public update(beaconInfoEvent: MatrixEvent): void {
@@ -168,13 +172,13 @@ export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.N
168172
const latestLocationEvent = validLocationEvents.sort(sortEventsByLatestContentTimestamp)?.[0];
169173

170174
if (latestLocationEvent) {
171-
this._latestLocationState = parseBeaconContent(latestLocationEvent.getContent());
175+
this._latestLocationEvent = latestLocationEvent;
172176
this.emit(BeaconEvent.LocationUpdate, this.latestLocationState);
173177
}
174178
}
175179

176180
private clearLatestLocation = () => {
177-
this._latestLocationState = undefined;
181+
this._latestLocationEvent = undefined;
178182
this.emit(BeaconEvent.LocationUpdate, this.latestLocationState);
179183
};
180184

0 commit comments

Comments
 (0)