Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
c94a69b6 by wurstsalat at 2022-09-11T21:51:05+02:00
cfix: Control: Correctly show MUC subject when switching
- - - - -
3 changed files:
- gajim/common/modules/muc.py
- gajim/common/structs.py
- gajim/gtk/control.py
Changes:
=====================================
gajim/common/modules/muc.py
=====================================
@@ -817,6 +817,7 @@ def _on_subject_change(self,
_stanza: Message,
properties: MessageProperties
) -> None:
+
if not properties.is_muc_subject:
return
@@ -827,13 +828,26 @@ def _on_subject_change(self,
self._log.warning('No MUCData found for %s', room_jid)
return
- muc_subject = properties.muc_subject
- if muc_subject is not None and muc_subject.timestamp is None:
- muc_subject = muc_subject._replace(timestamp=time.time())
+ room = self._get_contact(JID.from_string(room_jid))
+ assert isinstance(room, GroupchatContact)
+ old_subject = muc_data.subject
+
+ muc_subject = properties.muc_subject
muc_data.subject = muc_subject
- room = self._get_contact(room_jid)
- room.notify('room-subject', muc_subject)
+
+ if muc_subject is not None:
+ if muc_subject.timestamp is None:
+ muc_subject = muc_subject._replace(timestamp=time.time())
+
+ if old_subject is None:
+ muc_data.last_subject_timestamp = time.time()
+ room.notify('room-subject', muc_subject)
+ else:
+ # Check if we already showed that subject (rejoin)
+ if old_subject.text != muc_subject.text:
+ muc_data.last_subject_timestamp = time.time()
+ room.notify('room-subject', muc_subject)
if muc_data.state == MUCJoinedState.JOINING:
self._room_join_complete(muc_data)
=====================================
gajim/common/structs.py
=====================================
@@ -73,6 +73,7 @@ def __init__(self,
self.error: Optional[str] = None
self.error_text: Optional[str] = None
self.subject: Optional[MucSubject] = None
+ self.last_subject_timestamp: Optional[float] = None
@property
def jid(self) -> JID:
=====================================
gajim/gtk/control.py
=====================================
@@ -92,9 +92,6 @@ def __init__(self) -> None:
# Used with encryption plugins
self.sendmessage = False
- self._muc_subjects: dict[
- types.ChatContactT, tuple[float, MucSubject]] = {}
-
self.widget = cast(Gtk.Box, self._ui.get_object('control_box'))
self.widget.show_all()
@@ -195,12 +192,15 @@ def switch_contact(self, contact: Union[BareContact,
self.add_file_transfer(transfer)
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)
+ if (not app.settings.get('show_subject_on_join') or
+ contact.is_joining):
+ return
+
+ muc_data = self._client.get_module('MUC').get_muc_data(
+ str(contact.jid))
+ if muc_data is not None and muc_data.subject is not None:
+ self.conversation_view.add_muc_subject(
+ muc_data.subject, muc_data.last_subject_timestamp)
def _register_events(self) -> None:
if self.has_events_registered():
@@ -1153,19 +1153,9 @@ def add_muc_message(self,
def _on_room_subject(self,
contact: GroupchatContact,
_signal_name: str,
- subject: Optional[MucSubject]
+ subject: MucSubject
) -> None:
- if subject is None:
- return
-
- _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._muc_subjects[contact] = (time.time(), subject)
-
if (app.settings.get('show_subject_on_join') or
not contact.is_joining):
self.conversation_view.add_muc_subject(subject)
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/c94a69b6014505f31235834d64750374d9f9c369
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/c94a69b6014505f31235834d64750374d9f9c369
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