Live location sharing - update beacon_info implementation to latest MSC (#8256)
* update calls to set and createLiveBeacon Signed-off-by: Kerry Archibald <kerrya@element.io> * fix stop beacon Signed-off-by: Kerry Archibald <kerrya@element.io> * remove variable event type from beacon utils Signed-off-by: Kerry Archibald <kerrya@element.io> * use beacon identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * fix RoomLiveShareWarning tests Signed-off-by: Kerry Archibald <kerrya@element.io> * add case for beacon update Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * more lint Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
610225aef2
commit
03d0969ae3
9 changed files with 123 additions and 108 deletions
|
@ -16,7 +16,12 @@ limitations under the License.
|
|||
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Room, Beacon } from 'matrix-js-sdk/src/matrix';
|
||||
import {
|
||||
Room,
|
||||
Beacon,
|
||||
BeaconEvent,
|
||||
BeaconIdentifier,
|
||||
} from 'matrix-js-sdk/src/matrix';
|
||||
|
||||
import { formatDuration } from '../../../DateUtils';
|
||||
import { _t } from '../../../languageHandler';
|
||||
|
@ -45,16 +50,22 @@ const getUpdateInterval = (ms: number) => {
|
|||
return 1000;
|
||||
};
|
||||
const useMsRemaining = (beacon: Beacon): number => {
|
||||
const [msRemaining, setMsRemaining] = useState(() => getBeaconMsUntilExpiry(beacon));
|
||||
const beaconInfo = useEventEmitterState(
|
||||
beacon,
|
||||
BeaconEvent.Update,
|
||||
() => beacon.beaconInfo,
|
||||
);
|
||||
|
||||
const [msRemaining, setMsRemaining] = useState(() => getBeaconMsUntilExpiry(beaconInfo));
|
||||
|
||||
useEffect(() => {
|
||||
setMsRemaining(getBeaconMsUntilExpiry(beacon));
|
||||
}, [beacon]);
|
||||
setMsRemaining(getBeaconMsUntilExpiry(beaconInfo));
|
||||
}, [beaconInfo]);
|
||||
|
||||
const updateMsRemaining = useCallback(() => {
|
||||
const ms = getBeaconMsUntilExpiry(beacon);
|
||||
const ms = getBeaconMsUntilExpiry(beaconInfo);
|
||||
setMsRemaining(ms);
|
||||
}, [beacon]);
|
||||
}, [beaconInfo]);
|
||||
|
||||
useInterval(updateMsRemaining, getUpdateInterval(msRemaining));
|
||||
|
||||
|
@ -74,7 +85,7 @@ type LiveBeaconsState = {
|
|||
hasStopSharingError?: boolean;
|
||||
hasWireError?: boolean;
|
||||
};
|
||||
const useLiveBeacons = (liveBeaconIds: string[], roomId: string): LiveBeaconsState => {
|
||||
const useLiveBeacons = (liveBeaconIds: BeaconIdentifier[], roomId: string): LiveBeaconsState => {
|
||||
const [stoppingInProgress, setStoppingInProgress] = useState(false);
|
||||
const [error, setError] = useState<Error>();
|
||||
|
||||
|
|
|
@ -78,8 +78,7 @@ export const shareLiveLocation = (
|
|||
description,
|
||||
LocationAssetType.Self,
|
||||
),
|
||||
// use timestamp as unique suffix in interim
|
||||
`${Date.now()}`);
|
||||
);
|
||||
} catch (error) {
|
||||
handleShareError(error, openMenu, LocationShareType.Live);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue