diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 9aa192d9ca..6d35f76529 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -482,9 +482,7 @@ module.exports = React.createClass({ } }, - // rate limited because a power level change will emit an event for every - // member in the room. - onRoomStateMember: new rate_limited_func(function(ev, state, member) { + onRoomStateMember: function(ev, state, member) { // ignore if we don't have a room yet if (!this.state.room) { return; @@ -495,6 +493,15 @@ module.exports = React.createClass({ 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 this.tabComplete.loadEntries(this.state.room); this._updateAutoComplete(); @@ -508,11 +515,6 @@ module.exports = React.createClass({ joining: false }); } - - if (this.props.ConferenceHandler && - member.userId === this.props.ConferenceHandler.getConferenceUserIdForRoom(member.roomId)) { - this._updateConfCallNotification(); - } }, 500), _hasUnsentMessages: function(room) { diff --git a/src/ratelimitedfunc.js b/src/ratelimitedfunc.js index 94626d5ad9..ed892f4eac 100644 --- a/src/ratelimitedfunc.js +++ b/src/ratelimitedfunc.js @@ -14,6 +14,14 @@ See the License for the specific language governing permissions and 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) { this.lastCall = 0; this.scheduledCall = undefined; @@ -23,13 +31,13 @@ module.exports = function(f, minIntervalMs) { var now = Date.now(); if (self.lastCall < now - minIntervalMs) { - f.apply(this, arguments); + f.apply(this); self.lastCall = now; } else if (self.scheduledCall === undefined) { self.scheduledCall = setTimeout( () => { self.scheduledCall = undefined; - f.apply(this, arguments); + f.apply(this); self.lastCall = now; }, (self.lastCall + minIntervalMs) - now