Commit 36c85a5d authored by mathieui's avatar mathieui

Add an "end of archive" message type

parent d174e1fa
...@@ -26,7 +26,11 @@ from poezio import tabs ...@@ -26,7 +26,11 @@ from poezio import tabs
from poezio import xhtml, colors from poezio import xhtml, colors
from poezio.config import config from poezio.config import config
from poezio.text_buffer import TextBuffer, HistoryGap from poezio.text_buffer import TextBuffer, HistoryGap
from poezio.ui.types import BaseMessage, Message from poezio.ui.types import (
BaseMessage,
EndOfArchive,
Message,
)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -270,6 +274,13 @@ async def on_scroll_up(tab) -> None: ...@@ -270,6 +274,13 @@ async def on_scroll_up(tab) -> None:
# (InfoTab changes height depending on the type of messages, see # (InfoTab changes height depending on the type of messages, see
# `information_buffer_popup_on`). # `information_buffer_popup_on`).
messages = await fetch_history(tab, amount=height) messages = await fetch_history(tab, amount=height)
if tab._text_buffer.messages:
last_message = tab._text_buffer.messages[0]
else:
last_message = None
if not messages and not isinstance(last_message, EndOfArchive):
time = tab._text_buffer.messages[0].time
messages = [EndOfArchive('End of archive reached', time=time)]
tab._text_buffer.add_history_messages(messages) tab._text_buffer.add_history_messages(messages)
except NoMAMSupportException: except NoMAMSupportException:
tab.core.information('MAM not supported for %r' % tab.jid, 'Info') tab.core.information('MAM not supported for %r' % tab.jid, 'Info')
......
...@@ -12,6 +12,7 @@ from poezio.ui.consts import ( ...@@ -12,6 +12,7 @@ from poezio.ui.consts import (
) )
class BaseMessage: class BaseMessage:
__slots__ = ('txt', 'time', 'identifier') __slots__ = ('txt', 'time', 'identifier')
...@@ -27,6 +28,10 @@ class BaseMessage: ...@@ -27,6 +28,10 @@ class BaseMessage:
return SHORT_FORMAT_LENGTH + 1 return SHORT_FORMAT_LENGTH + 1
class EndOfArchive(BaseMessage):
"""Marker added to a buffer when we reach the end of a MAM archive"""
class InfoMessage(BaseMessage): class InfoMessage(BaseMessage):
def __init__(self, txt: str, identifier: str = '', time: Optional[datetime] = None): def __init__(self, txt: str, identifier: str = '', time: Optional[datetime] = None):
txt = ('\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT)) + txt txt = ('\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT)) + txt
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment