Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Fix sending locations into threads and fix i18n #7943

Merged
merged 3 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/views/location/LocationButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
import React, { ReactElement, SyntheticEvent, useContext } from 'react';
import classNames from 'classnames';
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
import { IEventRelation } from 'matrix-js-sdk/src/models/event';

import { _t } from '../../../languageHandler';
import { CollapsibleButton } from '../rooms/CollapsibleButton';
Expand All @@ -28,9 +29,10 @@ interface IProps {
roomId: string;
sender: RoomMember;
menuPosition: AboveLeftOf;
relation?: IEventRelation;
}

export const LocationButton: React.FC<IProps> = ({ roomId, sender, menuPosition }) => {
export const LocationButton: React.FC<IProps> = ({ roomId, sender, menuPosition, relation }) => {
const overflowMenuCloser = useContext(OverflowMenuContext);
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();

Expand All @@ -49,7 +51,9 @@ export const LocationButton: React.FC<IProps> = ({ roomId, sender, menuPosition
onFinished={_onFinished}
sender={sender}
roomId={roomId}
openMenu={openMenu} />;
openMenu={openMenu}
relation={relation}
/>;
}

const className = classNames(
Expand Down
7 changes: 2 additions & 5 deletions src/components/views/location/LocationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { tileServerFromWellKnown } from '../../../utils/WellKnownUtils';

export interface ILocationPickerProps {
sender: RoomMember;
onChoose(uri: string, ts: number): boolean;
onChoose(uri: string, ts: number): unknown;
onFinished(ev?: SyntheticEvent): void;
}

Expand Down Expand Up @@ -159,10 +159,7 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
private onOk = () => {
const position = this.state.position;

this.props.onChoose(
position ? getGeoUri(position) : undefined,
position ? position.timestamp : undefined,
);
this.props.onChoose(position ? getGeoUri(position) : undefined, position?.timestamp);
this.props.onFinished();
};

Expand Down
11 changes: 9 additions & 2 deletions src/components/views/location/LocationShareMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

import React, { SyntheticEvent, useContext, useState } from 'react';
import { Room } from 'matrix-js-sdk/src/models/room';
import { IEventRelation } from 'matrix-js-sdk/src/models/event';

import MatrixClientContext from '../../../contexts/MatrixClientContext';
import ContextMenu, { AboveLeftOf } from '../../structures/ContextMenu';
Expand All @@ -29,6 +30,7 @@ type Props = Omit<ILocationPickerProps, 'onChoose'> & {
menuPosition: AboveLeftOf;
openMenu: () => void;
roomId: Room["roomId"];
relation?: IEventRelation;
};

const getEnabledShareTypes = (): LocationShareType[] => {
Expand All @@ -43,7 +45,12 @@ const getEnabledShareTypes = (): LocationShareType[] => {
};

const LocationShareMenu: React.FC<Props> = ({
menuPosition, onFinished, sender, roomId, openMenu,
menuPosition,
onFinished,
sender,
roomId,
openMenu,
relation,
}) => {
const matrixClient = useContext(MatrixClientContext);
const enabledShareTypes = getEnabledShareTypes();
Expand All @@ -60,7 +67,7 @@ const LocationShareMenu: React.FC<Props> = ({
<div className="mx_LocationShareMenu">
{ shareType ? <LocationPicker
sender={sender}
onChoose={shareLocation(matrixClient, roomId, openMenu)}
onChoose={shareLocation(matrixClient, roomId, relation, openMenu)}
onFinished={onFinished}
/>
:
Expand Down
62 changes: 34 additions & 28 deletions src/components/views/location/shareLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,49 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { RelationType } from "matrix-js-sdk/src/@types/event";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { makeLocationContent } from "matrix-js-sdk/src/content-helpers";
import { logger } from "matrix-js-sdk/src/logger";
import { IEventRelation } from "matrix-js-sdk/src/models/event";

import { _t } from "../../../languageHandler";
import Modal from "../../../Modal";
import QuestionDialog from "../dialogs/QuestionDialog";
import SdkConfig from "../../../SdkConfig";

export const shareLocation = (client: MatrixClient, roomId: string, openMenu: () => void) =>
(uri: string, ts: number) => {
if (!uri) return false;
try {
const text = textForLocation(uri, ts, null);
client.sendMessage(
roomId,
makeLocationContent(text, uri, ts, null),
);
} catch (e) {
logger.error("We couldn’t send your location", e);
export const shareLocation = (
client: MatrixClient,
roomId: string,
relation: IEventRelation | undefined,
openMenu: () => void,
) => async (uri: string, ts: number) => {
if (!uri) return false;
try {
const text = textForLocation(uri, ts, null);
const threadId = relation?.rel_type === RelationType.Thread ? relation.event_id : null;
await client.sendMessage(roomId, threadId, makeLocationContent(text, uri, ts, null));
} catch (e) {
logger.error("We couldn't send your location", e);

const analyticsAction = 'We couldn’t send your location';
const params = {
title: _t("We couldn’t send your location"),
description: _t(
"Element could not send your location. Please try again later."),
button: _t('Try again'),
cancelButton: _t('Cancel'),
onFinished: (tryAgain: boolean) => {
if (tryAgain) {
openMenu();
}
},
};
Modal.createTrackedDialog(analyticsAction, '', QuestionDialog, params);
}
return true;
};
const analyticsAction = "We couldn't send your location";
const params = {
title: _t("We couldn't send your location"),
description: _t("%(brand)s could not send your location. Please try again later.", {
brand: SdkConfig.get().brand,
}),
button: _t('Try again'),
cancelButton: _t('Cancel'),
onFinished: (tryAgain: boolean) => {
if (tryAgain) {
openMenu();
}
},
};
Modal.createTrackedDialog(analyticsAction, '', QuestionDialog, params);
}
return true;
};

export function textForLocation(
uri: string,
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/rooms/EventTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export default class EventTile extends React.Component<IProps, IState> {
thread,
threadReplyCount: thread?.length,
threadLastReply: thread?.replyToEvent,
threadLastSender: thread?.replyToEvent.sender,
threadLastSender: thread?.replyToEvent?.sender,
};

// don't do RR animations until we are mounted
Expand Down
1 change: 1 addition & 0 deletions src/components/views/rooms/MessageComposerButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ function showLocationButton(
? <LocationButton
key="location"
roomId={roomId}
relation={props.relation}
sender={room.getMember(matrixClient.getUserId())}
menuPosition={props.menuPosition}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2177,8 +2177,8 @@
"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.",
"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.",
"We couldn't send your location": "We couldn't send your location",
"%(brand)s could not send your location. Please try again later.": "%(brand)s could not send your location. Please try again later.",
"My current location": "My current location",
"My live location": "My live location",
"Drop a Pin": "Drop a Pin",
Expand Down