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

Commits:

2 changed files:

Changes:

  • gajim/gtk/chat_list_stack.py
    ... ... @@ -182,7 +182,7 @@ def add_chat(self, workspace_id: str, account: str, jid: JID, type_: str,
    182 182
             chat_list.add_chat(account, jid, type_, pinned)
    
    183 183
     
    
    184 184
         def select_chat(self, account: str, jid: JID) -> None:
    
    185
    -        chat_list = self._find_chat(account, jid)
    
    185
    +        chat_list = self.find_chat(account, jid)
    
    186 186
             if chat_list is None:
    
    187 187
                 return
    
    188 188
     
    
    ... ... @@ -241,7 +241,7 @@ def remove_chats_for_account(self, account: str) -> None:
    241 241
                 chat_list.remove_chats_for_account(account)
    
    242 242
                 self.store_open_chats(workspace_id)
    
    243 243
     
    
    244
    -    def _find_chat(self, account: str, jid: JID) -> Optional[ChatList]:
    
    244
    +    def find_chat(self, account: str, jid: JID) -> Optional[ChatList]:
    
    245 245
             for chat_list in self._chat_lists.values():
    
    246 246
                 if chat_list.contains_chat(account, jid):
    
    247 247
                     return chat_list
    
    ... ... @@ -292,7 +292,7 @@ def process_event(self, event: ApplicationEvent) -> None:
    292 292
             if event.name not in HANDLED_EVENTS:
    
    293 293
                 return
    
    294 294
     
    
    295
    -        chat_list = self._find_chat(event.account, event.jid)
    
    295
    +        chat_list = self.find_chat(event.account, event.jid)
    
    296 296
             if chat_list is None:
    
    297 297
                 return
    
    298 298
             chat_list.process_event(event)

  • gajim/gtk/main.py
    ... ... @@ -349,7 +349,7 @@ def show_account_page(self, account: str) -> None:
    349 349
             self._account_side_bar.activate_account_page(account)
    
    350 350
             self._main_stack.show_account(account)
    
    351 351
     
    
    352
    -    def get_active_workspace(self) -> Optional[Workspace]:
    
    352
    +    def get_active_workspace(self) -> Optional[str]:
    
    353 353
             return self._workspace_side_bar.get_active_workspace()
    
    354 354
     
    
    355 355
         def is_chat_active(self, account: str, jid: JID) -> bool:
    
    ... ... @@ -458,6 +458,8 @@ def add_chat(self,
    458 458
                      workspace: str = 'default') -> None:
    
    459 459
             if workspace == 'current':
    
    460 460
                 workspace_id = self.get_active_workspace()
    
    461
    +            if workspace_id is None:
    
    462
    +                workspace_id = self._workspace_side_bar.get_first_workspace()
    
    461 463
             else:
    
    462 464
                 workspace_id = self._workspace_side_bar.get_first_workspace()
    
    463 465
             self._chat_page.add_chat_for_workspace(workspace_id,
    
    ... ... @@ -466,11 +468,18 @@ def add_chat(self,
    466 468
                                                    type_,
    
    467 469
                                                    select=select)
    
    468 470
     
    
    469
    -    def add_private_chat(self, account: str, jid: JID,
    
    471
    +    def add_private_chat(self,
    
    472
    +                         account: str,
    
    473
    +                         jid: JID,
    
    470 474
                              select: bool = False) -> None:
    
    471
    -        workspace_id = self.get_active_workspace()
    
    472
    -        if workspace_id is None:
    
    475
    +        # Try to add private chat to the same workspace the MUC resides in
    
    476
    +        chat_list_stack = self._chat_page.get_chat_list_stack()
    
    477
    +        chat_list = chat_list_stack.find_chat(account, jid.new_as_bare())
    
    478
    +        if chat_list is not None:
    
    479
    +            workspace_id = chat_list.workspace_id
    
    480
    +        else:
    
    473 481
                 workspace_id = self._workspace_side_bar.get_first_workspace()
    
    482
    +
    
    474 483
             self._chat_page.add_chat_for_workspace(workspace_id,
    
    475 484
                                                    account,
    
    476 485
                                                    jid,
    
    ... ... @@ -659,8 +668,7 @@ def _on_event(self, event):
    659 668
                         return
    
    660 669
                     if event.properties.is_muc_pm:
    
    661 670
                         self.add_private_chat(event.account,
    
    662
    -                                          event.properties.jid,
    
    663
    -                                          'pm')
    
    671
    +                                          event.properties.jid)
    
    664 672
                     else:
    
    665 673
                         jid = event.properties.jid.new_as_bare()
    
    666 674
                         self.add_chat(event.account, jid, 'contact')