From 2417b115d2ebe1a12949a14c045bbb4f71d5e53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 10 Sep 2019 23:49:59 +0200 Subject: mam: Only fetched mam when the buffer is running low in messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/mam.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'poezio') 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 -- cgit v1.2.3