Show an error dialog if we fail to send location (#7528)

This commit is contained in:
Andy Balaam 2022-01-13 13:23:00 +00:00 committed by GitHub
parent 44b9b6ca57
commit 25cd1a8a43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 23 deletions

View file

@ -19,9 +19,7 @@ import { MatrixEvent, IEventRelation } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { RelationType } from 'matrix-js-sdk/src/@types/event';
import { logger } from "matrix-js-sdk/src/logger";
import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls";
import { makeLocationContent } from "matrix-js-sdk/src/content-helpers";
import { _t } from '../../../languageHandler';
import { MatrixClientPeg } from '../../../MatrixClientPeg';
@ -60,7 +58,7 @@ import ErrorDialog from "../dialogs/ErrorDialog";
import PollCreateDialog from "../elements/PollCreateDialog";
import { SettingUpdatedPayload } from "../../../dispatcher/payloads/SettingUpdatedPayload";
import { CollapsibleButton, ICollapsibleButtonProps } from './CollapsibleButton';
import { LocationButton, textForLocation } from '../location/LocationButton';
import LocationButton from '../location/LocationButton';
let instanceCount = 0;
const NARROW_MODE_BREAKPOINT = 500;
@ -452,20 +450,6 @@ export default class MessageComposer extends React.Component<IProps, IState> {
return true;
};
private shareLocation = (uri: string, ts: number): boolean => {
if (!uri) return false;
try {
const text = textForLocation(uri, ts, null);
MatrixClientPeg.get().sendMessage(
this.props.room.roomId,
makeLocationContent(text, uri, ts, null),
);
} catch (e) {
logger.error("Error sending location:", e);
}
return true;
};
private sendMessage = async () => {
if (this.state.haveRecording && this.voiceRecordingButton.current) {
// There shouldn't be any text message to send when a voice recording is active, so
@ -530,11 +514,14 @@ export default class MessageComposer extends React.Component<IProps, IState> {
<UploadButton key="controls_upload" roomId={this.props.room.roomId} relation={this.props.relation} />,
);
if (SettingsStore.getValue("feature_location_share")) {
const sender = this.props.room.getMember(
MatrixClientPeg.get().getUserId(),
);
buttons.push(
<LocationButton
sender={this.props.room.getMember(MatrixClientPeg.get().getUserId())}
key="location"
shareLocation={this.shareLocation}
roomId={this.props.room.roomId}
sender={sender}
menuPosition={menuPosition}
narrowMode={this.state.narrowMode}
/>,