Live location share - explicitly stop beacons replaced beacons (PSG-544) (#8933)

* explicitly stop beacons before creating new ones

* remove unnecessary optional chain
This commit is contained in:
Kerry 2022-06-30 09:33:51 +02:00 committed by GitHub
parent d439871ea1
commit 4eab0deeb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

View file

@ -106,7 +106,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
* ids of live beacons
* ordered by creation time descending
*/
private liveBeaconIds = [];
private liveBeaconIds: BeaconIdentifier[] = [];
private locationInterval: number;
private geolocationError: GeolocationError | undefined;
private clearPositionWatch: ClearWatchCallback | undefined;
@ -392,6 +392,12 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
roomId: Room['roomId'],
beaconInfoContent: MBeaconInfoEventContent,
): Promise<void> => {
// explicitly stop any live beacons this user has
// to ensure they remain stopped
// if the new replacing beacon is redacted
const existingLiveBeaconIdsForRoom = this.getLiveBeaconIds(roomId);
await Promise.all(existingLiveBeaconIdsForRoom.map(beaconId => this.stopBeacon(beaconId)));
// eslint-disable-next-line camelcase
const { event_id } = await this.matrixClient.unstable_createLiveBeacon(
roomId,