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

Commit 2a55d22

Browse files
authored
Wire up CallEventGroupers for Search Results (#7866)
1 parent e644ede commit 2a55d22

File tree

4 files changed

+130
-19
lines changed

4 files changed

+130
-19
lines changed

src/components/structures/CallEventGrouper.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@ export enum CustomCallState {
4444
Missed = "missed",
4545
}
4646

47+
export function buildCallEventGroupers(
48+
callEventGroupers: Map<string, CallEventGrouper>,
49+
events?: MatrixEvent[],
50+
): Map<string, CallEventGrouper> {
51+
const newCallEventGroupers = new Map();
52+
events?.forEach(ev => {
53+
if (!ev.getType().startsWith("m.call.") && !ev.getType().startsWith("org.matrix.call.")) {
54+
return;
55+
}
56+
57+
const callId = ev.getContent().call_id;
58+
if (!newCallEventGroupers.has(callId)) {
59+
if (callEventGroupers.has(callId)) {
60+
// reuse the CallEventGrouper object where possible
61+
newCallEventGroupers.set(callId, callEventGroupers.get(callId));
62+
} else {
63+
newCallEventGroupers.set(callId, new CallEventGrouper());
64+
}
65+
}
66+
newCallEventGroupers.get(callId).add(ev);
67+
});
68+
return newCallEventGroupers;
69+
}
70+
4771
export default class CallEventGrouper extends EventEmitter {
4872
private events: Set<MatrixEvent> = new Set<MatrixEvent>();
4973
private call: MatrixCall;

src/components/structures/TimelinePanel.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { RoomPermalinkCreator } from "../../utils/permalinks/Permalinks";
5151
import Spinner from "../views/elements/Spinner";
5252
import EditorStateTransfer from '../../utils/EditorStateTransfer';
5353
import ErrorDialog from '../views/dialogs/ErrorDialog';
54-
import CallEventGrouper from "./CallEventGrouper";
54+
import CallEventGrouper, { buildCallEventGroupers } from "./CallEventGrouper";
5555
import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
5656

5757
const PAGINATE_SIZE = 20;
@@ -1546,24 +1546,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
15461546
) => this.props.timelineSet.getRelationsForEvent(eventId, relationType, eventType);
15471547

15481548
private buildCallEventGroupers(events?: MatrixEvent[]): void {
1549-
const oldCallEventGroupers = this.callEventGroupers;
1550-
this.callEventGroupers = new Map();
1551-
events?.forEach(ev => {
1552-
if (!ev.getType().startsWith("m.call.") && !ev.getType().startsWith("org.matrix.call.")) {
1553-
return;
1554-
}
1555-
1556-
const callId = ev.getContent().call_id;
1557-
if (!this.callEventGroupers.has(callId)) {
1558-
if (oldCallEventGroupers.has(callId)) {
1559-
// reuse the CallEventGrouper object where possible
1560-
this.callEventGroupers.set(callId, oldCallEventGroupers.get(callId));
1561-
} else {
1562-
this.callEventGroupers.set(callId, new CallEventGrouper());
1563-
}
1564-
}
1565-
this.callEventGroupers.get(callId).add(ev);
1566-
});
1549+
this.callEventGroupers = buildCallEventGroupers(this.callEventGroupers, events);
15671550
}
15681551

15691552
render() {

src/components/views/rooms/SearchResultTile.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717

1818
import React from "react";
1919
import { SearchResult } from "matrix-js-sdk/src/models/search-result";
20+
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
2021

2122
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
2223
import SettingsStore from "../../../settings/SettingsStore";
@@ -27,6 +28,7 @@ import DateSeparator from "../messages/DateSeparator";
2728
import EventTile, { haveTileForEvent } from "./EventTile";
2829
import { shouldFormContinuation } from "../../structures/MessagePanel";
2930
import { wantsDateSeparator } from "../../../DateUtils";
31+
import CallEventGrouper, { buildCallEventGroupers } from "../../structures/CallEventGrouper";
3032

3133
interface IProps {
3234
// a matrix-js-sdk SearchResult containing the details of this result
@@ -42,6 +44,20 @@ interface IProps {
4244
@replaceableComponent("views.rooms.SearchResultTile")
4345
export default class SearchResultTile extends React.Component<IProps> {
4446
static contextType = RoomContext;
47+
public context!: React.ContextType<typeof RoomContext>;
48+
49+
// A map of <callId, CallEventGrouper>
50+
private callEventGroupers = new Map<string, CallEventGrouper>();
51+
52+
constructor(props, context) {
53+
super(props, context);
54+
55+
this.buildCallEventGroupers(this.props.searchResult.context.getTimeline());
56+
}
57+
58+
private buildCallEventGroupers(events?: MatrixEvent[]): void {
59+
this.callEventGroupers = buildCallEventGroupers(this.callEventGroupers, events);
60+
}
4561

4662
public render() {
4763
const result = this.props.searchResult;
@@ -109,6 +125,7 @@ export default class SearchResultTile extends React.Component<IProps> {
109125
timelineRenderingType={TimelineRenderingType.Search}
110126
lastInSection={lastInSection}
111127
continuation={continuation}
128+
callEventGrouper={this.callEventGroupers.get(mxEv.getContent().call_id)}
112129
/>,
113130
);
114131
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 * as React from "react";
18+
import { mount } from "enzyme";
19+
import { SearchResult } from "matrix-js-sdk/src/models/search-result";
20+
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
21+
import { EventType } from "matrix-js-sdk/src/@types/event";
22+
23+
import sdk from "../../../skinned-sdk";
24+
import { createTestClient } from "../../../test-utils";
25+
import EventTile from "../../../../src/components/views/rooms/EventTile";
26+
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
27+
28+
const SearchResultTile = sdk.getComponent("views.rooms.SearchResultTile");
29+
30+
describe("SearchResultTile", () => {
31+
beforeAll(() => {
32+
MatrixClientPeg.get = () => createTestClient();
33+
});
34+
35+
it("Sets up appropriate callEventGrouper for m.call. events", () => {
36+
const wrapper = mount(
37+
<SearchResultTile
38+
searchResult={SearchResult.fromJson({
39+
rank: 0.00424866,
40+
result: {
41+
content: {
42+
body: "This is an example text message",
43+
format: "org.matrix.custom.html",
44+
formatted_body: "<b>This is an example text message</b>",
45+
msgtype: "m.text",
46+
},
47+
event_id: "$144429830826TWwbB:localhost",
48+
origin_server_ts: 1432735824653,
49+
room_id: "!qPewotXpIctQySfjSy:localhost",
50+
sender: "@example:example.org",
51+
type: "m.room.message",
52+
unsigned: {
53+
age: 1234,
54+
},
55+
},
56+
context: {
57+
end: "",
58+
start: "",
59+
profile_info: {},
60+
events_before: [{
61+
type: EventType.CallInvite,
62+
sender: "@user1:server",
63+
room_id: "!qPewotXpIctQySfjSy:localhost",
64+
origin_server_ts: 1432735824652,
65+
content: { call_id: "call.1" },
66+
event_id: "$1:server",
67+
}],
68+
events_after: [{
69+
type: EventType.CallAnswer,
70+
sender: "@user2:server",
71+
room_id: "!qPewotXpIctQySfjSy:localhost",
72+
origin_server_ts: 1432735824654,
73+
content: { call_id: "call.1" },
74+
event_id: "$2:server",
75+
}],
76+
},
77+
}, o => new MatrixEvent(o))}
78+
/>,
79+
);
80+
81+
const tiles = wrapper.find(EventTile);
82+
expect(tiles.length).toEqual(2);
83+
expect(tiles.at(0).prop("mxEvent").getId()).toBe("$1:server");
84+
expect(tiles.at(0).prop("callEventGrouper").events.size).toBe(2);
85+
expect(tiles.at(1).prop("mxEvent").getId()).toBe("$144429830826TWwbB:localhost");
86+
});
87+
});

0 commit comments

Comments
 (0)