diff options
author | Maxime “pep” Buquet <pep@bouah.net> | 2019-09-10 23:49:59 +0200 |
---|---|---|
committer | Maxime “pep” Buquet <pep@bouah.net> | 2019-09-10 23:49:59 +0200 |
commit | 2417b115d2ebe1a12949a14c045bbb4f71d5e53b (patch) | |
tree | ed6457e01ff4f78245787d59e9a343c30dc3aa90 | |
parent | 4137d8161ad8a32344d914c9106060ab0463f1f1 (diff) | |
download | poezio-2417b115d2ebe1a12949a14c045bbb4f71d5e53b.tar.gz poezio-2417b115d2ebe1a12949a14c045bbb4f71d5e53b.tar.bz2 poezio-2417b115d2ebe1a12949a14c045bbb4f71d5e53b.tar.xz poezio-2417b115d2ebe1a12949a14c045bbb4f71d5e53b.zip |
mam: Only fetched mam when the buffer is running low in messages
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r-- | poezio/mam.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/poezio/mam.py b/poezio/mam.py index bff0d4f9..cb5b9080 100644 --- a/poezio/mam.py +++ b/poezio/mam.py @@ -196,9 +196,22 @@ async def on_tab_open(tab) -> None: async def on_scroll_up(tab) -> None: - amount = tab.text_win.height + tw = tab.text_win + + # If position in the tab is <= two pages, then fetch MAM, so that we keep + # some prefetched margin. A first page should also be prefetched on join + # if not already available. + total, pos, height = len(tw.built_lines), tw.pos, tw.height + rest = (total - pos) // height + + if rest > 1: + return None + try: - await fetch_history(tab, amount=amount) + # XXX: Do we want to fetch a possibly variable number of messages? + # (InfoTab changes height depending on the type of messages, see + # `information_buffer_popup_on`). + await fetch_history(tab, amount=height) except NoMAMSupportException: tab.core.information('MAM not supported for %r' % tab.jid, 'Info') return None |