diff --git a/src/Notifier.js b/src/Notifier.js index b030f1b6f9..36a6f13bb6 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -153,10 +153,12 @@ const Notifier = { }, start: function() { - this.boundOnEvent = this.onEvent.bind(this); - this.boundOnSyncStateChange = this.onSyncStateChange.bind(this); - this.boundOnRoomReceipt = this.onRoomReceipt.bind(this); - this.boundOnEventDecrypted = this.onEventDecrypted.bind(this); + // do not re-bind in the case of repeated call + this.boundOnEvent = this.boundOnEvent || this.onEvent.bind(this); + this.boundOnSyncStateChange = this.boundOnSyncStateChange || this.onSyncStateChange.bind(this); + this.boundOnRoomReceipt = this.boundOnRoomReceipt || this.onRoomReceipt.bind(this); + this.boundOnEventDecrypted = this.boundOnEventDecrypted || this.onEventDecrypted.bind(this); + MatrixClientPeg.get().on('event', this.boundOnEvent); MatrixClientPeg.get().on('Room.receipt', this.boundOnRoomReceipt); MatrixClientPeg.get().on('Event.decrypted', this.boundOnEventDecrypted); @@ -166,7 +168,7 @@ const Notifier = { }, stop: function() { - if (MatrixClientPeg.get() && this.boundOnRoomTimeline) { + if (MatrixClientPeg.get()) { MatrixClientPeg.get().removeListener('Event', this.boundOnEvent); MatrixClientPeg.get().removeListener('Room.receipt', this.boundOnRoomReceipt); MatrixClientPeg.get().removeListener('Event.decrypted', this.boundOnEventDecrypted); diff --git a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js index 5ae90b694e..6aab777ee1 100644 --- a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js +++ b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js @@ -46,7 +46,7 @@ export default class ManageEventIndexDialog extends React.Component { }; } - async updateCurrentRoom(room) { + updateCurrentRoom = async (room) => { const eventIndex = EventIndexPeg.get(); const stats = await eventIndex.getStats(); let currentRoom = null; @@ -63,13 +63,13 @@ export default class ManageEventIndexDialog extends React.Component { roomCount: roomCount, currentRoom: currentRoom, }); - } + }; componentWillUnmount(): void { const eventIndex = EventIndexPeg.get(); if (eventIndex !== null) { - eventIndex.removeListener("changedCheckpoint", this.updateCurrentRoom.bind(this)); + eventIndex.removeListener("changedCheckpoint", this.updateCurrentRoom); } } @@ -83,7 +83,7 @@ export default class ManageEventIndexDialog extends React.Component { const eventIndex = EventIndexPeg.get(); if (eventIndex !== null) { - eventIndex.on("changedCheckpoint", this.updateCurrentRoom.bind(this)); + eventIndex.on("changedCheckpoint", this.updateCurrentRoom); const stats = await eventIndex.getStats(); const roomStats = eventIndex.crawlingRooms(); diff --git a/src/components/structures/FilePanel.js b/src/components/structures/FilePanel.js index 4c02f925fc..f8c03be864 100644 --- a/src/components/structures/FilePanel.js +++ b/src/components/structures/FilePanel.js @@ -95,8 +95,8 @@ const FilePanel = createReactClass({ // this could be made more general in the future or the filter logic // could be fixed. if (EventIndexPeg.get() !== null) { - client.on('Room.timeline', this.onRoomTimeline.bind(this)); - client.on('Event.decrypted', this.onEventDecrypted.bind(this)); + client.on('Room.timeline', this.onRoomTimeline); + client.on('Event.decrypted', this.onEventDecrypted); } }, @@ -107,8 +107,8 @@ const FilePanel = createReactClass({ if (!MatrixClientPeg.get().isRoomEncrypted(this.props.roomId)) return; if (EventIndexPeg.get() !== null) { - client.removeListener('Room.timeline', this.onRoomTimeline.bind(this)); - client.removeListener('Event.decrypted', this.onEventDecrypted.bind(this)); + client.removeListener('Room.timeline', this.onRoomTimeline); + client.removeListener('Event.decrypted', this.onEventDecrypted); } }, diff --git a/src/components/views/settings/EventIndexPanel.js b/src/components/views/settings/EventIndexPanel.js index 68faa53e53..ded62354cb 100644 --- a/src/components/views/settings/EventIndexPanel.js +++ b/src/components/views/settings/EventIndexPanel.js @@ -37,7 +37,7 @@ export default class EventIndexPanel extends React.Component { }; } - async updateCurrentRoom(room) { + updateCurrentRoom = async (room) => { const eventIndex = EventIndexPeg.get(); const stats = await eventIndex.getStats(); @@ -45,13 +45,13 @@ export default class EventIndexPanel extends React.Component { eventIndexSize: stats.size, roomCount: stats.roomCount, }); - } + }; componentWillUnmount(): void { const eventIndex = EventIndexPeg.get(); if (eventIndex !== null) { - eventIndex.removeListener("changedCheckpoint", this.updateCurrentRoom.bind(this)); + eventIndex.removeListener("changedCheckpoint", this.updateCurrentRoom); } } @@ -68,7 +68,7 @@ export default class EventIndexPanel extends React.Component { let roomCount = 0; if (eventIndex !== null) { - eventIndex.on("changedCheckpoint", this.updateCurrentRoom.bind(this)); + eventIndex.on("changedCheckpoint", this.updateCurrentRoom); const stats = await eventIndex.getStats(); eventIndexSize = stats.size; diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.js b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.js index 42947d1fb2..a3a9cb78c5 100644 --- a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.js +++ b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.js @@ -107,20 +107,20 @@ export default class RolesRoomSettingsTab extends React.Component { }; componentDidMount(): void { - MatrixClientPeg.get().on("RoomState.members", this._onRoomMembership.bind(this)); + MatrixClientPeg.get().on("RoomState.members", this._onRoomMembership); } componentWillUnmount(): void { const client = MatrixClientPeg.get(); if (client) { - client.removeListener("RoomState.members", this._onRoomMembership.bind(this)); + client.removeListener("RoomState.members", this._onRoomMembership); } } - _onRoomMembership(event, state, member) { + _onRoomMembership = (event, state, member) => { if (state.roomId !== this.props.roomId) return; this.forceUpdate(); - } + }; _populateDefaultPlEvents(eventsSection, stateLevel, eventsLevel) { for (const desiredEvent of Object.keys(plEventsToShow)) { diff --git a/src/integrations/IntegrationManagers.js b/src/integrations/IntegrationManagers.js index c933e5c433..3ba1aab135 100644 --- a/src/integrations/IntegrationManagers.js +++ b/src/integrations/IntegrationManagers.js @@ -54,14 +54,14 @@ export class IntegrationManagers { startWatching(): void { this.stopWatching(); this._client = MatrixClientPeg.get(); - this._client.on("accountData", this._onAccountData.bind(this)); + this._client.on("accountData", this._onAccountData); this._compileManagers(); setInterval(() => this._setupHomeserverManagers(), HS_MANAGERS_REFRESH_INTERVAL); } stopWatching(): void { if (!this._client) return; - this._client.removeListener("accountData", this._onAccountData.bind(this)); + this._client.removeListener("accountData", this._onAccountData); if (this._wellknownRefreshTimerId !== null) clearInterval(this._wellknownRefreshTimerId); } @@ -136,11 +136,11 @@ export class IntegrationManagers { this._primaryManager = null; // reset primary } - _onAccountData(ev: MatrixEvent): void { + _onAccountData = (ev: MatrixEvent): void => { if (ev.getType() === 'm.widgets') { this._compileManagers(); } - } + }; hasManager(): boolean { return this._managers.length > 0; diff --git a/src/mjolnir/Mjolnir.js b/src/mjolnir/Mjolnir.js index 4970d8e8af..0c99306278 100644 --- a/src/mjolnir/Mjolnir.js +++ b/src/mjolnir/Mjolnir.js @@ -61,7 +61,7 @@ export class Mjolnir { setup() { if (!MatrixClientPeg.get()) return; this._updateLists(SettingsStore.getValue("mjolnirRooms")); - MatrixClientPeg.get().on("RoomState.events", this._onEvent.bind(this)); + MatrixClientPeg.get().on("RoomState.events", this._onEvent); } stop() { @@ -76,7 +76,7 @@ export class Mjolnir { } if (!MatrixClientPeg.get()) return; - MatrixClientPeg.get().removeListener("RoomState.events", this._onEvent.bind(this)); + MatrixClientPeg.get().removeListener("RoomState.events", this._onEvent); } async getOrCreatePersonalList(): Promise { @@ -130,13 +130,13 @@ export class Mjolnir { this._lists = this._lists.filter(b => b.roomId !== roomId); } - _onEvent(event) { + _onEvent = (event) => { if (!MatrixClientPeg.get()) return; if (!this._roomIds.includes(event.getRoomId())) return; if (!ALL_RULE_TYPES.includes(event.getType())) return; this._updateLists(this._roomIds); - } + }; _onListsChanged(settingName, roomId, atLevel, newValue) { // We know that ban lists are only recorded at one level so we don't need to re-eval them