Live Location Sharing - left panel warning with error (#8201)

* add error style to left panel beacon warning

Signed-off-by: Kerry Archibald <kerrya@element.io>

* test

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add beacon sort util

* link to latest beacon room from left panel warning

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-03-31 13:51:44 +02:00 committed by GitHub
parent 1175226bcb
commit 4922e19b5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 289 additions and 24 deletions

View file

@ -38,6 +38,7 @@ import {
ClearWatchCallback,
GeolocationError,
mapGeolocationPositionToTimedGeo,
sortBeaconsByLatestCreation,
TimedGeoUri,
watchPosition,
} from "../utils/beacon";
@ -73,6 +74,10 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
* Reset on successful publish of location
*/
public readonly beaconWireErrorCounts = new Map<string, number>();
/**
* ids of live beacons
* ordered by creation time descending
*/
private liveBeaconIds = [];
private locationInterval: number;
private geolocationError: GeolocationError | undefined;
@ -126,17 +131,17 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
// we don't actually do anything here
}
public hasLiveBeacons(roomId?: string): boolean {
public hasLiveBeacons = (roomId?: string): boolean => {
return !!this.getLiveBeaconIds(roomId).length;
}
};
/**
* Some live beacon has a wire error
* Optionally filter by room
*/
public hasWireErrors(roomId?: string): boolean {
public hasWireErrors = (roomId?: string): boolean => {
return this.getLiveBeaconIds(roomId).some(this.beaconHasWireError);
}
};
/**
* If a beacon has failed to publish position
@ -157,16 +162,20 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
this.publishCurrentLocationToBeacons();
};
public getLiveBeaconIds(roomId?: string): string[] {
public getLiveBeaconIds = (roomId?: string): string[] => {
if (!roomId) {
return this.liveBeaconIds;
}
return this.liveBeaconIds.filter(beaconId => this.beaconsByRoomId.get(roomId)?.has(beaconId));
}
};
public getBeaconById(beaconId: string): Beacon | undefined {
public getLiveBeaconIdsWithWireError = (roomId?: string): string[] => {
return this.getLiveBeaconIds(roomId).filter(this.beaconHasWireError);
};
public getBeaconById = (beaconId: string): Beacon | undefined => {
return this.beacons.get(beaconId);
}
};
public stopBeacon = async (beaconInfoType: string): Promise<void> => {
const beacon = this.beacons.get(beaconInfoType);
@ -287,6 +296,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
const prevLiveBeaconIds = this.getLiveBeaconIds();
this.liveBeaconIds = [...this.beacons.values()]
.filter(beacon => beacon.isLive)
.sort(sortBeaconsByLatestCreation)
.map(beacon => beacon.identifier);
const diff = arrayDiff(prevLiveBeaconIds, this.liveBeaconIds);