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

Commit 2b8f7fc

Browse files
author
Kerry Archibald
committed
replace use of isSelfLocation
Signed-off-by: Kerry Archibald <[email protected]>
1 parent b93c139 commit 2b8f7fc

File tree

2 files changed

+3
-68
lines changed

2 files changed

+3
-68
lines changed

src/components/views/messages/MLocationBody.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ limitations under the License.
1717
import React from 'react';
1818
import maplibregl from 'maplibre-gl';
1919
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
20-
import {
21-
M_ASSET,
22-
LocationAssetType,
23-
ILocationContent,
24-
} from 'matrix-js-sdk/src/@types/location';
2520
import { ClientEvent, IClientWellKnown } from 'matrix-js-sdk/src/client';
2621

2722
import { IBodyProps } from "./IBodyProps";
@@ -33,6 +28,7 @@ import {
3328
createMapWithCoords,
3429
getLocationShareErrorMessage,
3530
LocationShareError,
31+
isSelfLocation,
3632
} from '../../../utils/location';
3733
import LocationViewDialog from '../location/LocationViewDialog';
3834
import TooltipTarget from '../elements/TooltipTarget';
@@ -132,12 +128,6 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
132128
}
133129
}
134130

135-
export function isSelfLocation(locationContent: ILocationContent): boolean {
136-
const asset = M_ASSET.findIn(locationContent) as { type: string };
137-
const assetType = asset?.type ?? LocationAssetType.Self;
138-
return assetType == LocationAssetType.Self;
139-
}
140-
141131
export const LocationBodyFallbackContent: React.FC<{ event: MatrixEvent, error: Error }> = ({ error, event }) => {
142132
const errorType = error?.message as LocationShareError;
143133
const message = `${_t('Unable to load map')}: ${getLocationShareErrorMessage(errorType)}`;

test/components/views/messages/MLocationBody-test.tsx

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,11 @@ limitations under the License.
1717
import React from 'react';
1818
import { mount } from "enzyme";
1919
import { mocked } from 'jest-mock';
20-
import { makeLocationContent } from "matrix-js-sdk/src/content-helpers";
21-
import {
22-
M_ASSET,
23-
LocationAssetType,
24-
ILocationContent,
25-
M_LOCATION,
26-
M_TIMESTAMP,
27-
} from "matrix-js-sdk/src/@types/location";
28-
import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events";
20+
import { LocationAssetType } from "matrix-js-sdk/src/@types/location";
2921
import maplibregl from 'maplibre-gl';
3022
import { logger } from 'matrix-js-sdk/src/logger';
3123

32-
import MLocationBody, {
33-
isSelfLocation,
34-
} from "../../../../src/components/views/messages/MLocationBody";
24+
import MLocationBody from "../../../../src/components/views/messages/MLocationBody";
3525
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
3626
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
3727
import { MediaEventHelper } from "../../../../src/utils/MediaEventHelper";
@@ -44,51 +34,6 @@ jest.mock("../../../../src/utils/WellKnownUtils", () => ({
4434
}));
4535

4636
describe("MLocationBody", () => {
47-
describe("isSelfLocation", () => {
48-
it("Returns true for a full m.asset event", () => {
49-
const content = makeLocationContent("", '0');
50-
expect(isSelfLocation(content)).toBe(true);
51-
});
52-
53-
it("Returns true for a missing m.asset", () => {
54-
const content = {
55-
body: "",
56-
msgtype: "m.location",
57-
geo_uri: "",
58-
[M_LOCATION.name]: { uri: "" },
59-
[TEXT_NODE_TYPE.name]: "",
60-
[M_TIMESTAMP.name]: 0,
61-
// Note: no m.asset!
62-
};
63-
expect(isSelfLocation(content as ILocationContent)).toBe(true);
64-
});
65-
66-
it("Returns true for a missing m.asset type", () => {
67-
const content = {
68-
body: "",
69-
msgtype: "m.location",
70-
geo_uri: "",
71-
[M_LOCATION.name]: { uri: "" },
72-
[TEXT_NODE_TYPE.name]: "",
73-
[M_TIMESTAMP.name]: 0,
74-
[M_ASSET.name]: {
75-
// Note: no type!
76-
},
77-
};
78-
expect(isSelfLocation(content as ILocationContent)).toBe(true);
79-
});
80-
81-
it("Returns false for an unknown asset type", () => {
82-
const content = makeLocationContent(
83-
undefined, /* text */
84-
"geo:foo",
85-
0,
86-
undefined, /* description */
87-
"org.example.unknown" as unknown as LocationAssetType);
88-
expect(isSelfLocation(content)).toBe(false);
89-
});
90-
});
91-
9237
describe('<MLocationBody>', () => {
9338
describe('with error', () => {
9439
const mockClient = {

0 commit comments

Comments
 (0)