/* Copyright 2024 New Vector Ltd. Copyright 2022 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ import React, { HTMLProps, useContext } from "react"; import { Beacon, BeaconEvent, LocationAssetType } from "matrix-js-sdk/src/matrix"; import MatrixClientContext from "../../../contexts/MatrixClientContext"; import { useEventEmitterState } from "../../../hooks/useEventEmitter"; import { humanizeTime } from "../../../utils/humanize"; import { preventDefaultWrapper } from "../../../utils/NativeEventUtils"; import { _t } from "../../../languageHandler"; import MemberAvatar from "../avatars/MemberAvatar"; import BeaconStatus from "./BeaconStatus"; import { BeaconDisplayStatus } from "./displayStatus"; import StyledLiveBeaconIcon from "./StyledLiveBeaconIcon"; import ShareLatestLocation from "./ShareLatestLocation"; interface Props { beacon: Beacon; } const BeaconListItem: React.FC> = ({ beacon, ...rest }) => { const latestLocationState = useEventEmitterState( beacon, BeaconEvent.LocationUpdate, () => beacon.latestLocationState, ); const matrixClient = useContext(MatrixClientContext); const room = matrixClient.getRoom(beacon.roomId); if (!latestLocationState || !beacon.isLive || !room) { return null; } const isSelfLocation = beacon.beaconInfo?.assetType === LocationAssetType.Self; const beaconMember = isSelfLocation ? room.getMember(beacon.beaconInfoOwner) : null; const humanizedUpdateTime = (latestLocationState.timestamp && humanizeTime(latestLocationState.timestamp)) || ""; return (
  • {isSelfLocation ? ( ) : ( )}
    {/* eat events from interactive share buttons so parent click handlers are not triggered */}
    {})}>
    {_t("location_sharing|live_update_time", { humanizedUpdateTime })}
  • ); }; export default BeaconListItem;