diff --git a/src/plugins/sib-mam-history.js b/src/plugins/sib-history-improved.js similarity index 57% rename from src/plugins/sib-mam-history.js rename to src/plugins/sib-history-improved.js index f0704e759212129dce7970a2196b940b0443e8d6..34eed4f40d7948a6d947921dc5bb8c9bc19fb55e 100644 --- a/src/plugins/sib-mam-history.js +++ b/src/plugins/sib-history-improved.js @@ -1,15 +1,46 @@ /** - * Forces the loading of the real number of messages (or more) - * from the setting `archived_messages_page_size`. + * Updates the history behavior of chat boxes. */ -converse.plugins.add('sib-mam-history', { +converse.plugins.add('sib-history-improved', { dependencies: [ 'converse-mam', ], + overrides: { + ChatRoomView: { + events: { + 'wheel .chat-content__messages': 'onScrolledUp', + }, + }, + ChatBoxView: { + events: { + 'wheel .chat-content__messages': 'onScrolledUp', + }, + + /** + * Fetch the old messages if there is no scroll available. + * @param {WheelEvent} ev + */ + onScrolledUp(ev) { + const { api } = this.__super__._converse; + const { utils } = converse.env; + const scrollable = this.msgs_container.clientHeight < this.msgs_container.scrollHeight; + + if (ev.deltaY < 0 && !scrollable) { + api.trigger('chatBoxScrolledUp', this); + utils.safeSave(this.model, { + scrolled: true, + scrollTop: 0, + }); + } + }, + }, + }, initialize() { const { api } = this._converse; let counter = 0; + // Forces the loading of the real number of messages (or more) + // from the setting `archived_messages_page_size`. api.listen.on('MAMResult', async data => { const max = +api.settings.get('archived_messages_page_size'); diff --git a/src/solid-xmpp-chat.js b/src/solid-xmpp-chat.js index 1a2733381b787c7fa0dbd86d0fc16043abc30816..b738cb02d9d498f3846e8f1fb0051d0980ab564a 100644 --- a/src/solid-xmpp-chat.js +++ b/src/solid-xmpp-chat.js @@ -9,7 +9,7 @@ import './plugins/converse-rai.js'; import './plugins/sib-chat-navigation.js'; import './plugins/sib-custom-hats.js'; import './plugins/sib-disconnected.js'; -import './plugins/sib-mam-history.js'; +import './plugins/sib-history-improved.js'; import './plugins/sib-mention-mobile.js'; import './plugins/sib-remove-notifications.js'; import './plugins/sib-scroll-down-on-focus.js'; @@ -225,7 +225,7 @@ export const SolidXMPPChat = { 'sib-connected', 'sib-custom-hats', 'sib-disconnected', - 'sib-mam-history', + 'sib-history-improved', 'sib-mention-mobile', 'sib-remove-notifications', 'sib-scroll-down-on-focus',