From d19be4568556cef1e4e4f8ab447cc0cfa83513fa Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Sun, 23 Feb 2020 18:17:17 -0800 Subject: [PATCH] add simple lock around lokiPublicChatAPI binding (on top of the clearing, only one is probably needed) --- libtextsecure/message_receiver.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 8397df5f8..0e6204016 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -24,6 +24,8 @@ /* eslint-disable more/no-then */ /* eslint-disable no-unreachable */ +let openGroupBound = false; + function MessageReceiver(username, password, signalingKey, options = {}) { this.count = 0; @@ -51,11 +53,15 @@ function MessageReceiver(username, password, signalingKey, options = {}) { // only do this once to prevent duplicates if (lokiPublicChatAPI) { - // bind events - lokiPublicChatAPI.on( - 'publicMessage', - this.handleUnencryptedMessage.bind(this) - ); + window.log.info('Binding open group events handler', openGroupBound); + if (!openGroupBound) { + // clear any previous binding + lokiPublicChatAPI.removeAllListeners('publicMessage'); + // we only need one MR in the system handling these + // bind events + lokiPublicChatAPI.on('publicMessage', this.handleUnencryptedMessage.bind(this)); + openGroupBound = true; + } } else { window.log.error('Can not handle open group data, API is not available'); }