Apply strictNullChecks to src/utils/*!exportUtils (#10455

* Apply `strictNullChecks` to `src/utils/exportUtils`

* strict fix

* fix strictNullChecks issues in some utils

* fix error message

* test coverage

* lint

* more strictNullChecks

* small optimisation for getUniqueRoomsWithIndividuals

* tidy

* test coverage
This commit is contained in:
Kerry
2023-04-03 20:26:55 +12:00
committed by GitHub
parent 4ed6e39067
commit 81a4498a8f
18 changed files with 143 additions and 81 deletions

View File

@@ -85,12 +85,14 @@ export const createMapSiteLinkFromEvent = (event: MatrixEvent): string | null =>
if (mLocation !== undefined) {
const uri = mLocation["uri"];
if (uri !== undefined) {
return makeMapSiteLink(parseGeoUri(uri));
const geoCoords = parseGeoUri(uri);
return geoCoords ? makeMapSiteLink(geoCoords) : null;
}
} else {
const geoUri = content["geo_uri"];
if (geoUri) {
return makeMapSiteLink(parseGeoUri(geoUri));
const geoCoords = parseGeoUri(geoUri);
return geoCoords ? makeMapSiteLink(geoCoords) : null;
}
}
return null;

View File

@@ -28,16 +28,23 @@ export const parseGeoUri = (uri: string): GeolocationCoordinates | undefined =>
if (!m) return;
const parts = m[1].split(";");
const coords = parts[0].split(",");
let uncertainty: number | null;
let uncertainty: number | null | undefined = undefined;
for (const param of parts.slice(1)) {
const m = param.match(/u=(.*)/);
if (m) uncertainty = parse(m[1]);
}
const latitude = parse(coords[0]);
const longitude = parse(coords[1]);
if (latitude === null || longitude === null) {
return;
}
return {
latitude: parse(coords[0]),
longitude: parse(coords[1]),
latitude: latitude!,
longitude: longitude!,
altitude: parse(coords[2]),
accuracy: uncertainty,
accuracy: uncertainty!,
altitudeAccuracy: null,
heading: null,
speed: null,