| ... |
... |
@@ -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):
|