Skip to content

Commit e43edee

Browse files
committed
call highlighted search terms highlights, and uphold them if provided by synapse
1 parent 8de94d4 commit e43edee

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

‎src/controllers/organisms/RoomView.js‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,26 @@ module.exports = {
451451
}
452452
}
453453
}).then(function(data) {
454+
// for debugging:
455+
// data.search_categories.room_events.highlights = ["hello", "everybody"];
456+
457+
var highlights;
458+
if (data.search_categories.room_events.highlights &&
459+
data.search_categories.room_events.highlights.length > 0)
460+
{
461+
// postgres on synapse returns us precise details of the
462+
// strings which actually got matched for highlighting.
463+
// for overlapping highlights, favour longer (more specific) terms first
464+
highlights = data.search_categories.room_events.highlights
465+
.sort(function(a, b) { b.length - a.length });
466+
}
467+
else {
468+
// sqlite doesn't, so just highlight the literal search term
469+
highlights = [ term ];
470+
}
471+
454472
self.setState({
455-
searchTerm: term,
473+
highlights: highlights,
456474
searchResults: data,
457475
});
458476
}, function(error) {
@@ -490,7 +508,7 @@ module.exports = {
490508
}
491509
}
492510
if (EventTile.haveTileForEvent(mxEv)) {
493-
ret.push(<li key={mxEv.getId() + "+0"}><EventTile mxEvent={mxEv} searchTerm={this.state.searchTerm}/></li>);
511+
ret.push(<li key={mxEv.getId() + "+0"}><EventTile mxEvent={mxEv} highlights={this.state.highlights}/></li>);
494512
}
495513
if (resultList[i].context.events_after[0]) {
496514
var mxEv2 = new Matrix.MatrixEvent(resultList[i].context.events_after[0]);
@@ -530,7 +548,7 @@ module.exports = {
530548
var ts0 = this.state.room.timeline[i - 1].getTs();
531549
var ts1 = this.state.room.timeline[i].getTs();
532550
if (new Date(ts0).toDateString() !== new Date(ts1).toDateString()) {
533-
dateSeparator = <DateSeparator key={ts1} ts={ts1}/>;
551+
dateSeparator = <li key={ts1}><DateSeparator key={ts1} ts={ts1}/></li>;
534552
continuation = false;
535553
}
536554
}

0 commit comments

Comments
 (0)