Live location share - forward latest location (PSF-1044) (#8860)
* handle beacon location events in ForwardDialog * add transformer for forwarded events in MessageContextMenu * remove canForward * update snapshots for beacon model change * add comments * fix bad copy pasted test * add test for beacon locationswatcha-feature/make-nextcloud-documents-integration-a-local-widget
parent
0a90674e89
commit
b51ef246ab
@ -0,0 +1,34 @@ |
|||||||
|
/* |
||||||
|
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 { getBeaconInfoIdentifier } from "matrix-js-sdk/src/matrix"; |
||||||
|
|
||||||
|
import { ForwardableEventTransformFunction } from "./types"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 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 |
||||||
|
*/ |
||||||
|
export const getForwardableBeaconEvent: ForwardableEventTransformFunction = (event, cli) => { |
||||||
|
const room = cli.getRoom(event.getRoomId()); |
||||||
|
const beacon = room.currentState.beacons?.get(getBeaconInfoIdentifier(event)); |
||||||
|
const latestLocationEvent = beacon.latestLocationEvent; |
||||||
|
|
||||||
|
if (beacon.isLive && latestLocationEvent) { |
||||||
|
return latestLocationEvent; |
||||||
|
} |
||||||
|
return null; |
||||||
|
}; |
||||||
@ -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_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"; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get forwardable event for a given event |
||||||
|
* If an event is not forwardable return null |
||||||
|
*/ |
||||||
|
export const getForwardableEvent = (event: MatrixEvent, cli: MatrixClient): MatrixEvent | null => { |
||||||
|
if (M_POLL_START.matches(event.getType())) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
if (M_BEACON_INFO.matches(event.getType())) { |
||||||
|
return getForwardableBeaconEvent(event, cli); |
||||||
|
} |
||||||
|
return event; |
||||||
|
}; |
||||||
|
|
||||||
@ -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 ForwardableEventTransformFunction = (event: MatrixEvent, cli: MatrixClient) => MatrixEvent | null; |
||||||
Loading…
Reference in new issue