2015-12-23 13:10:08 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
2019-12-20 03:45:24 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2015-12-23 13:10:08 +03: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.
|
|
|
|
*/
|
|
|
|
|
2019-09-06 17:04:46 +03:00
|
|
|
import React from 'react';
|
2021-07-01 13:17:18 +03:00
|
|
|
import EventTile, { haveTileForEvent } from "./EventTile";
|
|
|
|
import DateSeparator from '../messages/DateSeparator';
|
2020-09-16 13:26:15 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2021-06-29 15:11:58 +03:00
|
|
|
import { UIFeature } from "../../../settings/UIFeature";
|
2021-07-01 13:17:18 +03:00
|
|
|
import { RoomPermalinkCreator } from '../../../utils/permalinks/Permalinks';
|
2021-06-29 15:11:58 +03:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2015-12-23 13:10:08 +03:00
|
|
|
|
2021-07-01 13:17:18 +03:00
|
|
|
interface IProps {
|
|
|
|
// a matrix-js-sdk SearchResult containing the details of this result
|
|
|
|
searchResult: any;
|
|
|
|
// a list of strings to be highlighted in the results
|
|
|
|
searchHighlights?: string[];
|
|
|
|
// href for the highlights in this result
|
|
|
|
resultLink?: string;
|
|
|
|
onHeightChanged?: () => void;
|
|
|
|
permalinkCreator?: RoomPermalinkCreator;
|
|
|
|
}
|
2016-02-22 20:19:04 +03:00
|
|
|
|
2021-07-01 13:17:18 +03:00
|
|
|
@replaceableComponent("views.rooms.SearchResultTile")
|
|
|
|
export default class SearchResultTile extends React.Component<IProps> {
|
|
|
|
public render() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const result = this.props.searchResult;
|
|
|
|
const mxEv = result.context.getEvent();
|
|
|
|
const eventId = mxEv.getId();
|
2015-12-23 13:10:08 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const ts1 = mxEv.getTs();
|
|
|
|
const ret = [<DateSeparator key={ts1 + "-search"} ts={ts1} />];
|
2021-06-06 08:55:01 +03:00
|
|
|
const alwaysShowTimestamps = SettingsStore.getValue("alwaysShowTimestamps");
|
2015-12-23 13:10:08 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const timeline = result.context.getTimeline();
|
2020-09-16 13:26:15 +03:00
|
|
|
for (let j = 0; j < timeline.length; j++) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const ev = timeline[j];
|
2020-09-16 13:26:15 +03:00
|
|
|
let highlights;
|
2017-10-11 19:56:17 +03:00
|
|
|
const contextual = (j != result.context.getOurEventIndex());
|
2015-12-23 13:10:08 +03:00
|
|
|
if (!contextual) {
|
|
|
|
highlights = this.props.searchHighlights;
|
|
|
|
}
|
2019-12-21 00:43:06 +03:00
|
|
|
if (haveTileForEvent(ev)) {
|
2020-09-16 13:26:15 +03:00
|
|
|
ret.push((
|
|
|
|
<EventTile
|
|
|
|
key={`${eventId}+${j}`}
|
|
|
|
mxEvent={ev}
|
|
|
|
contextual={contextual}
|
|
|
|
highlights={highlights}
|
|
|
|
permalinkCreator={this.props.permalinkCreator}
|
|
|
|
highlightLink={this.props.resultLink}
|
|
|
|
onHeightChanged={this.props.onHeightChanged}
|
|
|
|
isTwelveHour={SettingsStore.getValue("showTwelveHourTimestamps")}
|
2021-06-06 08:55:01 +03:00
|
|
|
alwaysShowTimestamps={alwaysShowTimestamps}
|
2020-09-16 13:26:15 +03:00
|
|
|
enableFlair={SettingsStore.getValue(UIFeature.Flair)}
|
|
|
|
/>
|
|
|
|
));
|
2015-12-23 13:10:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (
|
2020-09-18 14:15:56 +03:00
|
|
|
<li data-scroll-tokens={eventId}>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ ret }
|
2015-12-23 13:10:08 +03:00
|
|
|
</li>);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
|
|
|
}
|