diff --git a/src/components/views/messages/MLocationBody.tsx b/src/components/views/messages/MLocationBody.tsx index 28a122e60f..36da968963 100644 --- a/src/components/views/messages/MLocationBody.tsx +++ b/src/components/views/messages/MLocationBody.tsx @@ -17,6 +17,7 @@ limitations under the License. import React from 'react'; import maplibregl from 'maplibre-gl'; import { logger } from "matrix-js-sdk/src/logger"; +import { LOCATION_EVENT_TYPE } from 'matrix-js-sdk/src/@types/location'; import SdkConfig from '../../../SdkConfig'; import { replaceableComponent } from "../../../utils/replaceableComponent"; @@ -41,17 +42,15 @@ export default class MLocationBody extends React.Component { // events - so folks can read their old chat history correctly. // https://github.com/matrix-org/matrix-doc/issues/3516 const content = this.props.mxEvent.getContent(); - const uri = content['org.matrix.msc3488.location'] ? - content['org.matrix.msc3488.location'].uri : - content['geo_uri']; + const loc = content[LOCATION_EVENT_TYPE.name]; + const uri = loc ? loc.uri : content['geo_uri']; this.coords = this.parseGeoUri(uri); this.state = { error: undefined, }; - this.description = - content['org.matrix.msc3488.location']?.description ?? content['body']; + this.description = loc?.description ?? content['body']; } private parseGeoUri = (uri: string): GeolocationCoordinates => { diff --git a/src/components/views/messages/MessageEvent.tsx b/src/components/views/messages/MessageEvent.tsx index c40c9ff2a0..a8ad1a98f9 100644 --- a/src/components/views/messages/MessageEvent.tsx +++ b/src/components/views/messages/MessageEvent.tsx @@ -18,6 +18,7 @@ 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 { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; +import { LOCATION_EVENT_TYPE } from 'matrix-js-sdk/src/@types/location'; import * as sdk from '../../../index'; import SettingsStore from "../../../settings/SettingsStore"; @@ -127,8 +128,10 @@ export default class MessageEvent extends React.Component implements IMe } } - if ((type && type === "org.matrix.msc3488.location") || - (type && type === EventType.RoomMessage && msgtype && msgtype === MsgType.Location)) { + if ( + LOCATION_EVENT_TYPE.matches(type) || + (type === EventType.RoomMessage && msgtype === MsgType.Location) + ) { // TODO: tidy this up once location sharing is out of labs if (SettingsStore.getValue("feature_location_share")) { BodyType = sdk.getComponent('messages.MLocationBody'); diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index bf95f722e4..dcfd7131f9 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -19,9 +19,9 @@ import { MatrixEvent, IEventRelation } from "matrix-js-sdk/src/models/event"; import { Room } from "matrix-js-sdk/src/models/room"; import { RoomMember } from "matrix-js-sdk/src/models/room-member"; import { RelationType } from 'matrix-js-sdk/src/@types/event'; -import { MsgType } from "matrix-js-sdk/src/@types/event"; import { logger } from "matrix-js-sdk/src/logger"; import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; +import { makeLocationContent } from "matrix-js-sdk/src/content-helpers"; import { _t } from '../../../languageHandler'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; @@ -505,19 +505,33 @@ export default class MessageComposer extends React.Component { return true; }; - private shareLocation = (uri: string, ts: number, type: LocationShareType, description: string): boolean => { + private textForLocation = ( + uri: string, + ts: number, + description: string | null, + ): string => { + const date = new Date(ts).toISOString(); + // TODO: translation, as soon as we've re-worded this better + if (description) { + return `${description} at ${uri} as of ${date}`; + } else { + return `Location at ${uri} as of ${date}`; + } + }; + + private shareLocation = ( + uri: string, + ts: number, + _type: LocationShareType, + description: string | null, + ): boolean => { if (!uri) return false; try { - const text = `${description ? description : 'Location'} at ${uri} as of ${new Date(ts).toISOString()}`; - // noinspection ES6MissingAwait - we don't care if it fails, it'll get queued. - MatrixClientPeg.get().sendMessage(this.props.room.roomId, { - "body": text, - "msgtype": MsgType.Location, - "geo_uri": uri, - "org.matrix.msc3488.location": { uri, description }, - "org.matrix.msc3488.ts": ts, - // TODO: MSC1767 fallbacks for text & thumbnail - }); + const text = this.textForLocation(uri, ts, description); + MatrixClientPeg.get().sendMessage( + this.props.room.roomId, + makeLocationContent(text, uri, ts, description), + ); } catch (e) { logger.error("Error sending location:", e); }