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

Commits:

3 changed files:

Changes:

  • gajim/gtk/chat_page.py
    ... ... @@ -92,7 +92,7 @@ def __init__(self):
    92 92
             self._ui.paned.set_position(app.settings.get('chat_handle_position'))
    
    93 93
             self._ui.paned.connect('button-release-event', self._on_button_release)
    
    94 94
     
    
    95
    -        self._currently_loaded_control: Optional[ControlType] = None
    
    95
    +        self._last_control: Optional[ControlType] = None
    
    96 96
             self._startup_finished: bool = False
    
    97 97
     
    
    98 98
             self._add_actions()
    
    ... ... @@ -168,7 +168,7 @@ def unload_idle_chats(self) -> bool:
    168 168
             return True
    
    169 169
     
    
    170 170
         def _on_chat_selected(self,
    
    171
    -                          chat_list_stack: ChatListStack,
    
    171
    +                          _chat_list_stack: ChatListStack,
    
    172 172
                               workspace_id: str,
    
    173 173
                               account: str,
    
    174 174
                               jid: JID) -> None:
    
    ... ... @@ -181,11 +181,12 @@ def _on_chat_selected(self,
    181 181
             control = self.get_control(account, jid)
    
    182 182
             if control is None:
    
    183 183
                 return
    
    184
    -        if self._currently_loaded_control != control:
    
    185
    -            if self._currently_loaded_control is not None:
    
    186
    -                self._currently_loaded_control.set_control_active(False)
    
    184
    +
    
    185
    +        if control != self._last_control:
    
    186
    +            if self._last_control is not None:
    
    187
    +                self._last_control.set_control_active(False)
    
    187 188
                 control.set_control_active(True)
    
    188
    -        self._currently_loaded_control = control
    
    189
    +        self._last_control = control
    
    189 190
     
    
    190 191
         def _on_chat_unselected(self, _chat_list_stack):
    
    191 192
             self._chat_stack.clear()
    
    ... ... @@ -302,7 +303,7 @@ def remove_chat(self, account: str, jid: JID) -> None:
    302 303
         def _on_chat_removed(self, _chat_list: ChatList, account: str, jid: JID,
    
    303 304
                              type_: str) -> None:
    
    304 305
             self._chat_stack.remove_chat(account, jid)
    
    305
    -        self._currently_loaded_control = None
    
    306
    +        self._last_control = None
    
    306 307
             if type_ == 'groupchat':
    
    307 308
                 client = app.get_client(account)
    
    308 309
                 client.get_module('MUC').leave(jid)
    
    ... ... @@ -324,8 +325,9 @@ def get_active_control(self) -> Optional[ControlType]:
    324 325
                 return None
    
    325 326
             return self.get_control(chat.account, chat.jid)
    
    326 327
     
    
    327
    -    def get_currently_loaded_control(self) -> Optional[ControlType]:
    
    328
    -        return self._currently_loaded_control
    
    328
    +    def is_chat_idle(self, account: str, jid: JID) -> bool:
    
    329
    +        entry = self._chat_idle_time.get((account, jid))
    
    330
    +        return entry is not None
    
    329 331
     
    
    330 332
         def get_controls(self, account: Optional[str]
    
    331 333
                          ) -> Generator[ControlType, None, None]:
    

  • gajim/gtk/controls/base.py
    ... ... @@ -1123,6 +1123,12 @@ def save_message(self, message: str, msg_type: str) -> None:
    1123 1123
             else:
    
    1124 1124
                 self.received_history_pos = pos
    
    1125 1125
     
    
    1126
    +    def _allow_add_message(self) -> bool:
    
    1127
    +        lower_complete = self._scrolled_view.get_lower_complete()
    
    1128
    +        chat_idle = app.window.is_chat_idle(self.account, self.contact.jid)
    
    1129
    +        chat_selected = bool(app.window.get_active_control() is not None)
    
    1130
    +        return lower_complete and chat_idle or chat_selected
    
    1131
    +
    
    1126 1132
         def add_info_message(self, text: str) -> None:
    
    1127 1133
             self.conversation_view.add_info_message(text)
    
    1128 1134
     
    
    ... ... @@ -1130,15 +1136,11 @@ def add_file_transfer(self, transfer: HTTPFileTransfer) -> None:
    1130 1136
             self.conversation_view.add_file_transfer(transfer)
    
    1131 1137
     
    
    1132 1138
         def add_jingle_file_transfer(self, event):
    
    1133
    -        control_selected = bool(
    
    1134
    -            self == app.window.get_currently_loaded_control())
    
    1135
    -        if self._scrolled_view.get_lower_complete() and control_selected:
    
    1139
    +        if self._allow_add_message():
    
    1136 1140
                 self.conversation_view.add_jingle_file_transfer(event)
    
    1137 1141
     
    
    1138 1142
         def add_call_message(self, event):
    
    1139
    -        control_selected = bool(
    
    1140
    -            self == app.window.get_currently_loaded_control())
    
    1141
    -        if self._scrolled_view.get_lower_complete() and control_selected:
    
    1143
    +        if self._allow_add_message():
    
    1142 1144
                 self.conversation_view.add_call_message(event=event)
    
    1143 1145
     
    
    1144 1146
         def add_message(self,
    
    ... ... @@ -1157,9 +1159,7 @@ def add_message(self,
    1157 1159
             if additional_data is None:
    
    1158 1160
                 additional_data = AdditionalDataDict()
    
    1159 1161
     
    
    1160
    -        control_selected = bool(
    
    1161
    -            self == app.window.get_currently_loaded_control())
    
    1162
    -        if self._scrolled_view.get_lower_complete() and control_selected:
    
    1162
    +        if self._allow_add_message():
    
    1163 1163
                 self.conversation_view.add_message(
    
    1164 1164
                     text,
    
    1165 1165
                     kind,
    

  • gajim/gtk/main.py
    ... ... @@ -506,8 +506,8 @@ def get_controls(self, account: Optional[str] = None
    506 506
         def get_active_control(self) -> Optional[ControlType]:
    
    507 507
             return self._chat_page.get_active_control()
    
    508 508
     
    
    509
    -    def get_currently_loaded_control(self) -> Optional[ControlType]:
    
    510
    -        return self._chat_page.get_currently_loaded_control()
    
    509
    +    def is_chat_idle(self, account: str, jid: JID) -> bool:
    
    510
    +        return self._chat_page.is_chat_idle(account, jid)
    
    511 511
     
    
    512 512
         def chat_exists(self, account: str, jid: JID) -> bool:
    
    513 513
             return self._chat_page.chat_exists(account, jid)