Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
f21ec271 by wurstsalat at 2022-08-14T22:57:47+02:00
cfix: Control: Use deque for storing info messages
- - - - -
b6e481ce by wurstsalat at 2022-08-14T23:18:22+02:00
new: Control: Store muc subject per contact
- - - - -
3 changed files:
- gajim/gtk/control.py
- gajim/gtk/conversation/rows/muc_subject.py
- gajim/gtk/conversation/view.py
Changes:
=====================================
gajim/gtk/control.py
=====================================
@@ -20,6 +20,8 @@
from typing import cast
from collections import defaultdict
+from collections import deque
+from functools import partial
import os
import logging
import time
@@ -62,8 +64,6 @@
log = logging.getLogger('gajim.gui.control')
-INFO_MESSAGES_COUNT = 100
-
class ChatControl(EventHelper):
def __init__(self) -> None:
@@ -102,10 +102,14 @@ def __init__(self) -> None:
# XEP-0333 Chat Markers
self.last_msg_id: Optional[str] = None
- self._subject_text_cache: dict[JID, str] = {}
+ self._muc_subjects: dict[
+ types.ChatContactT, tuple[float, MucSubject]] = {}
+ # Store 100 info messages per contact on a FIFO basis
self._info_messages: dict[
- types.ChatContactT, list[tuple[float, str]]] = defaultdict(list)
+ types.ChatContactT,
+ deque[tuple[float, str]]] = defaultdict(
+ partial(deque, maxlen=100)) # pyright: ignore
self.widget = cast(Gtk.Box, self._ui.get_object('control_box'))
self.widget.show_all()
@@ -211,6 +215,14 @@ def switch_contact(self, contact: Union[BareContact,
for timestamp, message in self._info_messages[contact]:
self.add_info_message(message, timestamp)
+ if isinstance(contact, GroupchatContact):
+ if (app.settings.get('show_subject_on_join') or
+ not contact.is_joining):
+ timestamp, subject = self._muc_subjects.get(
+ contact, (None, None))
+ if subject is not None:
+ self.conversation_view.add_muc_subject(subject, timestamp)
+
def _register_events(self) -> None:
if self.has_events_registered():
return
@@ -502,9 +514,6 @@ def add_info_message(self,
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)
@@ -834,11 +843,12 @@ def _on_room_subject(self,
if subject is None:
return
- if self._subject_text_cache.get(contact.jid) == subject.text:
+ _timestamp, old_subject = self._muc_subjects.get(contact, (None, None))
+ if old_subject is not None and old_subject.text == subject.text:
# Probably a rejoin, we already showed that subject
return
- self._subject_text_cache[contact.jid] = subject.text
+ self._muc_subjects[contact] = (time.time(), subject)
if (app.settings.get('show_subject_on_join') or
not contact.is_joining):
=====================================
gajim/gtk/conversation/rows/muc_subject.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
@@ -29,12 +33,17 @@ class MUCSubject(BaseRow):
type = 'muc-subject'
- def __init__(self, account: str, subject: MucSubject) -> None:
+ def __init__(self,
+ account: str,
+ subject: MucSubject,
+ timestamp: Optional[float] = None
+ ) -> None:
+
BaseRow.__init__(self, account)
- 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
self.grid.set_halign(Gtk.Align.START)
=====================================
gajim/gtk/conversation/view.py
=====================================
@@ -162,8 +162,12 @@ def _sort_func(row1: BaseRow, row2: BaseRow) -> int:
return 0
return -1 if row1.timestamp < row2.timestamp else 1
- def add_muc_subject(self, subject: MucSubject) -> None:
- muc_subject = MUCSubject(self.contact.account, subject)
+ def add_muc_subject(self,
+ subject: MucSubject,
+ timestamp: Optional[float] = None
+ ) -> None:
+
+ muc_subject = MUCSubject(self.contact.account, subject, timestamp)
self._insert_message(muc_subject)
def add_muc_user_left(self,
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/6fd1b99da4ca1731926aa92e6c219b7c30dc81f9...b6e481ce71f9bf29510ce9cbbb85e101e24ce10e
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/6fd1b99da4ca1731926aa92e6c219b7c30dc81f9...b6e481ce71f9bf29510ce9cbbb85e101e24ce10e
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits