Fix onRoomStateMember debouncing

Don't have debounced functions take arsg, because they won't be the same for each invocation.
This commit is contained in:
David Baker 2016-07-26 18:15:26 +01:00
parent 4ecf5f6372
commit 31399254b6
2 changed files with 20 additions and 10 deletions

View file

@ -482,9 +482,7 @@ module.exports = React.createClass({
} }
}, },
// rate limited because a power level change will emit an event for every onRoomStateMember: function(ev, state, member) {
// member in the room.
onRoomStateMember: new rate_limited_func(function(ev, state, member) {
// ignore if we don't have a room yet // ignore if we don't have a room yet
if (!this.state.room) { if (!this.state.room) {
return; return;
@ -495,6 +493,15 @@ module.exports = React.createClass({
return; return;
} }
if (this.props.ConferenceHandler &&
member.userId === this.props.ConferenceHandler.getConferenceUserIdForRoom(member.roomId)) {
this._updateConfCallNotification();
}
this._updateRoomMembers();
},
_updateRoomMembers: new rate_limited_func(function() {
// a member state changed in this room, refresh the tab complete list // a member state changed in this room, refresh the tab complete list
this.tabComplete.loadEntries(this.state.room); this.tabComplete.loadEntries(this.state.room);
this._updateAutoComplete(); this._updateAutoComplete();
@ -508,11 +515,6 @@ module.exports = React.createClass({
joining: false joining: false
}); });
} }
if (this.props.ConferenceHandler &&
member.userId === this.props.ConferenceHandler.getConferenceUserIdForRoom(member.roomId)) {
this._updateConfCallNotification();
}
}, 500), }, 500),
_hasUnsentMessages: function(room) { _hasUnsentMessages: function(room) {

View file

@ -14,6 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/**
* 'debounces' a function to only execute every n milliseconds.
* Useful when react-sdk gets many, many events but only wants
* to update the interface once for all of them.
*
* Note that the function must not take arguments, since the args
* could be different for each invocarion of the function.
*/
module.exports = function(f, minIntervalMs) { module.exports = function(f, minIntervalMs) {
this.lastCall = 0; this.lastCall = 0;
this.scheduledCall = undefined; this.scheduledCall = undefined;
@ -23,13 +31,13 @@ module.exports = function(f, minIntervalMs) {
var now = Date.now(); var now = Date.now();
if (self.lastCall < now - minIntervalMs) { if (self.lastCall < now - minIntervalMs) {
f.apply(this, arguments); f.apply(this);
self.lastCall = now; self.lastCall = now;
} else if (self.scheduledCall === undefined) { } else if (self.scheduledCall === undefined) {
self.scheduledCall = setTimeout( self.scheduledCall = setTimeout(
() => { () => {
self.scheduledCall = undefined; self.scheduledCall = undefined;
f.apply(this, arguments); f.apply(this);
self.lastCall = now; self.lastCall = now;
}, },
(self.lastCall + minIntervalMs) - now (self.lastCall + minIntervalMs) - now