2015-12-23 18:10:08 +08:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
const React = require('react');
|
2017-12-26 09:03:18 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-10-12 00:56:17 +08:00
|
|
|
const sdk = require('../../../index');
|
2015-12-23 18:10:08 +08:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'SearchResult',
|
|
|
|
|
|
|
|
propTypes: {
|
2016-01-07 00:46:29 +08:00
|
|
|
// a matrix-js-sdk SearchResult containing the details of this result
|
2017-12-26 09:03:18 +08:00
|
|
|
searchResult: PropTypes.object.isRequired,
|
2016-01-07 00:46:29 +08:00
|
|
|
|
|
|
|
// a list of strings to be highlighted in the results
|
2017-12-26 09:03:18 +08:00
|
|
|
searchHighlights: PropTypes.array,
|
2016-01-07 00:46:29 +08:00
|
|
|
|
2016-02-18 03:50:04 +08:00
|
|
|
// href for the highlights in this result
|
2017-12-26 09:03:18 +08:00
|
|
|
resultLink: PropTypes.string,
|
2016-02-23 01:19:04 +08:00
|
|
|
|
2019-03-06 19:27:16 +08:00
|
|
|
onHeightChanged: PropTypes.func,
|
2015-12-23 18:10:08 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-10-12 00:56:17 +08:00
|
|
|
const DateSeparator = sdk.getComponent('messages.DateSeparator');
|
|
|
|
const EventTile = sdk.getComponent('rooms.EventTile');
|
|
|
|
const result = this.props.searchResult;
|
|
|
|
const mxEv = result.context.getEvent();
|
|
|
|
const eventId = mxEv.getId();
|
2015-12-23 18:10:08 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
const ts1 = mxEv.getTs();
|
|
|
|
const ret = [<DateSeparator key={ts1 + "-search"} ts={ts1} />];
|
2015-12-23 18:10:08 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
const timeline = result.context.getTimeline();
|
2015-12-23 18:10:08 +08:00
|
|
|
for (var j = 0; j < timeline.length; j++) {
|
2017-10-12 00:56:17 +08:00
|
|
|
const ev = timeline[j];
|
2015-12-23 18:10:08 +08:00
|
|
|
var highlights;
|
2017-10-12 00:56:17 +08:00
|
|
|
const contextual = (j != result.context.getOurEventIndex());
|
2015-12-23 18:10:08 +08:00
|
|
|
if (!contextual) {
|
|
|
|
highlights = this.props.searchHighlights;
|
|
|
|
}
|
|
|
|
if (EventTile.haveTileForEvent(ev)) {
|
|
|
|
ret.push(<EventTile key={eventId+"+"+j} mxEvent={ev} contextual={contextual} highlights={highlights}
|
2019-02-22 19:22:36 +08:00
|
|
|
permalinkCreator={this.props.permalinkCreator}
|
2016-02-23 01:19:04 +08:00
|
|
|
highlightLink={this.props.resultLink}
|
2019-03-06 19:27:16 +08:00
|
|
|
onHeightChanged={this.props.onHeightChanged} />);
|
2015-12-23 18:10:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (
|
2017-05-04 17:00:13 +08:00
|
|
|
<li data-scroll-tokens={eventId+"+"+j}>
|
2017-10-12 00:56:17 +08:00
|
|
|
{ ret }
|
2015-12-23 18:10:08 +08:00
|
|
|
</li>);
|
|
|
|
},
|
|
|
|
});
|