diff --git a/src/controllers/organisms/RoomView.js b/src/controllers/organisms/RoomView.js index b05307d10..1824f7fd6 100644 --- a/src/controllers/organisms/RoomView.js +++ b/src/controllers/organisms/RoomView.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +var Matrix = require("matrix-js-sdk"); var MatrixClientPeg = require("matrix-react-sdk/lib/MatrixClientPeg"); var React = require("react"); var q = require("q"); @@ -38,7 +39,8 @@ module.exports = { uploadingRoomSettings: false, numUnreadMessages: 0, draggingFile: false, - searchResults: [], + searching: false, + searchResults: null, } }, @@ -357,9 +359,23 @@ module.exports = { return WhoIsTyping.whoIsTypingString(this.state.room); }, - onSearch: function(term) { - MatrixClientPeg.get().searchMessageText(term).then(function(data) { + onSearch: function(term, scope) { + var self = this; + MatrixClientPeg.get().search({ + body: { + search_categories: { + room_events: { + search_term: term, + event_context: { + before_limit: 1, + after_limit: 1, + } + } + } + } + }).then(function(data) { self.setState({ + searchTerm: term, searchResults: data, }); }, function(error) { @@ -375,7 +391,27 @@ module.exports = { var EventTile = sdk.getComponent('molecules.EventTile'); - if (this.state.searchResults.length) { + if (this.state.searchResults) { + // XXX: this dance is foul, due to the results API not 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(