From da1d87648c45d6b61eeec7d8454f5a0d71f4b42b Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 3 Jul 2019 11:55:42 +0200 Subject: [PATCH] New config option `clear_messages_on_reconnection` In some cases, it might be desirable to clear cached chat messages once you've reconnected to the XMPP server. For example, if you want to prevent the chat history from getting too long or if you want to avoid gaps in the chat history (for example due to MAM not returning all messages since the last cached message). If you're using OMEMO, then you probably don't want to set this setting to ``true``. OMEMO messages can be decrypted only once, so if they then subsequently get cleared, you won't get the plaintext back. --- CHANGES.md | 5 +++-- docs/source/configuration.rst | 18 ++++++++++++++++++ src/headless/converse-chatboxes.js | 5 ++++- src/headless/converse-muc.js | 4 +++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ea8596c43..b39ba5d9a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,14 +18,15 @@ - Continuously retry (in 2s intervals) to fetch login credentials (via [credentials_url](https://conversejs.org/docs/html/configuration.html#credentials-url)) in case of failure - Replace `moment` with [DayJS](https://github.com/iamkun/dayjs). - New config option [auto_focus](https://conversejs.org/docs/html/configuration.html#auto-focus) +- New config option [clear_messages_on_reconnection](https://conversejs.org/docs/html/configuration.html#clear-messages-on-reconnection) - New config option [enable_smacks](https://conversejs.org/docs/html/configuration.html#enable-smacks) -- New config option [muc_show_join_leave_status](https://conversejs.org/docs/html/configuration.html#muc-show-join-leave-status) - New config option [message_limit](https://conversejs.org/docs/html/configuration.html#message-limit) +- New config option [muc_mention_autocomplete_min_chars](https://conversejs.org/docs/html/configuration.html#muc-mention-autocomplete-min-chars) +- New config option [muc_show_join_leave_status](https://conversejs.org/docs/html/configuration.html#muc-show-join-leave-status) - New config option [singleton](https://conversejs.org/docs/html/configuration.html#singleton) By setting this option to `false` and `view_mode` to `'embedded'`, it's now possible to "embed" the full app and not just a single chat. To embed just a single chat, it's now necessary to explicitly set `singleton` to `true`. -- New config option [muc_mention_autocomplete_min_chars](https://conversejs.org/docs/html/configuration.html#muc-mention-autocomplete-min-chars) - New event: [chatBoxBlurred](https://conversejs.org/docs/html/api/-_converse.html#event:chatBoxBlurred) - New event: [chatReconnected](https://conversejs.org/docs/html/api/-_converse.html#event:chatReconnected) - #316: Add support for XEP-0198 Stream Management diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 5aa30bcf4..f49d688ff 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -468,6 +468,24 @@ For more information, read this blog post: `Which BOSH server do you need? `_. Please see the :ref:`websocket-url` configuration setting. + +clear_messages_on_reconnection +------------------------------ + +* Default: ``false`` + +In some cases, it might be desirable to clear cached chat messages once you've +reconnected to the XMPP server. + +For example, if you want to prevent the chat history from getting too long or +if you want to avoid gaps in the chat history (for example due to MAM not +returning all messages since the last cached message). + +Beware, if you're using OMEMO, then you probably don't want to set this setting to +``true``. OMEMO messages can be decrypted only once, so if they then +subsequently get cleared, you won't get the plaintext back. + + chatstate_notification_blacklist -------------------------------- diff --git a/src/headless/converse-chatboxes.js b/src/headless/converse-chatboxes.js index b1a77c48b..797fad55e 100644 --- a/src/headless/converse-chatboxes.js +++ b/src/headless/converse-chatboxes.js @@ -36,6 +36,7 @@ converse.plugins.add('converse-chatboxes', { // configuration settings. _converse.api.settings.update({ 'auto_join_private_chats': [], + 'clear_messages_on_reconnection': false, 'filter_by_resource': false, 'send_chat_state_notifications': true }); @@ -358,7 +359,9 @@ converse.plugins.add('converse-chatboxes', { }, onReconnection () { - this.clearMessages(); + if (_converse.clear_messages_on_reconnection) { + this.clearMessages(); + } this.announceReconnection(); }, diff --git a/src/headless/converse-muc.js b/src/headless/converse-muc.js index 9ee92b31f..9babd22ed 100644 --- a/src/headless/converse-muc.js +++ b/src/headless/converse-muc.js @@ -398,7 +398,9 @@ converse.plugins.add('converse-muc', { // the cache (which might be stale). this.removeNonMembers(); await this.refreshRoomFeatures(); - this.clearMessages(); // XXX: This should be conditional + if (_converse.clear_messages_on_reconnection) { + this.clearMessages(); + } if (!u.isPersistableModel(this)) { // XXX: Happens during tests, nothing to do if this // is a hanging chatbox (i.e. not in the collection anymore).