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

Commits:

3 changed files:

Changes:

  • gajim/common/modules/muc.py
    ... ... @@ -817,6 +817,7 @@ def _on_subject_change(self,
    817 817
                                _stanza: Message,
    
    818 818
                                properties: MessageProperties
    
    819 819
                                ) -> None:
    
    820
    +
    
    820 821
             if not properties.is_muc_subject:
    
    821 822
                 return
    
    822 823
     
    
    ... ... @@ -827,13 +828,26 @@ def _on_subject_change(self,
    827 828
                 self._log.warning('No MUCData found for %s', room_jid)
    
    828 829
                 return
    
    829 830
     
    
    830
    -        muc_subject = properties.muc_subject
    
    831
    -        if muc_subject is not None and muc_subject.timestamp is None:
    
    832
    -            muc_subject = muc_subject._replace(timestamp=time.time())
    
    831
    +        room = self._get_contact(JID.from_string(room_jid))
    
    832
    +        assert isinstance(room, GroupchatContact)
    
    833 833
     
    
    834
    +        old_subject = muc_data.subject
    
    835
    +
    
    836
    +        muc_subject = properties.muc_subject
    
    834 837
             muc_data.subject = muc_subject
    
    835
    -        room = self._get_contact(room_jid)
    
    836
    -        room.notify('room-subject', muc_subject)
    
    838
    +
    
    839
    +        if muc_subject is not None:
    
    840
    +            if muc_subject.timestamp is None:
    
    841
    +                muc_subject = muc_subject._replace(timestamp=time.time())
    
    842
    +
    
    843
    +            if old_subject is None:
    
    844
    +                muc_data.last_subject_timestamp = time.time()
    
    845
    +                room.notify('room-subject', muc_subject)
    
    846
    +            else:
    
    847
    +                # Check if we already showed that subject (rejoin)
    
    848
    +                if old_subject.text != muc_subject.text:
    
    849
    +                    muc_data.last_subject_timestamp = time.time()
    
    850
    +                    room.notify('room-subject', muc_subject)
    
    837 851
     
    
    838 852
             if muc_data.state == MUCJoinedState.JOINING:
    
    839 853
                 self._room_join_complete(muc_data)
    

  • gajim/common/structs.py
    ... ... @@ -73,6 +73,7 @@ def __init__(self,
    73 73
             self.error: Optional[str] = None
    
    74 74
             self.error_text: Optional[str] = None
    
    75 75
             self.subject: Optional[MucSubject] = None
    
    76
    +        self.last_subject_timestamp: Optional[float] = None
    
    76 77
     
    
    77 78
         @property
    
    78 79
         def jid(self) -> JID:
    

  • gajim/gtk/control.py
    ... ... @@ -92,9 +92,6 @@ def __init__(self) -> None:
    92 92
             # Used with encryption plugins
    
    93 93
             self.sendmessage = False
    
    94 94
     
    
    95
    -        self._muc_subjects: dict[
    
    96
    -            types.ChatContactT, tuple[float, MucSubject]] = {}
    
    97
    -
    
    98 95
             self.widget = cast(Gtk.Box, self._ui.get_object('control_box'))
    
    99 96
             self.widget.show_all()
    
    100 97
     
    
    ... ... @@ -195,12 +192,15 @@ def switch_contact(self, contact: Union[BareContact,
    195 192
                     self.add_file_transfer(transfer)
    
    196 193
     
    
    197 194
             if isinstance(contact, GroupchatContact):
    
    198
    -            if (app.settings.get('show_subject_on_join') or
    
    199
    -                    not contact.is_joining):
    
    200
    -                timestamp, subject = self._muc_subjects.get(
    
    201
    -                    contact, (None, None))
    
    202
    -                if subject is not None:
    
    203
    -                    self.conversation_view.add_muc_subject(subject, timestamp)
    
    195
    +            if (not app.settings.get('show_subject_on_join') or
    
    196
    +                    contact.is_joining):
    
    197
    +                return
    
    198
    +
    
    199
    +            muc_data = self._client.get_module('MUC').get_muc_data(
    
    200
    +                str(contact.jid))
    
    201
    +            if muc_data is not None and muc_data.subject is not None:
    
    202
    +                self.conversation_view.add_muc_subject(
    
    203
    +                    muc_data.subject, muc_data.last_subject_timestamp)
    
    204 204
     
    
    205 205
         def _register_events(self) -> None:
    
    206 206
             if self.has_events_registered():
    
    ... ... @@ -1153,19 +1153,9 @@ def add_muc_message(self,
    1153 1153
         def _on_room_subject(self,
    
    1154 1154
                              contact: GroupchatContact,
    
    1155 1155
                              _signal_name: str,
    
    1156
    -                         subject: Optional[MucSubject]
    
    1156
    +                         subject: MucSubject
    
    1157 1157
                              ) -> None:
    
    1158 1158
     
    
    1159
    -        if subject is None:
    
    1160
    -            return
    
    1161
    -
    
    1162
    -        _timestamp, old_subject = self._muc_subjects.get(contact, (None, None))
    
    1163
    -        if old_subject is not None and old_subject.text == subject.text:
    
    1164
    -            # Probably a rejoin, we already showed that subject
    
    1165
    -            return
    
    1166
    -
    
    1167
    -        self._muc_subjects[contact] = (time.time(), subject)
    
    1168
    -
    
    1169 1159
             if (app.settings.get('show_subject_on_join') or
    
    1170 1160
                     not contact.is_joining):
    
    1171 1161
                 self.conversation_view.add_muc_subject(subject)