From 6d332256b53582d288df269c7b5c77d192225fae Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 16 Sep 2016 18:48:47 +0100 Subject: [PATCH] Ignore results of old requests --- src/components/structures/RoomDirectory.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index 50a247ed24..9c65c6f16d 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -95,11 +95,19 @@ module.exports = React.createClass({ }, getMoreRooms: function() { + const my_filter_string = this.filterString; const opts = {limit: 20}; if (this.nextBatch) opts.since = this.nextBatch; - if (this.filterString) opts.filter = { generic_search_term: this.filterString } ; + if (this.filterString) opts.filter = { generic_search_term: my_filter_string } ; this.setState({loading: true}); return MatrixClientPeg.get().publicRooms(opts).then((data) => { + if (my_filter_string != this.filterString) { + // if the filter has changed since this request was sent, + // throw away the result (don't even clear the busy flag + // since we must still have a request in flight) + return; + } + this.nextBatch = data.next_batch; this.setState((s) => { s.publicRooms.push(...data.chunk); @@ -108,6 +116,11 @@ module.exports = React.createClass({ }); return Boolean(data.next_batch); }, (err) => { + if (my_filter_string != this.filterString) { + // as above: we don't care about errors for old + // requests either + return; + } this.setState({ loading: false }); console.error("Failed to get publicRooms: %s", JSON.stringify(err)); var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");