Daniel Brötzmann pushed to branch master at gajim / gajim

Commits:

3 changed files:

Changes:

  • gajim/gtk/control.py
    ... ... @@ -19,6 +19,7 @@
    19 19
     from typing import Union
    
    20 20
     from typing import cast
    
    21 21
     
    
    22
    +from collections import defaultdict
    
    22 23
     import os
    
    23 24
     import logging
    
    24 25
     import time
    
    ... ... @@ -61,6 +62,8 @@
    61 62
     
    
    62 63
     log = logging.getLogger('gajim.gui.control')
    
    63 64
     
    
    65
    +INFO_MESSAGES_COUNT = 100
    
    66
    +
    
    64 67
     
    
    65 68
     class ChatControl(EventHelper):
    
    66 69
         def __init__(self) -> None:
    
    ... ... @@ -101,6 +104,9 @@ def __init__(self) -> None:
    101 104
     
    
    102 105
             self._subject_text_cache: dict[JID, str] = {}
    
    103 106
     
    
    107
    +        self._info_messages: dict[
    
    108
    +            types.ChatContactT, list[tuple[float, str]]] = defaultdict(list)
    
    109
    +
    
    104 110
             self.widget = cast(Gtk.Box, self._ui.get_object('control_box'))
    
    105 111
             self.widget.show_all()
    
    106 112
     
    
    ... ... @@ -202,6 +208,9 @@ def switch_contact(self, contact: Union[BareContact,
    202 208
                 for transfer in transfers:
    
    203 209
                     self.add_file_transfer(transfer)
    
    204 210
     
    
    211
    +        for timestamp, message in self._info_messages[contact]:
    
    212
    +            self.add_info_message(message, timestamp)
    
    213
    +
    
    205 214
         def _register_events(self) -> None:
    
    206 215
             if self.has_events_registered():
    
    207 216
                 return
    
    ... ... @@ -485,8 +494,19 @@ def get_our_nick(self) -> str:
    485 494
         def _allow_add_message(self) -> bool:
    
    486 495
             return self._scrolled_view.get_lower_complete()
    
    487 496
     
    
    488
    -    def add_info_message(self, text: str) -> None:
    
    489
    -        self.conversation_view.add_info_message(text)
    
    497
    +    def add_info_message(self,
    
    498
    +                         text: str,
    
    499
    +                         timestamp: Optional[float] = None
    
    500
    +                         ) -> None:
    
    501
    +
    
    502
    +        if timestamp is None:
    
    503
    +            assert self._contact is not None
    
    504
    +            self._info_messages[self._contact].append((time.time(), text))
    
    505
    +            info_messages = self._info_messages[self._contact]
    
    506
    +            if len(info_messages) > INFO_MESSAGES_COUNT:
    
    507
    +                info_messages.pop(0)
    
    508
    +
    
    509
    +        self.conversation_view.add_info_message(text, timestamp)
    
    490 510
     
    
    491 511
         def add_file_transfer(self, transfer: HTTPFileTransfer) -> None:
    
    492 512
             self.conversation_view.add_file_transfer(transfer)
    

  • gajim/gtk/conversation/rows/info.py
    ... ... @@ -12,6 +12,10 @@
    12 12
     # You should have received a copy of the GNU General Public License
    
    13 13
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    14 14
     
    
    15
    +from __future__ import annotations
    
    16
    +
    
    17
    +from typing import Optional
    
    18
    +
    
    15 19
     import time
    
    16 20
     from datetime import datetime
    
    17 21
     
    
    ... ... @@ -25,13 +29,18 @@
    25 29
     
    
    26 30
     
    
    27 31
     class InfoMessage(BaseRow):
    
    28
    -    def __init__(self, account: str, text: str) -> None:
    
    32
    +    def __init__(self,
    
    33
    +                 account: str,
    
    34
    +                 text: str,
    
    35
    +                 timestamp: Optional[float]
    
    36
    +                 ) -> None:
    
    37
    +
    
    29 38
             BaseRow.__init__(self, account)
    
    30 39
     
    
    31 40
             self.type = 'info'
    
    32
    -        timestamp = time.time()
    
    33
    -        self.timestamp = datetime.fromtimestamp(timestamp)
    
    34
    -        self.db_timestamp = timestamp
    
    41
    +        current_timestamp = timestamp or time.time()
    
    42
    +        self.timestamp = datetime.fromtimestamp(current_timestamp)
    
    43
    +        self.db_timestamp = current_timestamp
    
    35 44
     
    
    36 45
             text = GLib.markup_escape_text(text)
    
    37 46
     
    

  • gajim/gtk/conversation/view.py
    ... ... @@ -193,8 +193,12 @@ def add_user_status(self, name: str, show: str, status: str) -> None:
    193 193
             user_status = UserStatus(self.contact.account, name, show, status)
    
    194 194
             self._insert_message(user_status)
    
    195 195
     
    
    196
    -    def add_info_message(self, text: str) -> None:
    
    197
    -        message = InfoMessage(self.contact.account, text)
    
    196
    +    def add_info_message(self,
    
    197
    +                         text: str,
    
    198
    +                         timestamp: Optional[float] = None
    
    199
    +                         ) -> None:
    
    200
    +
    
    201
    +        message = InfoMessage(self.contact.account, text, timestamp)
    
    198 202
             self._insert_message(message)
    
    199 203
     
    
    200 204
         def add_file_transfer(self, transfer: HTTPFileTransfer) -> None: