2015-12-23 10:10:08 +00:00
|
|
|
/*
|
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
2019-12-19 17:45:24 -07:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2015-12-23 10:10:08 +00:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-06-24 18:45:23 -04:00
|
|
|
import React from "react";
|
|
|
|
|
import { SearchResult } from "matrix-js-sdk/src/models/search-result";
|
2022-02-22 10:39:08 +00:00
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2022-01-12 17:16:00 +00:00
|
|
|
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
|
2020-09-16 11:26:15 +01:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2021-07-01 11:17:18 +01:00
|
|
|
import { RoomPermalinkCreator } from '../../../utils/permalinks/Permalinks';
|
2021-06-24 18:45:23 -04:00
|
|
|
import DateSeparator from "../messages/DateSeparator";
|
2022-03-22 23:16:25 -06:00
|
|
|
import EventTile from "./EventTile";
|
2022-01-26 20:15:44 +00:00
|
|
|
import { shouldFormContinuation } from "../../structures/MessagePanel";
|
|
|
|
|
import { wantsDateSeparator } from "../../../DateUtils";
|
2022-08-30 15:13:39 -04:00
|
|
|
import LegacyCallEventGrouper, { buildLegacyCallEventGroupers } from "../../structures/LegacyCallEventGrouper";
|
2022-03-22 23:16:25 -06:00
|
|
|
import { haveRendererForEvent } from "../../../events/EventTileFactory";
|
2021-06-24 18:45:23 -04:00
|
|
|
|
|
|
|
|
interface IProps {
|
2021-07-01 11:17:18 +01:00
|
|
|
// a matrix-js-sdk SearchResult containing the details of this result
|
2021-06-24 18:45:23 -04:00
|
|
|
searchResult: SearchResult;
|
2021-07-01 11:17:18 +01:00
|
|
|
// a list of strings to be highlighted in the results
|
2021-06-24 18:45:23 -04:00
|
|
|
searchHighlights?: string[];
|
|
|
|
|
// href for the highlights in this result
|
|
|
|
|
resultLink?: string;
|
2021-07-01 11:17:18 +01:00
|
|
|
onHeightChanged?: () => void;
|
|
|
|
|
permalinkCreator?: RoomPermalinkCreator;
|
2021-06-24 18:45:23 -04:00
|
|
|
}
|
2015-12-23 10:10:08 +00:00
|
|
|
|
2021-06-24 18:45:23 -04:00
|
|
|
export default class SearchResultTile extends React.Component<IProps> {
|
2021-06-16 20:40:47 -04:00
|
|
|
static contextType = RoomContext;
|
2022-02-22 10:39:08 +00:00
|
|
|
public context!: React.ContextType<typeof RoomContext>;
|
|
|
|
|
|
2022-08-30 15:13:39 -04:00
|
|
|
// A map of <callId, LegacyCallEventGrouper>
|
|
|
|
|
private callEventGroupers = new Map<string, LegacyCallEventGrouper>();
|
2022-02-22 10:39:08 +00:00
|
|
|
|
|
|
|
|
constructor(props, context) {
|
|
|
|
|
super(props, context);
|
|
|
|
|
|
2022-08-30 15:13:39 -04:00
|
|
|
this.buildLegacyCallEventGroupers(this.props.searchResult.context.getTimeline());
|
2022-02-22 10:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-30 15:13:39 -04:00
|
|
|
private buildLegacyCallEventGroupers(events?: MatrixEvent[]): void {
|
|
|
|
|
this.callEventGroupers = buildLegacyCallEventGroupers(this.callEventGroupers, events);
|
2022-02-22 10:39:08 +00:00
|
|
|
}
|
2021-06-16 20:40:47 -04:00
|
|
|
|
2021-06-24 18:45:23 -04:00
|
|
|
public render() {
|
2017-10-11 17:56:17 +01:00
|
|
|
const result = this.props.searchResult;
|
2022-01-26 20:15:44 +00:00
|
|
|
const resultEvent = result.context.getEvent();
|
|
|
|
|
const eventId = resultEvent.getId();
|
2015-12-23 10:10:08 +00:00
|
|
|
|
2022-01-26 20:15:44 +00:00
|
|
|
const ts1 = resultEvent.getTs();
|
2022-01-27 16:32:12 -06:00
|
|
|
const ret = [<DateSeparator key={ts1 + "-search"} roomId={resultEvent.getRoomId()} ts={ts1} />];
|
2021-06-24 18:45:23 -04:00
|
|
|
const layout = SettingsStore.getValue("layout");
|
|
|
|
|
const isTwelveHour = SettingsStore.getValue("showTwelveHourTimestamps");
|
2021-06-06 01:55:01 -04:00
|
|
|
const alwaysShowTimestamps = SettingsStore.getValue("alwaysShowTimestamps");
|
2022-03-26 18:06:25 -04:00
|
|
|
const threadsEnabled = SettingsStore.getValue("feature_thread");
|
2015-12-23 10:10:08 +00:00
|
|
|
|
2017-10-11 17:56:17 +01:00
|
|
|
const timeline = result.context.getTimeline();
|
2020-09-16 11:26:15 +01:00
|
|
|
for (let j = 0; j < timeline.length; j++) {
|
2022-01-26 20:15:44 +00:00
|
|
|
const mxEv = timeline[j];
|
2020-09-16 11:26:15 +01:00
|
|
|
let highlights;
|
2017-10-11 17:56:17 +01:00
|
|
|
const contextual = (j != result.context.getOurEventIndex());
|
2015-12-23 10:10:08 +00:00
|
|
|
if (!contextual) {
|
|
|
|
|
highlights = this.props.searchHighlights;
|
|
|
|
|
}
|
2022-01-26 20:15:44 +00:00
|
|
|
|
2022-04-14 19:23:22 -04:00
|
|
|
if (haveRendererForEvent(mxEv, this.context?.showHiddenEvents)) {
|
2022-01-26 20:15:44 +00:00
|
|
|
// do we need a date separator since the last event?
|
|
|
|
|
const prevEv = timeline[j - 1];
|
|
|
|
|
// is this a continuation of the previous message?
|
|
|
|
|
const continuation = prevEv &&
|
|
|
|
|
!wantsDateSeparator(prevEv.getDate(), mxEv.getDate()) &&
|
|
|
|
|
shouldFormContinuation(
|
|
|
|
|
prevEv,
|
|
|
|
|
mxEv,
|
2022-04-14 19:23:22 -04:00
|
|
|
this.context?.showHiddenEvents,
|
2022-03-26 18:06:25 -04:00
|
|
|
threadsEnabled,
|
2022-01-26 20:15:44 +00:00
|
|
|
TimelineRenderingType.Search,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let lastInSection = true;
|
|
|
|
|
const nextEv = timeline[j + 1];
|
|
|
|
|
if (nextEv) {
|
|
|
|
|
const willWantDateSeparator = wantsDateSeparator(mxEv.getDate(), nextEv.getDate());
|
|
|
|
|
lastInSection = (
|
|
|
|
|
willWantDateSeparator ||
|
|
|
|
|
mxEv.getSender() !== nextEv.getSender() ||
|
|
|
|
|
!shouldFormContinuation(
|
|
|
|
|
mxEv,
|
|
|
|
|
nextEv,
|
2022-04-14 19:23:22 -04:00
|
|
|
this.context?.showHiddenEvents,
|
2022-03-26 18:06:25 -04:00
|
|
|
threadsEnabled,
|
2022-01-26 20:15:44 +00:00
|
|
|
TimelineRenderingType.Search,
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 18:45:23 -04:00
|
|
|
ret.push(
|
2020-09-16 11:26:15 +01:00
|
|
|
<EventTile
|
|
|
|
|
key={`${eventId}+${j}`}
|
2022-01-26 20:15:44 +00:00
|
|
|
mxEvent={mxEv}
|
2021-06-24 18:45:23 -04:00
|
|
|
layout={layout}
|
2020-09-16 11:26:15 +01:00
|
|
|
contextual={contextual}
|
|
|
|
|
highlights={highlights}
|
|
|
|
|
permalinkCreator={this.props.permalinkCreator}
|
|
|
|
|
highlightLink={this.props.resultLink}
|
|
|
|
|
onHeightChanged={this.props.onHeightChanged}
|
2021-06-24 18:45:23 -04:00
|
|
|
isTwelveHour={isTwelveHour}
|
2021-06-06 01:55:01 -04:00
|
|
|
alwaysShowTimestamps={alwaysShowTimestamps}
|
2022-01-26 20:15:44 +00:00
|
|
|
lastInSection={lastInSection}
|
|
|
|
|
continuation={continuation}
|
2022-02-22 10:39:08 +00:00
|
|
|
callEventGrouper={this.callEventGroupers.get(mxEv.getContent().call_id)}
|
2021-06-24 18:45:23 -04:00
|
|
|
/>,
|
|
|
|
|
);
|
2015-12-23 10:10:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-24 18:45:23 -04:00
|
|
|
|
2022-01-26 20:15:44 +00:00
|
|
|
return <li data-scroll-tokens={eventId}>
|
|
|
|
|
<ol>{ ret }</ol>
|
|
|
|
|
</li>;
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
|
|
|
|
}
|