diff options
author | mathieui <mathieui@mathieui.net> | 2020-05-22 01:35:07 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2020-05-23 16:10:13 +0200 |
commit | 54339ee7e070dd51229d7ad939d8d24963438694 (patch) | |
tree | f93aca11a927907df940204cb37d104aa722317e | |
parent | fbec652efd4f0667f350de823b71d8ae91d98cae (diff) | |
download | poezio-54339ee7e070dd51229d7ad939d8d24963438694.tar.gz poezio-54339ee7e070dd51229d7ad939d8d24963438694.tar.bz2 poezio-54339ee7e070dd51229d7ad939d8d24963438694.tar.xz poezio-54339ee7e070dd51229d7ad939d8d24963438694.zip |
Textbuffer: add "find last message" function
-rw-r--r-- | poezio/tabs/muctab.py | 2 | ||||
-rw-r--r-- | poezio/text_buffer.py | 7 |
2 files changed, 8 insertions, 1 deletions
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) |