From 9d33ec596771581af04487dca605419c42a7587b Mon Sep 17 00:00:00 2001 From: mhiaror <107958541+mhiaror@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:10:23 -0400 Subject: [PATCH] fix message receipts getting disabled if custom throttleTime is passed (#236) --- src/core/chatSession.js | 7 +++++++ src/globalConfig.js | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/chatSession.js b/src/core/chatSession.js index 093aa35..b631f80 100644 --- a/src/core/chatSession.js +++ b/src/core/chatSession.js @@ -217,6 +217,13 @@ var setGlobalConfig = config => { GlobalConfig.updateThrottleTime(config.features?.messageReceipts?.throttleTime); if (config.features?.messageReceipts?.shouldSendMessageReceipts === false) { GlobalConfig.removeFeatureFlag(FEATURES.MESSAGE_RECEIPTS_ENABLED); + } else { + /** + * Note: if update config is called with `config.features` array, it replaces default config + * this ensure `message-receipts` feature is always enabled. + * Only way to disable message receipts is by setting config.features.messageReceipts.shouldSendMessageReceipts == false + * */ + setFeatureFlag(FEATURES.MESSAGE_RECEIPTS_ENABLED); } }; diff --git a/src/globalConfig.js b/src/globalConfig.js index c833ad6..05e28f8 100644 --- a/src/globalConfig.js +++ b/src/globalConfig.js @@ -46,7 +46,8 @@ class GlobalConfigImpl { this.endpointOverride = config.endpoint || this.endpointOverride; this.reconnect = config.reconnect === false ? false : this.reconnect; this.messageReceiptThrottleTime = config.throttleTime ? config.throttleTime : 5000; - const features = config.features || this.features.values; + // update features only if features is of type array. + const features = Array.isArray(config.features) ? config.features : this.features.values; this.features["values"] = Array.isArray(features) ? [...features] : new Array(); }