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

Commits:

3 changed files:

Changes:

  • gajim/gtk/control.py
    ... ... @@ -20,6 +20,8 @@
    20 20
     from typing import cast
    
    21 21
     
    
    22 22
     from collections import defaultdict
    
    23
    +from collections import deque
    
    24
    +from functools import partial
    
    23 25
     import os
    
    24 26
     import logging
    
    25 27
     import time
    
    ... ... @@ -62,8 +64,6 @@
    62 64
     
    
    63 65
     log = logging.getLogger('gajim.gui.control')
    
    64 66
     
    
    65
    -INFO_MESSAGES_COUNT = 100
    
    66
    -
    
    67 67
     
    
    68 68
     class ChatControl(EventHelper):
    
    69 69
         def __init__(self) -> None:
    
    ... ... @@ -102,10 +102,14 @@ def __init__(self) -> None:
    102 102
             # XEP-0333 Chat Markers
    
    103 103
             self.last_msg_id: Optional[str] = None
    
    104 104
     
    
    105
    -        self._subject_text_cache: dict[JID, str] = {}
    
    105
    +        self._muc_subjects: dict[
    
    106
    +            types.ChatContactT, tuple[float, MucSubject]] = {}
    
    106 107
     
    
    108
    +        # Store 100 info messages per contact on a FIFO basis
    
    107 109
             self._info_messages: dict[
    
    108
    -            types.ChatContactT, list[tuple[float, str]]] = defaultdict(list)
    
    110
    +            types.ChatContactT,
    
    111
    +            deque[tuple[float, str]]] = defaultdict(
    
    112
    +                partial(deque, maxlen=100))  # pyright: ignore
    
    109 113
     
    
    110 114
             self.widget = cast(Gtk.Box, self._ui.get_object('control_box'))
    
    111 115
             self.widget.show_all()
    
    ... ... @@ -211,6 +215,14 @@ def switch_contact(self, contact: Union[BareContact,
    211 215
             for timestamp, message in self._info_messages[contact]:
    
    212 216
                 self.add_info_message(message, timestamp)
    
    213 217
     
    
    218
    +        if isinstance(contact, GroupchatContact):
    
    219
    +            if (app.settings.get('show_subject_on_join') or
    
    220
    +                    not contact.is_joining):
    
    221
    +                timestamp, subject = self._muc_subjects.get(
    
    222
    +                    contact, (None, None))
    
    223
    +                if subject is not None:
    
    224
    +                    self.conversation_view.add_muc_subject(subject, timestamp)
    
    225
    +
    
    214 226
         def _register_events(self) -> None:
    
    215 227
             if self.has_events_registered():
    
    216 228
                 return
    
    ... ... @@ -502,9 +514,6 @@ def add_info_message(self,
    502 514
             if timestamp is None:
    
    503 515
                 assert self._contact is not None
    
    504 516
                 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 517
     
    
    509 518
             self.conversation_view.add_info_message(text, timestamp)
    
    510 519
     
    
    ... ... @@ -834,11 +843,12 @@ def _on_room_subject(self,
    834 843
             if subject is None:
    
    835 844
                 return
    
    836 845
     
    
    837
    -        if self._subject_text_cache.get(contact.jid) == subject.text:
    
    846
    +        _timestamp, old_subject = self._muc_subjects.get(contact, (None, None))
    
    847
    +        if old_subject is not None and old_subject.text == subject.text:
    
    838 848
                 # Probably a rejoin, we already showed that subject
    
    839 849
                 return
    
    840 850
     
    
    841
    -        self._subject_text_cache[contact.jid] = subject.text
    
    851
    +        self._muc_subjects[contact] = (time.time(), subject)
    
    842 852
     
    
    843 853
             if (app.settings.get('show_subject_on_join') or
    
    844 854
                     not contact.is_joining):
    

  • gajim/gtk/conversation/rows/muc_subject.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
     
    
    ... ... @@ -29,12 +33,17 @@ class MUCSubject(BaseRow):
    29 33
     
    
    30 34
         type = 'muc-subject'
    
    31 35
     
    
    32
    -    def __init__(self, account: str, subject: MucSubject) -> None:
    
    36
    +    def __init__(self,
    
    37
    +                 account: str,
    
    38
    +                 subject: MucSubject,
    
    39
    +                 timestamp: Optional[float] = None
    
    40
    +                 ) -> None:
    
    41
    +
    
    33 42
             BaseRow.__init__(self, account)
    
    34 43
     
    
    35
    -        timestamp = time.time()
    
    36
    -        self.timestamp = datetime.fromtimestamp(timestamp)
    
    37
    -        self.db_timestamp = timestamp
    
    44
    +        current_timestamp = timestamp or time.time()
    
    45
    +        self.timestamp = datetime.fromtimestamp(current_timestamp)
    
    46
    +        self.db_timestamp = current_timestamp
    
    38 47
     
    
    39 48
             self.grid.set_halign(Gtk.Align.START)
    
    40 49
     
    

  • gajim/gtk/conversation/view.py
    ... ... @@ -162,8 +162,12 @@ def _sort_func(row1: BaseRow, row2: BaseRow) -> int:
    162 162
                 return 0
    
    163 163
             return -1 if row1.timestamp < row2.timestamp else 1
    
    164 164
     
    
    165
    -    def add_muc_subject(self, subject: MucSubject) -> None:
    
    166
    -        muc_subject = MUCSubject(self.contact.account, subject)
    
    165
    +    def add_muc_subject(self,
    
    166
    +                        subject: MucSubject,
    
    167
    +                        timestamp: Optional[float] = None
    
    168
    +                        ) -> None:
    
    169
    +
    
    170
    +        muc_subject = MUCSubject(self.contact.account, subject, timestamp)
    
    167 171
             self._insert_message(muc_subject)
    
    168 172
     
    
    169 173
         def add_muc_user_left(self,