Commit 54339ee7 authored by mathieui's avatar mathieui

Textbuffer: add "find last message" function

parent fbec652e
...@@ -161,7 +161,7 @@ class MucTab(ChatTab): ...@@ -161,7 +161,7 @@ class MucTab(ChatTab):
delta = datetime.now() - self.last_connection delta = datetime.now() - self.last_connection
seconds = delta.seconds + delta.days * 24 * 3600 seconds = delta.seconds + delta.days * 24 * 3600
else: else:
seconds = None seconds = self._text_buffer.find_last_message()
muc.join_groupchat( muc.join_groupchat(
self.core, self.core,
self.jid.bare, self.jid.bare,
......
...@@ -277,6 +277,13 @@ class TextBuffer: ...@@ -277,6 +277,13 @@ class TextBuffer:
def del_window(self, win) -> None: def del_window(self, win) -> None:
self._windows.remove(win) 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): def __del__(self):
size = len(self.messages) size = len(self.messages)
log.debug('** Deleting %s messages from textbuffer', size) log.debug('** Deleting %s messages from textbuffer', size)
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