mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 09:46:09 +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 React, { ReactElement, SyntheticEvent, useContext } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
||||||
|
import { IEventRelation } from 'matrix-js-sdk/src/models/event';
|
||||||
|
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import { CollapsibleButton } from '../rooms/CollapsibleButton';
|
import { CollapsibleButton } from '../rooms/CollapsibleButton';
|
||||||
|
@ -28,9 +29,10 @@ interface IProps {
|
||||||
roomId: string;
|
roomId: string;
|
||||||
sender: RoomMember;
|
sender: RoomMember;
|
||||||
menuPosition: AboveLeftOf;
|
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 overflowMenuCloser = useContext(OverflowMenuContext);
|
||||||
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();
|
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();
|
||||||
|
|
||||||
|
@ -49,7 +51,9 @@ export const LocationButton: React.FC<IProps> = ({ roomId, sender, menuPosition
|
||||||
onFinished={_onFinished}
|
onFinished={_onFinished}
|
||||||
sender={sender}
|
sender={sender}
|
||||||
roomId={roomId}
|
roomId={roomId}
|
||||||
openMenu={openMenu} />;
|
openMenu={openMenu}
|
||||||
|
relation={relation}
|
||||||
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const className = classNames(
|
const className = classNames(
|
||||||
|
|
|
@ -32,7 +32,7 @@ import { tileServerFromWellKnown } from '../../../utils/WellKnownUtils';
|
||||||
|
|
||||||
export interface ILocationPickerProps {
|
export interface ILocationPickerProps {
|
||||||
sender: RoomMember;
|
sender: RoomMember;
|
||||||
onChoose(uri: string, ts: number): boolean;
|
onChoose(uri: string, ts: number): unknown;
|
||||||
onFinished(ev?: SyntheticEvent): void;
|
onFinished(ev?: SyntheticEvent): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,10 +159,7 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
|
||||||
private onOk = () => {
|
private onOk = () => {
|
||||||
const position = this.state.position;
|
const position = this.state.position;
|
||||||
|
|
||||||
this.props.onChoose(
|
this.props.onChoose(position ? getGeoUri(position) : undefined, position?.timestamp);
|
||||||
position ? getGeoUri(position) : undefined,
|
|
||||||
position ? position.timestamp : undefined,
|
|
||||||
);
|
|
||||||
this.props.onFinished();
|
this.props.onFinished();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import React, { SyntheticEvent, useContext, useState } from 'react';
|
import React, { SyntheticEvent, useContext, useState } from 'react';
|
||||||
import { Room } from 'matrix-js-sdk/src/models/room';
|
import { Room } from 'matrix-js-sdk/src/models/room';
|
||||||
|
import { IEventRelation } from 'matrix-js-sdk/src/models/event';
|
||||||
|
|
||||||
import MatrixClientContext from '../../../contexts/MatrixClientContext';
|
import MatrixClientContext from '../../../contexts/MatrixClientContext';
|
||||||
import ContextMenu, { AboveLeftOf } from '../../structures/ContextMenu';
|
import ContextMenu, { AboveLeftOf } from '../../structures/ContextMenu';
|
||||||
|
@ -29,6 +30,7 @@ type Props = Omit<ILocationPickerProps, 'onChoose'> & {
|
||||||
menuPosition: AboveLeftOf;
|
menuPosition: AboveLeftOf;
|
||||||
openMenu: () => void;
|
openMenu: () => void;
|
||||||
roomId: Room["roomId"];
|
roomId: Room["roomId"];
|
||||||
|
relation?: IEventRelation;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getEnabledShareTypes = (): LocationShareType[] => {
|
const getEnabledShareTypes = (): LocationShareType[] => {
|
||||||
|
@ -43,7 +45,12 @@ const getEnabledShareTypes = (): LocationShareType[] => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const LocationShareMenu: React.FC<Props> = ({
|
const LocationShareMenu: React.FC<Props> = ({
|
||||||
menuPosition, onFinished, sender, roomId, openMenu,
|
menuPosition,
|
||||||
|
onFinished,
|
||||||
|
sender,
|
||||||
|
roomId,
|
||||||
|
openMenu,
|
||||||
|
relation,
|
||||||
}) => {
|
}) => {
|
||||||
const matrixClient = useContext(MatrixClientContext);
|
const matrixClient = useContext(MatrixClientContext);
|
||||||
const enabledShareTypes = getEnabledShareTypes();
|
const enabledShareTypes = getEnabledShareTypes();
|
||||||
|
@ -60,7 +67,7 @@ const LocationShareMenu: React.FC<Props> = ({
|
||||||
<div className="mx_LocationShareMenu">
|
<div className="mx_LocationShareMenu">
|
||||||
{ shareType ? <LocationPicker
|
{ shareType ? <LocationPicker
|
||||||
sender={sender}
|
sender={sender}
|
||||||
onChoose={shareLocation(matrixClient, roomId, openMenu)}
|
onChoose={shareLocation(matrixClient, roomId, relation, openMenu)}
|
||||||
onFinished={onFinished}
|
onFinished={onFinished}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
|
|
|
@ -14,43 +14,49 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { RelationType } from "matrix-js-sdk/src/@types/event";
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import { makeLocationContent } from "matrix-js-sdk/src/content-helpers";
|
import { makeLocationContent } from "matrix-js-sdk/src/content-helpers";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
import { IEventRelation } from "matrix-js-sdk/src/models/event";
|
||||||
|
|
||||||
import { _t } from "../../../languageHandler";
|
import { _t } from "../../../languageHandler";
|
||||||
import Modal from "../../../Modal";
|
import Modal from "../../../Modal";
|
||||||
import QuestionDialog from "../dialogs/QuestionDialog";
|
import QuestionDialog from "../dialogs/QuestionDialog";
|
||||||
|
import SdkConfig from "../../../SdkConfig";
|
||||||
|
|
||||||
export const shareLocation = (client: MatrixClient, roomId: string, openMenu: () => void) =>
|
export const shareLocation = (
|
||||||
(uri: string, ts: number) => {
|
client: MatrixClient,
|
||||||
if (!uri) return false;
|
roomId: string,
|
||||||
try {
|
relation: IEventRelation | undefined,
|
||||||
const text = textForLocation(uri, ts, null);
|
openMenu: () => void,
|
||||||
client.sendMessage(
|
) => async (uri: string, ts: number) => {
|
||||||
roomId,
|
if (!uri) return false;
|
||||||
makeLocationContent(text, uri, ts, null),
|
try {
|
||||||
);
|
const text = textForLocation(uri, ts, null);
|
||||||
} catch (e) {
|
const threadId = relation?.rel_type === RelationType.Thread ? relation.event_id : null;
|
||||||
logger.error("We couldn’t send your location", e);
|
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 analyticsAction = "We couldn't send your location";
|
||||||
const params = {
|
const params = {
|
||||||
title: _t("We couldn’t send your location"),
|
title: _t("We couldn't send your location"),
|
||||||
description: _t(
|
description: _t("%(brand)s could not send your location. Please try again later.", {
|
||||||
"Element could not send your location. Please try again later."),
|
brand: SdkConfig.get().brand,
|
||||||
button: _t('Try again'),
|
}),
|
||||||
cancelButton: _t('Cancel'),
|
button: _t('Try again'),
|
||||||
onFinished: (tryAgain: boolean) => {
|
cancelButton: _t('Cancel'),
|
||||||
if (tryAgain) {
|
onFinished: (tryAgain: boolean) => {
|
||||||
openMenu();
|
if (tryAgain) {
|
||||||
}
|
openMenu();
|
||||||
},
|
}
|
||||||
};
|
},
|
||||||
Modal.createTrackedDialog(analyticsAction, '', QuestionDialog, params);
|
};
|
||||||
}
|
Modal.createTrackedDialog(analyticsAction, '', QuestionDialog, params);
|
||||||
return true;
|
}
|
||||||
};
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
export function textForLocation(
|
export function textForLocation(
|
||||||
uri: string,
|
uri: string,
|
||||||
|
|
|
@ -399,7 +399,7 @@ export default class EventTile extends React.Component<IProps, IState> {
|
||||||
thread,
|
thread,
|
||||||
threadReplyCount: thread?.length,
|
threadReplyCount: thread?.length,
|
||||||
threadLastReply: thread?.replyToEvent,
|
threadLastReply: thread?.replyToEvent,
|
||||||
threadLastSender: thread?.replyToEvent.sender,
|
threadLastSender: thread?.replyToEvent?.sender,
|
||||||
};
|
};
|
||||||
|
|
||||||
// don't do RR animations until we are mounted
|
// don't do RR animations until we are mounted
|
||||||
|
|
|
@ -361,6 +361,7 @@ function showLocationButton(
|
||||||
? <LocationButton
|
? <LocationButton
|
||||||
key="location"
|
key="location"
|
||||||
roomId={roomId}
|
roomId={roomId}
|
||||||
|
relation={props.relation}
|
||||||
sender={room.getMember(matrixClient.getUserId())}
|
sender={room.getMember(matrixClient.getUserId())}
|
||||||
menuPosition={props.menuPosition}
|
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.",
|
"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.",
|
"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.",
|
"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",
|
"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.",
|
"%(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 current location": "My current location",
|
||||||
"My live location": "My live location",
|
"My live location": "My live location",
|
||||||
"Drop a Pin": "Drop a Pin",
|
"Drop a Pin": "Drop a Pin",
|
||||||
|
|
Loading…
Reference in a new issue