mirror of
https://github.com/element-hq/element-web
synced 2024-11-25 10:45:51 +03:00
update location event types (#8022)
* update types Signed-off-by: Kerry Archibald <kerrya@element.io> * fix tests Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * trigger Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
a4b2e0c0d8
commit
e96d9157a9
9 changed files with 39 additions and 35 deletions
|
@ -22,7 +22,7 @@ import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
|
|||
import { ClientEvent } from "matrix-js-sdk/src/client";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { MsgType } from "matrix-js-sdk/src/@types/event";
|
||||
import { LOCATION_EVENT_TYPE } from "matrix-js-sdk/src/@types/location";
|
||||
import { M_LOCATION } from "matrix-js-sdk/src/@types/location";
|
||||
|
||||
import { MatrixClientPeg } from './MatrixClientPeg';
|
||||
import SdkConfig from './SdkConfig';
|
||||
|
@ -64,10 +64,10 @@ const msgTypeHandlers = {
|
|||
const name = (event.sender || {}).name;
|
||||
return _t("%(name)s is requesting verification", { name });
|
||||
},
|
||||
[LOCATION_EVENT_TYPE.name]: (event: MatrixEvent) => {
|
||||
[M_LOCATION.name]: (event: MatrixEvent) => {
|
||||
return TextForEvent.textForLocationEvent(event)();
|
||||
},
|
||||
[LOCATION_EVENT_TYPE.altName]: (event: MatrixEvent) => {
|
||||
[M_LOCATION.altName]: (event: MatrixEvent) => {
|
||||
return TextForEvent.textForLocationEvent(event)();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ import {
|
|||
M_POLL_END,
|
||||
PollStartEvent,
|
||||
} from "matrix-events-sdk";
|
||||
import { LOCATION_EVENT_TYPE } from "matrix-js-sdk/src/@types/location";
|
||||
import { M_LOCATION } from "matrix-js-sdk/src/@types/location";
|
||||
|
||||
import { _t } from './languageHandler';
|
||||
import * as Roles from './Roles';
|
||||
|
@ -339,7 +339,7 @@ function textForMessageEvent(ev: MatrixEvent): () => string | null {
|
|||
const content = ev.getContent();
|
||||
const msgtype = content.msgtype;
|
||||
|
||||
if (LOCATION_EVENT_TYPE.matches(type) || LOCATION_EVENT_TYPE.matches(msgtype)) {
|
||||
if (M_LOCATION.matches(type) || M_LOCATION.matches(msgtype)) {
|
||||
return textForLocationEvent(ev);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
|||
import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
|
||||
import { Relations } from 'matrix-js-sdk/src/models/relations';
|
||||
import { RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
|
||||
import { LOCATION_EVENT_TYPE } from 'matrix-js-sdk/src/@types/location';
|
||||
import { M_LOCATION } from 'matrix-js-sdk/src/@types/location';
|
||||
import { M_POLL_START } from "matrix-events-sdk";
|
||||
|
||||
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
||||
|
@ -526,10 +526,10 @@ function canForward(event: MatrixEvent): boolean {
|
|||
function isLocationEvent(event: MatrixEvent): boolean {
|
||||
const eventType = event.getType();
|
||||
return (
|
||||
LOCATION_EVENT_TYPE.matches(eventType) ||
|
||||
M_LOCATION.matches(eventType) ||
|
||||
(
|
||||
eventType === EventType.RoomMessage &&
|
||||
LOCATION_EVENT_TYPE.matches(event.getContent().msgtype)
|
||||
M_LOCATION.matches(event.getContent().msgtype)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -41,10 +41,9 @@ export const shareLocation = (
|
|||
) => async (uri: string, ts: number) => {
|
||||
if (!uri) return false;
|
||||
try {
|
||||
const text = textForLocation(uri, ts, null);
|
||||
const threadId = relation?.rel_type === RelationType.Thread ? relation.event_id : null;
|
||||
const assetType = shareType === LocationShareType.Pin ? LocationAssetType.Pin : LocationAssetType.Self;
|
||||
await client.sendMessage(roomId, threadId, makeLocationContent(text, uri, ts, null, assetType));
|
||||
await client.sendMessage(roomId, threadId, makeLocationContent(undefined, uri, ts, undefined, assetType));
|
||||
} catch (e) {
|
||||
logger.error("We couldn't send your location", e);
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@ import maplibregl from 'maplibre-gl';
|
|||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
||||
import {
|
||||
ASSET_NODE_TYPE,
|
||||
M_ASSET,
|
||||
LocationAssetType,
|
||||
ILocationContent,
|
||||
LOCATION_EVENT_TYPE,
|
||||
M_LOCATION,
|
||||
} from 'matrix-js-sdk/src/@types/location';
|
||||
import { ClientEvent, IClientWellKnown } from 'matrix-js-sdk/src/client';
|
||||
|
||||
|
@ -129,7 +129,7 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
|
|||
}
|
||||
|
||||
export function isSelfLocation(locationContent: ILocationContent): boolean {
|
||||
const asset = ASSET_NODE_TYPE.findIn(locationContent) as { type: string };
|
||||
const asset = M_ASSET.findIn(locationContent) as { type: string };
|
||||
const assetType = asset?.type ?? LocationAssetType.Self;
|
||||
return assetType == LocationAssetType.Self;
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ export function locationEventGeoUri(mxEvent: MatrixEvent): string {
|
|||
// events - so folks can read their old chat history correctly.
|
||||
// https://github.com/matrix-org/matrix-doc/issues/3516
|
||||
const content = mxEvent.getContent();
|
||||
const loc = LOCATION_EVENT_TYPE.findIn(content) as { uri?: string };
|
||||
const loc = M_LOCATION.findIn(content) as { uri?: string };
|
||||
return loc ? loc.uri : content['geo_uri'];
|
||||
}
|
||||
|
||||
|
@ -343,7 +343,7 @@ function makeLink(coords: GeolocationCoordinates): string {
|
|||
|
||||
export function createMapSiteLink(event: MatrixEvent): string {
|
||||
const content: Object = event.getContent();
|
||||
const mLocation = content[LOCATION_EVENT_TYPE.name];
|
||||
const mLocation = content[M_LOCATION.name];
|
||||
if (mLocation !== undefined) {
|
||||
const uri = mLocation["uri"];
|
||||
if (uri !== undefined) {
|
||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
import React, { createRef } from 'react';
|
||||
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
|
||||
import { Relations } from 'matrix-js-sdk/src/models/relations';
|
||||
import { LOCATION_EVENT_TYPE } from 'matrix-js-sdk/src/@types/location';
|
||||
import { M_LOCATION } from 'matrix-js-sdk/src/@types/location';
|
||||
import { M_POLL_START } from "matrix-events-sdk";
|
||||
|
||||
import * as sdk from '../../../index';
|
||||
|
@ -132,7 +132,7 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
|
|||
|
||||
// TODO: move to eventTypes when location sharing spec stabilises
|
||||
if (
|
||||
LOCATION_EVENT_TYPE.matches(type) ||
|
||||
M_LOCATION.matches(type) ||
|
||||
(type === EventType.RoomMessage && msgtype === MsgType.Location)
|
||||
) {
|
||||
BodyType = sdk.getComponent('messages.MLocationBody');
|
||||
|
|
|
@ -18,7 +18,7 @@ import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
|||
import { EventType, EVENT_VISIBILITY_CHANGE_TYPE, MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
|
||||
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
||||
import { logger } from 'matrix-js-sdk/src/logger';
|
||||
import { LOCATION_EVENT_TYPE } from 'matrix-js-sdk/src/@types/location';
|
||||
import { M_LOCATION } from 'matrix-js-sdk/src/@types/location';
|
||||
import { M_POLL_START } from "matrix-events-sdk";
|
||||
|
||||
import { MatrixClientPeg } from '../MatrixClientPeg';
|
||||
|
@ -252,10 +252,10 @@ export function getEventDisplayInfo(mxEvent: MatrixEvent, hideEvent?: boolean):
|
|||
const noBubbleEvent = (
|
||||
(eventType === EventType.RoomMessage && msgtype === MsgType.Emote) ||
|
||||
M_POLL_START.matches(eventType) ||
|
||||
LOCATION_EVENT_TYPE.matches(eventType) ||
|
||||
M_LOCATION.matches(eventType) ||
|
||||
(
|
||||
eventType === EventType.RoomMessage &&
|
||||
LOCATION_EVENT_TYPE.matches(msgtype)
|
||||
M_LOCATION.matches(msgtype)
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
|||
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
||||
import { mocked } from 'jest-mock';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { ASSET_NODE_TYPE, LocationAssetType } from 'matrix-js-sdk/src/@types/location';
|
||||
import { M_ASSET, LocationAssetType } from 'matrix-js-sdk/src/@types/location';
|
||||
|
||||
import '../../../skinned-sdk';
|
||||
import LocationShareMenu from '../../../../src/components/views/location/LocationShareMenu';
|
||||
|
@ -162,7 +162,7 @@ describe('<LocationShareMenu />', () => {
|
|||
expect(messageRoomId).toEqual(defaultProps.roomId);
|
||||
expect(relation).toEqual(null);
|
||||
expect(messageBody).toEqual(expect.objectContaining({
|
||||
[ASSET_NODE_TYPE.name]: {
|
||||
[M_ASSET.name]: {
|
||||
type: LocationAssetType.Self,
|
||||
},
|
||||
}));
|
||||
|
@ -243,7 +243,7 @@ describe('<LocationShareMenu />', () => {
|
|||
expect(messageRoomId).toEqual(defaultProps.roomId);
|
||||
expect(relation).toEqual(null);
|
||||
expect(messageBody).toEqual(expect.objectContaining({
|
||||
[ASSET_NODE_TYPE.name]: {
|
||||
[M_ASSET.name]: {
|
||||
type: LocationAssetType.Pin,
|
||||
},
|
||||
}));
|
||||
|
|
|
@ -16,11 +16,11 @@ limitations under the License.
|
|||
|
||||
import { makeLocationContent } from "matrix-js-sdk/src/content-helpers";
|
||||
import {
|
||||
ASSET_NODE_TYPE,
|
||||
M_ASSET,
|
||||
LocationAssetType,
|
||||
ILocationContent,
|
||||
LOCATION_EVENT_TYPE,
|
||||
TIMESTAMP_NODE_TYPE,
|
||||
M_LOCATION,
|
||||
M_TIMESTAMP,
|
||||
} from "matrix-js-sdk/src/@types/location";
|
||||
import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events";
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
|
@ -203,7 +203,7 @@ describe("MLocationBody", () => {
|
|||
|
||||
describe("isSelfLocation", () => {
|
||||
it("Returns true for a full m.asset event", () => {
|
||||
const content = makeLocationContent("", "", 0);
|
||||
const content = makeLocationContent("", 0);
|
||||
expect(isSelfLocation(content)).toBe(true);
|
||||
});
|
||||
|
||||
|
@ -212,9 +212,9 @@ describe("MLocationBody", () => {
|
|||
body: "",
|
||||
msgtype: "m.location",
|
||||
geo_uri: "",
|
||||
[LOCATION_EVENT_TYPE.name]: { uri: "" },
|
||||
[M_LOCATION.name]: { uri: "" },
|
||||
[TEXT_NODE_TYPE.name]: "",
|
||||
[TIMESTAMP_NODE_TYPE.name]: 0,
|
||||
[M_TIMESTAMP.name]: 0,
|
||||
// Note: no m.asset!
|
||||
};
|
||||
expect(isSelfLocation(content as ILocationContent)).toBe(true);
|
||||
|
@ -225,10 +225,10 @@ describe("MLocationBody", () => {
|
|||
body: "",
|
||||
msgtype: "m.location",
|
||||
geo_uri: "",
|
||||
[LOCATION_EVENT_TYPE.name]: { uri: "" },
|
||||
[M_LOCATION.name]: { uri: "" },
|
||||
[TEXT_NODE_TYPE.name]: "",
|
||||
[TIMESTAMP_NODE_TYPE.name]: 0,
|
||||
[ASSET_NODE_TYPE.name]: {
|
||||
[M_TIMESTAMP.name]: 0,
|
||||
[M_ASSET.name]: {
|
||||
// Note: no type!
|
||||
},
|
||||
};
|
||||
|
@ -236,7 +236,12 @@ describe("MLocationBody", () => {
|
|||
});
|
||||
|
||||
it("Returns false for an unknown asset type", () => {
|
||||
const content = makeLocationContent("", "", 0, "", "org.example.unknown" as unknown as LocationAssetType);
|
||||
const content = makeLocationContent(
|
||||
undefined, /* text */
|
||||
"geo:foo",
|
||||
0,
|
||||
undefined, /* description */
|
||||
"org.example.unknown" as unknown as LocationAssetType);
|
||||
expect(isSelfLocation(content)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
@ -246,7 +251,7 @@ function oldLocationEvent(geoUri: string): MatrixEvent {
|
|||
return new MatrixEvent(
|
||||
{
|
||||
"event_id": nextId(),
|
||||
"type": LOCATION_EVENT_TYPE.name,
|
||||
"type": M_LOCATION.name,
|
||||
"content": {
|
||||
"body": "Something about where I am",
|
||||
"msgtype": "m.location",
|
||||
|
@ -260,7 +265,7 @@ function modernLocationEvent(geoUri: string): MatrixEvent {
|
|||
return new MatrixEvent(
|
||||
{
|
||||
"event_id": nextId(),
|
||||
"type": LOCATION_EVENT_TYPE.name,
|
||||
"type": M_LOCATION.name,
|
||||
"content": makeLocationContent(
|
||||
`Found at ${geoUri} at 2021-12-21T12:22+0000`,
|
||||
geoUri,
|
||||
|
|
Loading…
Reference in a new issue