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

Commit f63923d

Browse files
author
Kerry
authored
Live location sharing - add configs to render beacon_info in timeline (#8251)
* add configs to render beacon_info in timeline Signed-off-by: Kerry Archibald <[email protected]> * fix copyright Signed-off-by: Kerry Archibald <[email protected]> * one more comment Signed-off-by: Kerry Archibald <[email protected]> * update beacon identifier Signed-off-by: Kerry Archibald <[email protected]> * use special case for beacon_info tile mapper Signed-off-by: Kerry Archibald <[email protected]>
1 parent 03d0969 commit f63923d

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from 'react';
18+
import { Beacon, getBeaconInfoIdentifier } from 'matrix-js-sdk/src/matrix';
19+
20+
import MatrixClientContext from '../../../contexts/MatrixClientContext';
21+
import { IBodyProps } from "./IBodyProps";
22+
23+
export default class MLocationBody extends React.Component<IBodyProps> {
24+
public static contextType = MatrixClientContext;
25+
public context!: React.ContextType<typeof MatrixClientContext>;
26+
private beacon: Beacon | undefined;
27+
private roomId: string;
28+
private beaconIdentifier: string;
29+
30+
constructor(props: IBodyProps) {
31+
super(props);
32+
33+
this.roomId = props.mxEvent.getRoomId();
34+
35+
this.beaconIdentifier = getBeaconInfoIdentifier(props.mxEvent);
36+
}
37+
38+
componentDidMount() {
39+
const roomState = this.context.getRoom(this.roomId)?.currentState;
40+
41+
const beacon = roomState?.beacons.get(this.beaconIdentifier);
42+
43+
this.beacon = beacon;
44+
}
45+
46+
render(): React.ReactElement<HTMLDivElement> {
47+
if (!this.beacon) {
48+
// TODO loading and error states
49+
return null;
50+
}
51+
// TODO everything else :~)
52+
const description = this.beacon.beaconInfo.description;
53+
return <div>{ description }</div>;
54+
}
55+
}

src/components/views/messages/MessageEvent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
import React, { createRef } from 'react';
1818
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
1919
import { Relations } from 'matrix-js-sdk/src/models/relations';
20+
import { M_BEACON_INFO } from 'matrix-js-sdk/src/@types/beacon';
2021
import { M_LOCATION } from 'matrix-js-sdk/src/@types/location';
2122
import { M_POLL_START } from "matrix-events-sdk";
2223

@@ -39,6 +40,7 @@ import MStickerBody from "./MStickerBody";
3940
import MPollBody from "./MPollBody";
4041
import MLocationBody from "./MLocationBody";
4142
import MjolnirBody from "./MjolnirBody";
43+
import MBeaconBody from "./MBeaconBody";
4244

4345
// onMessageAllowed is handled internally
4446
interface IProps extends Omit<IBodyProps, "onMessageAllowed" | "mediaEventHelper"> {
@@ -97,6 +99,8 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
9799
[EventType.Sticker]: MStickerBody,
98100
[M_POLL_START.name]: MPollBody,
99101
[M_POLL_START.altName]: MPollBody,
102+
[M_BEACON_INFO.name]: MBeaconBody,
103+
[M_BEACON_INFO.altName]: MBeaconBody,
100104

101105
...(this.props.overrideEventTypes || {}),
102106
};

src/events/EventTileFactory.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
1919
import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
2020
import { M_POLL_START, Optional } from "matrix-events-sdk";
2121
import { MatrixClient } from "matrix-js-sdk/src/client";
22+
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
2223

2324
import EditorStateTransfer from "../utils/EditorStateTransfer";
2425
import { RoomPermalinkCreator } from "../utils/permalinks/Permalinks";
@@ -211,9 +212,17 @@ export function pickFactory(mxEvent: MatrixEvent, cli: MatrixClient, asHiddenEv?
211212

212213
// Try and pick a state event factory, if we can.
213214
if (mxEvent.isState()) {
215+
if (
216+
M_BEACON_INFO.matches(evType) &&
217+
SettingsStore.getValue("feature_location_share_live")
218+
) {
219+
return MessageEventFactory;
220+
}
221+
214222
if (SINGULAR_STATE_EVENTS.has(evType) && mxEvent.getStateKey() !== '') {
215223
return noEventFactoryFactory(); // improper event type to render
216224
}
225+
217226
return STATE_EVENT_TILE_TYPES[evType] ?? noEventFactoryFactory();
218227
}
219228

src/utils/EventRenderingUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
1818
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
1919
import { M_POLL_START } from "matrix-events-sdk";
2020
import { M_LOCATION } from "matrix-js-sdk/src/@types/location";
21+
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
2122

2223
import SettingsStore from "../settings/SettingsStore";
2324
import { haveRendererForEvent, JitsiEventFactory, JSONEventFactory, pickFactory } from "../events/EventTileFactory";
@@ -72,7 +73,8 @@ export function getEventDisplayInfo(mxEvent: MatrixEvent, hideEvent?: boolean):
7273
eventType !== EventType.RoomMessageEncrypted &&
7374
eventType !== EventType.Sticker &&
7475
eventType !== EventType.RoomCreate &&
75-
!M_POLL_START.matches(eventType)
76+
!M_POLL_START.matches(eventType) &&
77+
!M_BEACON_INFO.matches(eventType)
7678
);
7779
// Some non-info messages want to be rendered in the appropriate bubble column but without the bubble background
7880
const noBubbleEvent = (

0 commit comments

Comments
 (0)