This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 locations
- Loading branch information
Kerry
committed
Jun 17, 2022
1 parent
0a90674
commit b51ef24
Showing
12 changed files
with
292 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.