mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 01:35:49 +03:00
Fix sending locations into threads and fix i18n (#7943)
This commit is contained in:
parent
0f4125dfd5
commit
3c858a723b
7 changed files with 55 additions and 40 deletions
|
@ -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';
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
@ -29,6 +30,7 @@ type Props = Omit<ILocationPickerProps, 'onChoose'> & {
|
|||
menuPosition: AboveLeftOf;
|
||||
openMenu: () => void;
|
||||
roomId: Room["roomId"];
|
||||
relation?: IEventRelation;
|
||||
};
|
||||
|
||||
const getEnabledShareTypes = (): LocationShareType[] => {
|
||||
|
@ -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();
|
||||
|
@ -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}
|
||||
/>
|
||||
:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -361,6 +361,7 @@ function showLocationButton(
|
|||
? <LocationButton
|
||||
key="location"
|
||||
roomId={roomId}
|
||||
relation={props.relation}
|
||||
sender={room.getMember(matrixClient.getUserId())}
|
||||
menuPosition={props.menuPosition}
|
||||
/>
|
||||
|
|
|
@ -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 couldn’t send your location": "We couldn’t 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",
|
||||
|
|
Loading…
Reference in a new issue