Use a cancel function
rather than checking queryList each time
This commit is contained in:
parent
23a25e550d
commit
c42b705497
1 changed files with 16 additions and 12 deletions
|
@ -194,6 +194,7 @@ module.exports = React.createClass({
|
||||||
address: query,
|
address: query,
|
||||||
isKnown: false,
|
isKnown: false,
|
||||||
};
|
};
|
||||||
|
if (this._cancelThreepidLookup) this._cancelThreepidLookup();
|
||||||
if (addrType == 'email') {
|
if (addrType == 'email') {
|
||||||
this._lookupThreepid(addrType, query).done();
|
this._lookupThreepid(addrType, query).done();
|
||||||
}
|
}
|
||||||
|
@ -216,6 +217,7 @@ module.exports = React.createClass({
|
||||||
inviteList: inviteList,
|
inviteList: inviteList,
|
||||||
queryList: [],
|
queryList: [],
|
||||||
});
|
});
|
||||||
|
if (this._cancelThreepidLookup) this._cancelThreepidLookup();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -233,6 +235,7 @@ module.exports = React.createClass({
|
||||||
inviteList: inviteList,
|
inviteList: inviteList,
|
||||||
queryList: [],
|
queryList: [],
|
||||||
});
|
});
|
||||||
|
if (this._cancelThreepidLookup) this._cancelThreepidLookup();
|
||||||
},
|
},
|
||||||
|
|
||||||
_getDirectMessageRoom: function(addr) {
|
_getDirectMessageRoom: function(addr) {
|
||||||
|
@ -436,31 +439,32 @@ module.exports = React.createClass({
|
||||||
inviteList: inviteList,
|
inviteList: inviteList,
|
||||||
queryList: [],
|
queryList: [],
|
||||||
});
|
});
|
||||||
|
if (this._cancelThreepidLookup) this._cancelThreepidLookup();
|
||||||
return inviteList;
|
return inviteList;
|
||||||
},
|
},
|
||||||
|
|
||||||
_lookupThreepid: function(medium, address) {
|
_lookupThreepid: function(medium, address) {
|
||||||
|
let cancelled = false;
|
||||||
|
// Note that we can't safely remove this after we're done
|
||||||
|
// because we don't know that it's the same one, so we just
|
||||||
|
// leave it: it's replacing the old one each time so it's
|
||||||
|
// not like they leak.
|
||||||
|
this._cancelThreepidLookup = function() {
|
||||||
|
cancelled = true;
|
||||||
|
}
|
||||||
|
|
||||||
// wait a bit to let the user finish typing
|
// wait a bit to let the user finish typing
|
||||||
return q.delay(500).then(() => {
|
return q.delay(500).then(() => {
|
||||||
// If the query has changed, forget it
|
if (cancelled) return null;
|
||||||
if (this.state.queryList[0] && this.state.queryList[0].address !== address) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return MatrixClientPeg.get().lookupThreePid(medium, address);
|
return MatrixClientPeg.get().lookupThreePid(medium, address);
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res === null || !res.mxid) return null;
|
if (res === null || !res.mxid) return null;
|
||||||
// If the query has changed now, drop the response
|
if (cancelled) return null;
|
||||||
if (this.state.queryList[0] && this.state.queryList[0].address !== address) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MatrixClientPeg.get().getProfileInfo(res.mxid);
|
return MatrixClientPeg.get().getProfileInfo(res.mxid);
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res === null) return null;
|
if (res === null) return null;
|
||||||
// If the query has changed now, drop the response
|
if (cancelled) return null;
|
||||||
if (this.state.queryList[0] && this.state.queryList[0].address !== address) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
this.setState({
|
this.setState({
|
||||||
queryList: [{
|
queryList: [{
|
||||||
// an InviteAddressType
|
// an InviteAddressType
|
||||||
|
|
Loading…
Reference in a new issue