diff --git a/src/controllers/organisms/RoomView.js b/src/controllers/organisms/RoomView.js index e5fe6ce2..f33b5ee9 100644 --- a/src/controllers/organisms/RoomView.js +++ b/src/controllers/organisms/RoomView.js @@ -288,6 +288,7 @@ module.exports = { fillSpace: function() { if (!this.refs.messagePanel) return; + if (this.state.searchResults) return; // TODO: paginate search results var messageWrapperScroll = this._getScrollNode(); if (messageWrapperScroll.scrollTop < messageWrapperScroll.clientHeight && this.state.room.oldState.paginationToken) { this.setState({paginating: true}); @@ -426,7 +427,7 @@ module.exports = { onSearch: function(term, scope) { var filter; - if (scope === "Room") { // FIXME: should be enum + if (scope === "Room") { filter = { // XXX: it's unintuitive that the filter for searching doesn't have the same shape as the v2 filter API :( rooms: [ @@ -443,6 +444,14 @@ module.exports = { search_term: term, filter: filter, order_by: "recent", + include_state: true, + groupings: { + group_by: [ + { + key: "room_id" + } + ] + }, event_context: { before_limit: 1, after_limit: 1, @@ -465,13 +474,14 @@ module.exports = { .sort(function(a, b) { b.length - a.length }); } else { - // sqlite doesn't, so just highlight the literal search term + // sqlite doesn't, so just try to highlight the literal search term highlights = [ term ]; } self.setState({ highlights: highlights, searchResults: data, + searchScope: scope, }); }, function(error) { var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); @@ -484,39 +494,51 @@ module.exports = { getEventTiles: function() { var DateSeparator = sdk.getComponent('molecules.DateSeparator'); + var cli = MatrixClientPeg.get(); var ret = []; var count = 0; var EventTile = sdk.getComponent('messages.Event'); + var self = this; if (this.state.searchResults) { - // XXX: this dance is foul, due to the results API not returning sorted results + // XXX: this dance is foul, due to the results API not directly returning sorted results var results = this.state.searchResults.search_categories.room_events.results; - var eventIds = Object.keys(results); - // XXX: todo: merge overlapping results somehow? - // XXX: why doesn't searching on name work? - var resultList = eventIds.map(function(key) { return results[key]; }); // .sort(function(a, b) { b.rank - a.rank }); - for (var i = 0; i < resultList.length; i++) { - var ts1 = resultList[i].result.origin_server_ts; - ret.push(