Wire up CallEventGroupers for Search Results (#7866)

This commit is contained in:
Michael Telatynski 2022-02-22 10:39:08 +00:00 committed by GitHub
parent e644ede09e
commit 2a55d22916
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 130 additions and 19 deletions

View file

@ -44,6 +44,30 @@ export enum CustomCallState {
Missed = "missed",
}
export function buildCallEventGroupers(
callEventGroupers: Map<string, CallEventGrouper>,
events?: MatrixEvent[],
): Map<string, CallEventGrouper> {
const newCallEventGroupers = new Map();
events?.forEach(ev => {
if (!ev.getType().startsWith("m.call.") && !ev.getType().startsWith("org.matrix.call.")) {
return;
}
const callId = ev.getContent().call_id;
if (!newCallEventGroupers.has(callId)) {
if (callEventGroupers.has(callId)) {
// reuse the CallEventGrouper object where possible
newCallEventGroupers.set(callId, callEventGroupers.get(callId));
} else {
newCallEventGroupers.set(callId, new CallEventGrouper());
}
}
newCallEventGroupers.get(callId).add(ev);
});
return newCallEventGroupers;
}
export default class CallEventGrouper extends EventEmitter {
private events: Set<MatrixEvent> = new Set<MatrixEvent>();
private call: MatrixCall;

View file

@ -51,7 +51,7 @@ import { RoomPermalinkCreator } from "../../utils/permalinks/Permalinks";
import Spinner from "../views/elements/Spinner";
import EditorStateTransfer from '../../utils/EditorStateTransfer';
import ErrorDialog from '../views/dialogs/ErrorDialog';
import CallEventGrouper from "./CallEventGrouper";
import CallEventGrouper, { buildCallEventGroupers } from "./CallEventGrouper";
import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
const PAGINATE_SIZE = 20;
@ -1546,24 +1546,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
) => this.props.timelineSet.getRelationsForEvent(eventId, relationType, eventType);
private buildCallEventGroupers(events?: MatrixEvent[]): void {
const oldCallEventGroupers = this.callEventGroupers;
this.callEventGroupers = new Map();
events?.forEach(ev => {
if (!ev.getType().startsWith("m.call.") && !ev.getType().startsWith("org.matrix.call.")) {
return;
}
const callId = ev.getContent().call_id;
if (!this.callEventGroupers.has(callId)) {
if (oldCallEventGroupers.has(callId)) {
// reuse the CallEventGrouper object where possible
this.callEventGroupers.set(callId, oldCallEventGroupers.get(callId));
} else {
this.callEventGroupers.set(callId, new CallEventGrouper());
}
}
this.callEventGroupers.get(callId).add(ev);
});
this.callEventGroupers = buildCallEventGroupers(this.callEventGroupers, events);
}
render() {

View file

@ -17,6 +17,7 @@ limitations under the License.
import React from "react";
import { SearchResult } from "matrix-js-sdk/src/models/search-result";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
import SettingsStore from "../../../settings/SettingsStore";
@ -27,6 +28,7 @@ import DateSeparator from "../messages/DateSeparator";
import EventTile, { haveTileForEvent } from "./EventTile";
import { shouldFormContinuation } from "../../structures/MessagePanel";
import { wantsDateSeparator } from "../../../DateUtils";
import CallEventGrouper, { buildCallEventGroupers } from "../../structures/CallEventGrouper";
interface IProps {
// a matrix-js-sdk SearchResult containing the details of this result
@ -42,6 +44,20 @@ interface IProps {
@replaceableComponent("views.rooms.SearchResultTile")
export default class SearchResultTile extends React.Component<IProps> {
static contextType = RoomContext;
public context!: React.ContextType<typeof RoomContext>;
// A map of <callId, CallEventGrouper>
private callEventGroupers = new Map<string, CallEventGrouper>();
constructor(props, context) {
super(props, context);
this.buildCallEventGroupers(this.props.searchResult.context.getTimeline());
}
private buildCallEventGroupers(events?: MatrixEvent[]): void {
this.callEventGroupers = buildCallEventGroupers(this.callEventGroupers, events);
}
public render() {
const result = this.props.searchResult;
@ -109,6 +125,7 @@ export default class SearchResultTile extends React.Component<IProps> {
timelineRenderingType={TimelineRenderingType.Search}
lastInSection={lastInSection}
continuation={continuation}
callEventGrouper={this.callEventGroupers.get(mxEv.getContent().call_id)}
/>,
);
}