From 54339ee7e070dd51229d7ad939d8d24963438694 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 22 May 2020 01:35:07 +0200 Subject: Textbuffer: add "find last message" function --- poezio/tabs/muctab.py | 2 +- poezio/text_buffer.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index f5d1c700..7b0f8a42 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -161,7 +161,7 @@ class MucTab(ChatTab): delta = datetime.now() - self.last_connection seconds = delta.seconds + delta.days * 24 * 3600 else: - seconds = None + seconds = self._text_buffer.find_last_message() muc.join_groupchat( self.core, self.jid.bare, diff --git a/poezio/text_buffer.py b/poezio/text_buffer.py index 121a797a..03ad2f1b 100644 --- a/poezio/text_buffer.py +++ b/poezio/text_buffer.py @@ -277,6 +277,13 @@ class TextBuffer: def del_window(self, win) -> None: self._windows.remove(win) + def find_last_message(self) -> Optional[Message]: + """Find the last real message received in this buffer""" + for message in reversed(self.messages): + if isinstance(message, Message): + return message + return None + def __del__(self): size = len(self.messages) log.debug('** Deleting %s messages from textbuffer', size) -- cgit v1.2.3