From 42b15497fce0889e6893d010db60f9c7eb929434 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 18 Jun 2021 10:07:30 +0200 Subject: [PATCH] New event `historyPruned` --- CHANGES.md | 1 + src/headless/shared/chat/utils.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b48551742..713e14924 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ - New hook: [getMessageActionButtons](https://conversejs.org/docs/html/api/-_converse.html#event:getMessageActionButtons) - New hook: [shouldNotifyOfGroupMessage](https://conversejs.org/docs/html/api/-_converse.html#event:shouldNotifyOfGroupMessage) - New hook: [presenceConstructed](https://conversejs.org/docs/html/api/-_converse.html#event:presenceConstructed) +- New event: [historyPruned](https://conversejs.org/docs/html/api/-_converse.html#event:historyPruned) - File structure reordering: All plugins are now in `./plugins` folders. - New configuration setting: [show_tab_notifications](https://conversejs.org/docs/html/configuration.html#show-tab-notifications) - New configuration setting: [muc_clear_messages_on_leave](https://conversejs.org/docs/html/configuration.html#muc-clear-messages-on-leave) diff --git a/src/headless/shared/chat/utils.js b/src/headless/shared/chat/utils.js index f9dfe9837..ab95f1ed3 100644 --- a/src/headless/shared/chat/utils.js +++ b/src/headless/shared/chat/utils.js @@ -11,6 +11,15 @@ export function pruneHistory (model) { if (non_empty_messages.length > max_history) { while (non_empty_messages.length > max_history) { non_empty_messages.shift().destroy(); + /** + * Triggered once the message history has been pruned, i.e. + * once older messages have been removed to keep the + * number of messages below the value set in `prune_messages_above`. + * @event _converse#historyPruned + * @type { _converse.ChatBox | _converse.ChatRoom } + * @example _converse.api.listen.on('historyPruned', this => { ... }); + */ + api.trigger('historyPruned', model); } } }