Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 91cbd4d

Browse files
author
Kerry
authored
hide live location option when composer has relation (#8746)
Signed-off-by: Kerry Archibald <[email protected]>
1 parent 228abb6 commit 91cbd4d

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/components/views/location/LocationShareMenu.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,16 @@ type Props = Omit<ILocationPickerProps, 'onChoose' | 'shareType'> & {
3838
relation?: IEventRelation;
3939
};
4040

41-
const getEnabledShareTypes = (): LocationShareType[] => {
42-
const enabledShareTypes = [LocationShareType.Own, LocationShareType.Live];
41+
const getEnabledShareTypes = (relation): LocationShareType[] => {
42+
const enabledShareTypes = [
43+
LocationShareType.Own,
44+
];
45+
46+
// live locations cannot have a relation
47+
// hide the option when composer has a relation
48+
if (!relation) {
49+
enabledShareTypes.push(LocationShareType.Live);
50+
}
4351

4452
if (SettingsStore.getValue("feature_location_share_pin_drop")) {
4553
enabledShareTypes.push(LocationShareType.Pin);
@@ -57,7 +65,7 @@ const LocationShareMenu: React.FC<Props> = ({
5765
relation,
5866
}) => {
5967
const matrixClient = useContext(MatrixClientContext);
60-
const enabledShareTypes = getEnabledShareTypes();
68+
const enabledShareTypes = getEnabledShareTypes(relation);
6169
const isLiveShareEnabled = useFeatureEnabled("feature_location_share_live");
6270

6371
const multipleShareTypesEnabled = enabledShareTypes.length > 1;

test/components/views/location/LocationShareMenu-test.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ limitations under the License.
1616

1717
import React from 'react';
1818
import { mount, ReactWrapper } from 'enzyme';
19+
import { mocked } from 'jest-mock';
1920
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
2021
import { MatrixClient } from 'matrix-js-sdk/src/client';
21-
import { mocked } from 'jest-mock';
22-
import { act } from 'react-dom/test-utils';
23-
import { M_ASSET, LocationAssetType } from 'matrix-js-sdk/src/@types/location';
22+
import { RelationType } from 'matrix-js-sdk/src/matrix';
2423
import { logger } from 'matrix-js-sdk/src/logger';
24+
import { M_ASSET, LocationAssetType } from 'matrix-js-sdk/src/@types/location';
25+
import { act } from 'react-dom/test-utils';
2526

2627
import LocationShareMenu from '../../../../src/components/views/location/LocationShareMenu';
2728
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';
@@ -375,6 +376,16 @@ describe('<LocationShareMenu />', () => {
375376
describe('Live location share', () => {
376377
beforeEach(() => enableSettings(["feature_location_share_live"]));
377378

379+
it('does not display live location share option when composer has a relation', () => {
380+
const relation = {
381+
rel_type: RelationType.Thread,
382+
event_id: '12345',
383+
};
384+
const component = getComponent({ relation });
385+
386+
expect(getShareTypeOption(component, LocationShareType.Live).length).toBeFalsy();
387+
});
388+
378389
it('creates beacon info event on submission', () => {
379390
const onFinished = jest.fn();
380391
const component = getComponent({ onFinished });

0 commit comments

Comments
 (0)