diff options
author | wurstsalat <mailtrash@posteo.de> | 2022-08-14 21:35:02 +0300 |
---|---|---|
committer | wurstsalat <mailtrash@posteo.de> | 2022-08-14 21:35:02 +0300 |
commit | 6fd1b99da4ca1731926aa92e6c219b7c30dc81f9 (patch) | |
tree | 56a4da88a84126fcd3954a7262fc99da052fd2c6 | |
parent | ef3683f3aa11738e6d0489ea28db08a7e34db5d3 (diff) |
new: Control: Store info messages per contact
-rw-r--r-- | gajim/gtk/control.py | 24 | ||||
-rw-r--r-- | gajim/gtk/conversation/rows/info.py | 17 | ||||
-rw-r--r-- | gajim/gtk/conversation/view.py | 8 |
3 files changed, 41 insertions, 8 deletions
diff --git a/gajim/gtk/control.py b/gajim/gtk/control.py index c51344e95..b56de245e 100644 --- a/gajim/gtk/control.py +++ b/gajim/gtk/control.py @@ -19,6 +19,7 @@ from typing import Optional from typing import Union from typing import cast +from collections import defaultdict import os import logging import time @@ -61,6 +62,8 @@ from gajim.gui.groupchat_state import GroupchatState log = logging.getLogger('gajim.gui.control') +INFO_MESSAGES_COUNT = 100 + class ChatControl(EventHelper): def __init__(self) -> None: @@ -101,6 +104,9 @@ class ChatControl(EventHelper): self._subject_text_cache: dict[JID, str] = {} + self._info_messages: dict[ + types.ChatContactT, list[tuple[float, str]]] = defaultdict(list) + self.widget = cast(Gtk.Box, self._ui.get_object('control_box')) self.widget.show_all() @@ -202,6 +208,9 @@ class ChatControl(EventHelper): for transfer in transfers: self.add_file_transfer(transfer) + for timestamp, message in self._info_messages[contact]: + self.add_info_message(message, timestamp) + def _register_events(self) -> None: if self.has_events_registered(): return @@ -485,8 +494,19 @@ class ChatControl(EventHelper): def _allow_add_message(self) -> bool: return self._scrolled_view.get_lower_complete() - def add_info_message(self, text: str) -> None: - self.conversation_view.add_info_message(text) + def add_info_message(self, + text: str, + timestamp: Optional[float] = None + ) -> None: + + if timestamp is None: + assert self._contact is not None + self._info_messages[self._contact].append((time.time(), text)) + info_messages = self._info_messages[self._contact] + if len(info_messages) > INFO_MESSAGES_COUNT: + info_messages.pop(0) + + self.conversation_view.add_info_message(text, timestamp) def add_file_transfer(self, transfer: HTTPFileTransfer) -> None: self.conversation_view.add_file_transfer(transfer) diff --git a/gajim/gtk/conversation/rows/info.py b/gajim/gtk/conversation/rows/info.py index ebd49820f..308a36102 100644 --- a/gajim/gtk/conversation/rows/info.py +++ b/gajim/gtk/conversation/rows/info.py @@ -12,6 +12,10 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see <http://www.gnu.org/licenses/>. +from __future__ import annotations + +from typing import Optional + import time from datetime import datetime @@ -25,13 +29,18 @@ from .base import BaseRow class InfoMessage(BaseRow): - def __init__(self, account: str, text: str) -> None: + def __init__(self, + account: str, + text: str, + timestamp: Optional[float] + ) -> None: + BaseRow.__init__(self, account) self.type = 'info' - timestamp = time.time() - self.timestamp = datetime.fromtimestamp(timestamp) - self.db_timestamp = timestamp + current_timestamp = timestamp or time.time() + self.timestamp = datetime.fromtimestamp(current_timestamp) + self.db_timestamp = current_timestamp text = GLib.markup_escape_text(text) diff --git a/gajim/gtk/conversation/view.py b/gajim/gtk/conversation/view.py index d5985ba6c..9c9d66894 100644 --- a/gajim/gtk/conversation/view.py +++ b/gajim/gtk/conversation/view.py @@ -193,8 +193,12 @@ class ConversationView(Gtk.ListBox): user_status = UserStatus(self.contact.account, name, show, status) self._insert_message(user_status) - def add_info_message(self, text: str) -> None: - message = InfoMessage(self.contact.account, text) + def add_info_message(self, + text: str, + timestamp: Optional[float] = None + ) -> None: + + message = InfoMessage(self.contact.account, text, timestamp) self._insert_message(message) def add_file_transfer(self, transfer: HTTPFileTransfer) -> None: |