Live location share - redact related locations on beacon redaction (PSF-1151) (#8926)
* redact beacon locations on redaction * redact beacon locations on beacon info redaction * fussy import ordering * use real fake redaction in beaconbody test
This commit is contained in:
parent
1304ff18a5
commit
4486509d88
4 changed files with 172 additions and 4 deletions
|
@ -14,10 +14,18 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import { Beacon, BeaconEvent, MatrixEvent } from 'matrix-js-sdk/src/matrix';
|
||||
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
||||
import {
|
||||
Beacon,
|
||||
BeaconEvent,
|
||||
MatrixEvent,
|
||||
MatrixEventEvent,
|
||||
MatrixClient,
|
||||
RelationType,
|
||||
} from 'matrix-js-sdk/src/matrix';
|
||||
import { BeaconLocationState } from 'matrix-js-sdk/src/content-helpers';
|
||||
import { randomString } from 'matrix-js-sdk/src/randomstring';
|
||||
import { M_BEACON } from 'matrix-js-sdk/src/@types/beacon';
|
||||
|
||||
import MatrixClientContext from '../../../contexts/MatrixClientContext';
|
||||
import { useEventEmitterState } from '../../../hooks/useEventEmitter';
|
||||
|
@ -27,10 +35,11 @@ import { isBeaconWaitingToStart, useBeacon } from '../../../utils/beacon';
|
|||
import { isSelfLocation } from '../../../utils/location';
|
||||
import { BeaconDisplayStatus, getBeaconDisplayStatus } from '../beacon/displayStatus';
|
||||
import BeaconStatus from '../beacon/BeaconStatus';
|
||||
import OwnBeaconStatus from '../beacon/OwnBeaconStatus';
|
||||
import Map from '../location/Map';
|
||||
import MapFallback from '../location/MapFallback';
|
||||
import SmartMarker from '../location/SmartMarker';
|
||||
import OwnBeaconStatus from '../beacon/OwnBeaconStatus';
|
||||
import { GetRelationsForEvent } from '../rooms/EventTile';
|
||||
import BeaconViewDialog from '../beacon/BeaconViewDialog';
|
||||
import { IBodyProps } from "./IBodyProps";
|
||||
|
||||
|
@ -87,7 +96,36 @@ const useUniqueId = (eventId: string): string => {
|
|||
return id;
|
||||
};
|
||||
|
||||
const MBeaconBody: React.FC<IBodyProps> = React.forwardRef(({ mxEvent }, ref) => {
|
||||
// remove related beacon locations on beacon redaction
|
||||
const useHandleBeaconRedaction = (
|
||||
event: MatrixEvent,
|
||||
getRelationsForEvent: GetRelationsForEvent,
|
||||
cli: MatrixClient,
|
||||
): void => {
|
||||
const onBeforeBeaconInfoRedaction = useCallback((_event: MatrixEvent, redactionEvent: MatrixEvent) => {
|
||||
const relations = getRelationsForEvent ?
|
||||
getRelationsForEvent(event.getId(), RelationType.Reference, M_BEACON.name) :
|
||||
undefined;
|
||||
|
||||
relations?.getRelations()?.forEach(locationEvent => {
|
||||
cli.redactEvent(
|
||||
locationEvent.getRoomId(),
|
||||
locationEvent.getId(),
|
||||
undefined,
|
||||
redactionEvent.getContent(),
|
||||
);
|
||||
});
|
||||
}, [event, getRelationsForEvent, cli]);
|
||||
|
||||
useEffect(() => {
|
||||
event.addListener(MatrixEventEvent.BeforeRedaction, onBeforeBeaconInfoRedaction);
|
||||
return () => {
|
||||
event.removeListener(MatrixEventEvent.BeforeRedaction, onBeforeBeaconInfoRedaction);
|
||||
};
|
||||
}, [event, onBeforeBeaconInfoRedaction]);
|
||||
};
|
||||
|
||||
const MBeaconBody: React.FC<IBodyProps> = React.forwardRef(({ mxEvent, getRelationsForEvent }, ref) => {
|
||||
const {
|
||||
beacon,
|
||||
isLive,
|
||||
|
@ -102,6 +140,8 @@ const MBeaconBody: React.FC<IBodyProps> = React.forwardRef(({ mxEvent }, ref) =>
|
|||
const markerRoomMember = isSelfLocation(mxEvent.getContent()) ? mxEvent.sender : undefined;
|
||||
const isOwnBeacon = beacon?.beaconInfoOwner === matrixClient.getUserId();
|
||||
|
||||
useHandleBeaconRedaction(mxEvent, getRelationsForEvent, matrixClient);
|
||||
|
||||
const onClick = () => {
|
||||
if (displayStatus !== BeaconDisplayStatus.Active) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue