Live location share - open latest location in map site (#8981)
* move getForwardableBeacon to beacon utils * move event transform type up * add helper to get shareable-as-locaion events * use getShareableLocationEvent in MessageContextMenu * test opening in maplink * fix bad copy pasted tests
This commit is contained in:
parent
0026e0462b
commit
ed92071046
10 changed files with 310 additions and 17 deletions
|
@ -35,7 +35,6 @@ import {
|
|||
canPinEvent,
|
||||
editEvent,
|
||||
isContentActionable,
|
||||
isLocationEvent,
|
||||
} from '../../../utils/EventUtils';
|
||||
import IconizedContextMenu, { IconizedContextMenuOption, IconizedContextMenuOptionList } from './IconizedContextMenu';
|
||||
import { ReadPinsEventId } from "../right_panel/types";
|
||||
|
@ -58,6 +57,7 @@ import { OpenForwardDialogPayload } from "../../../dispatcher/payloads/OpenForwa
|
|||
import { OpenReportEventDialogPayload } from "../../../dispatcher/payloads/OpenReportEventDialogPayload";
|
||||
import { createMapSiteLinkFromEvent } from '../../../utils/location';
|
||||
import { getForwardableEvent } from '../../../events/forward/getForwardableEvent';
|
||||
import { getShareableLocationEvent } from '../../../events/location/getShareableLocationEvent';
|
||||
|
||||
interface IProps extends IPosition {
|
||||
chevronFace: ChevronFace;
|
||||
|
@ -145,10 +145,6 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
|
|||
return content.pinned && Array.isArray(content.pinned) && content.pinned.includes(this.props.mxEvent.getId());
|
||||
}
|
||||
|
||||
private canOpenInMapSite(mxEvent: MatrixEvent): boolean {
|
||||
return isLocationEvent(mxEvent);
|
||||
}
|
||||
|
||||
private canEndPoll(mxEvent: MatrixEvent): boolean {
|
||||
return (
|
||||
M_POLL_START.matches(mxEvent.getType()) &&
|
||||
|
@ -369,8 +365,9 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
|
|||
}
|
||||
|
||||
let openInMapSiteButton: JSX.Element;
|
||||
if (this.canOpenInMapSite(mxEvent)) {
|
||||
const mapSiteLink = createMapSiteLinkFromEvent(mxEvent);
|
||||
const shareableLocationEvent = getShareableLocationEvent(mxEvent, cli);
|
||||
if (shareableLocationEvent) {
|
||||
const mapSiteLink = createMapSiteLinkFromEvent(shareableLocationEvent);
|
||||
openInMapSiteButton = (
|
||||
<IconizedContextMenuOption
|
||||
iconClassName="mx_MessageContextMenu_iconOpenInMapSite"
|
||||
|
|
|
@ -18,7 +18,7 @@ import { M_POLL_START } from "matrix-events-sdk";
|
|||
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
|
||||
import { MatrixEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { getForwardableBeaconEvent } from "./getForwardableBeacon";
|
||||
import { getShareableLocationEventForBeacon } from "../../utils/beacon/getShareableLocation";
|
||||
|
||||
/**
|
||||
* Get forwardable event for a given event
|
||||
|
@ -28,8 +28,11 @@ export const getForwardableEvent = (event: MatrixEvent, cli: MatrixClient): Matr
|
|||
if (M_POLL_START.matches(event.getType())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Live location beacons should forward their latest location as a static pin location
|
||||
// If the beacon is not live, or doesn't have a location forwarding is not allowed
|
||||
if (M_BEACON_INFO.matches(event.getType())) {
|
||||
return getForwardableBeaconEvent(event, cli);
|
||||
return getShareableLocationEventForBeacon(event, cli);
|
||||
}
|
||||
return event;
|
||||
};
|
||||
|
|
|
@ -16,4 +16,4 @@ limitations under the License.
|
|||
|
||||
import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
export type ForwardableEventTransformFunction = (event: MatrixEvent, cli: MatrixClient) => MatrixEvent | null;
|
||||
export type ActionableEventTransformFunction = (event: MatrixEvent, cli: MatrixClient) => MatrixEvent | null;
|
||||
|
|
18
src/events/index.ts
Normal file
18
src/events/index.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
export { getForwardableEvent } from './forward/getForwardableEvent';
|
||||
export { getShareableLocationEvent } from './location/getShareableLocationEvent';
|
36
src/events/location/getShareableLocationEvent.ts
Normal file
36
src/events/location/getShareableLocationEvent.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
|
||||
import { MatrixEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { getShareableLocationEventForBeacon } from "../../utils/beacon/getShareableLocation";
|
||||
import { isLocationEvent } from "../../utils/EventUtils";
|
||||
|
||||
/**
|
||||
* Get event that is shareable as a location
|
||||
* If an event does not have a shareable location, return null
|
||||
*/
|
||||
export const getShareableLocationEvent = (event: MatrixEvent, cli: MatrixClient): MatrixEvent | null => {
|
||||
if (isLocationEvent(event)) {
|
||||
return event;
|
||||
}
|
||||
|
||||
if (M_BEACON_INFO.matches(event.getType())) {
|
||||
return getShareableLocationEventForBeacon(event, cli);
|
||||
}
|
||||
return null;
|
||||
};
|
19
src/events/types.ts
Normal file
19
src/events/types.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
export type ActionableEventTransformFunction = (event: MatrixEvent, cli: MatrixClient) => MatrixEvent | null;
|
|
@ -14,15 +14,18 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { getBeaconInfoIdentifier } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { ForwardableEventTransformFunction } from "./types";
|
||||
import {
|
||||
MatrixClient,
|
||||
MatrixEvent,
|
||||
getBeaconInfoIdentifier,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
||||
/**
|
||||
* Live location beacons should forward their latest location as a static pin location
|
||||
* If the beacon is not live, or doesn't have a location forwarding is not allowed
|
||||
* Beacons should only have shareable locations (open in external mapping tool, forward)
|
||||
* when they are live and have a location
|
||||
* If not live, returns null
|
||||
*/
|
||||
export const getForwardableBeaconEvent: ForwardableEventTransformFunction = (event, cli) => {
|
||||
export const getShareableLocationEventForBeacon = (event: MatrixEvent, cli: MatrixClient): MatrixEvent | null => {
|
||||
const room = cli.getRoom(event.getRoomId());
|
||||
const beacon = room.currentState.beacons?.get(getBeaconInfoIdentifier(event));
|
||||
const latestLocationEvent = beacon?.latestLocationEvent;
|
Loading…
Add table
Add a link
Reference in a new issue