From 2ee840922de7bce2b2875a40a5a707adb3e786ab Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 29 Oct 2015 02:03:04 +0000 Subject: [PATCH] basic implementation of search --- src/controllers/organisms/RoomView.js | 44 +++++++++++++++++-- src/skins/vector/views/molecules/SearchBar.js | 4 +- src/skins/vector/views/organisms/RoomView.js | 4 ++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/controllers/organisms/RoomView.js b/src/controllers/organisms/RoomView.js index b05307d1..1824f7fd 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(
  • ); // Rank: {resultList[i].rank} + var mxEv = new Matrix.MatrixEvent(resultList[i].result); + if (resultList[i].context.events_before[0]) { + var mxEv2 = new Matrix.MatrixEvent(resultList[i].context.events_before[0]); + ret.push(
  • ); + } + ret.push(
  • ); + if (resultList[i].context.events_after[0]) { + var mxEv2 = new Matrix.MatrixEvent(resultList[i].context.events_after[0]); + ret.push(
  • ); + } + } return ret; } diff --git a/src/skins/vector/views/molecules/SearchBar.js b/src/skins/vector/views/molecules/SearchBar.js index da1dfb6b..04130ca5 100644 --- a/src/skins/vector/views/molecules/SearchBar.js +++ b/src/skins/vector/views/molecules/SearchBar.js @@ -44,14 +44,14 @@ module.exports = React.createClass({ onSearchChange: function(e) { if (e.keyCode === 13) { - this.props.onSearch(this.refs.search_term.getDOMNode().value); + this.props.onSearch(this.refs.search_term.getDOMNode().value, this.state.scope); } }, render: function() { return (
    - +
    This Room
    All Rooms
    diff --git a/src/skins/vector/views/organisms/RoomView.js b/src/skins/vector/views/organisms/RoomView.js index 3406448c..0a2d2411 100644 --- a/src/skins/vector/views/organisms/RoomView.js +++ b/src/skins/vector/views/organisms/RoomView.js @@ -63,6 +63,10 @@ module.exports = React.createClass({ this.setState(this.getInitialState()); }, + onSearchClick: function() { + this.setState({ searching: true }); + }, + onConferenceNotificationClick: function() { dis.dispatch({ action: 'place_call',