Show an error dialog if location permission is denied (#7531)

This commit is contained in:
Andy Balaam 2022-01-13 14:38:04 +00:00 committed by GitHub
parent 25cd1a8a43
commit 22c2aa37d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View file

@ -25,6 +25,8 @@ import { _t } from '../../../languageHandler';
import { replaceableComponent } from "../../../utils/replaceableComponent"; import { replaceableComponent } from "../../../utils/replaceableComponent";
import MemberAvatar from '../avatars/MemberAvatar'; import MemberAvatar from '../avatars/MemberAvatar';
import MatrixClientContext from '../../../contexts/MatrixClientContext'; import MatrixClientContext from '../../../contexts/MatrixClientContext';
import Modal from '../../../Modal';
import ErrorDialog from '../dialogs/ErrorDialog';
interface IProps { interface IProps {
sender: RoomMember; sender: RoomMember;
@ -106,6 +108,20 @@ class LocationPicker extends React.Component<IProps, IState> {
this.geolocate.trigger(); this.geolocate.trigger();
}); });
this.geolocate.on('error', (e: GeolocationPositionError) => {
this.props.onFinished();
logger.error("Could not fetch location", e);
Modal.createTrackedDialog(
'Could not fetch location',
'',
ErrorDialog,
{
title: _t("Could not fetch location"),
description: positionFailureMessage(e.code),
},
);
});
this.geolocate.on('geolocate', this.onGeolocate); this.geolocate.on('geolocate', this.onGeolocate);
} catch (e) { } catch (e) {
logger.error("Failed to render map", e.error); logger.error("Failed to render map", e.error);
@ -197,3 +213,21 @@ export function getGeoUri(position: GeolocationPosition): string {
} }
export default LocationPicker; export default LocationPicker;
function positionFailureMessage(code: number): string {
switch (code) {
case 1: return _t(
"Element was denied permission to fetch your location. " +
"Please allow location access in your browser settings.",
);
case 2: return _t(
"Failed to fetch your location. Please try again later.",
);
case 3: return _t(
"Timed out trying to fetch your location. Please try again later.",
);
case 4: return _t(
"Unknown error fetching location. Please try again later.",
);
}
}

View file

@ -2137,6 +2137,11 @@
"Share location": "Share location", "Share location": "Share location",
"We couldnt send your location": "We couldnt send your location", "We couldnt send your location": "We couldnt send your location",
"Element could not send your location. Please try again later.": "Element could not send your location. Please try again later.", "Element could not send your location. Please try again later.": "Element could not send your location. Please try again later.",
"Could not fetch location": "Could not fetch location",
"Element was denied permission to fetch your location. Please allow location access in your browser settings.": "Element was denied permission to fetch your location. Please allow location access in your browser settings.",
"Failed to fetch your location. Please try again later.": "Failed to fetch your location. Please try again later.",
"Timed out trying to fetch your location. Please try again later.": "Timed out trying to fetch your location. Please try again later.",
"Unknown error fetching location. Please try again later.": "Unknown error fetching location. Please try again later.",
"Failed to load group members": "Failed to load group members", "Failed to load group members": "Failed to load group members",
"Filter community members": "Filter community members", "Filter community members": "Filter community members",
"Are you sure you want to remove '%(roomName)s' from %(groupId)s?": "Are you sure you want to remove '%(roomName)s' from %(groupId)s?", "Are you sure you want to remove '%(roomName)s' from %(groupId)s?": "Are you sure you want to remove '%(roomName)s' from %(groupId)s?",