Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 6fd1b99d by wurstsalat at 2022-08-14T20:35:02+02:00 new: Control: Store info messages per contact
- - - - -
3 changed files:
- gajim/gtk/control.py - gajim/gtk/conversation/rows/info.py - gajim/gtk/conversation/view.py
Changes:
===================================== gajim/gtk/control.py ===================================== @@ -19,6 +19,7 @@ from typing import Union from typing import cast
+from collections import defaultdict import os import logging import time @@ -61,6 +62,8 @@
log = logging.getLogger('gajim.gui.control')
+INFO_MESSAGES_COUNT = 100 +
class ChatControl(EventHelper): def __init__(self) -> None: @@ -101,6 +104,9 @@ def __init__(self) -> None:
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 @@ def switch_contact(self, contact: Union[BareContact, 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 @@ def get_our_nick(self) -> str: 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)
===================================== 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 @@
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)
===================================== gajim/gtk/conversation/view.py ===================================== @@ -193,8 +193,12 @@ def add_user_status(self, name: str, show: str, status: str) -> None: 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:
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/6fd1b99da4ca1731926aa92e6c219b7c3...