Philipp Hörist pushed to branch unify-control at gajim / gajim
Commits: 69c22ce9 by lovetox at 2022-08-07T23:27:38+02:00 fix: Remove unused import - - - - - 257272d8 by lovetox at 2022-08-07T23:58:45+02:00 other: Contacts: Add dedicated methods for adding contacts - - - - - b875983e by lovetox at 2022-08-07T23:59:15+02:00 other: Add contacts when opening chats - - - - - b07384ca by lovetox at 2022-08-07T23:59:26+02:00 fix: Check for None - - - - - 4 changed files: - gajim/common/modules/contacts.py - gajim/gtk/chat_page.py - gajim/gtk/control.py - gajim/gtk/main.py Changes: ===================================== gajim/common/modules/contacts.py ===================================== @@ -21,6 +21,7 @@ from typing import overload import cairo +from gi.repository.GObject import Value from nbxmpp.const import Affiliation from nbxmpp.const import Chatstate from nbxmpp.const import Role @@ -122,6 +123,56 @@ def _on_client_state_changed(self, if state.is_disconnected: self._reset_presence() + def add_chat_contact(self, jid: Union[str, JID]) -> BareContact: + if isinstance(jid, str): + jid = JID.from_string(jid) + + contact = self._contacts.get(jid) + if contact is not None: + if not isinstance(contact, BareContact): + raise ValueError(f'Trying to add GroupchatContact {jid}, ' + f'but contact exists already as {contact}') + return contact + + contact = BareContact(self._log, jid, self._account) + + self._contacts[jid] = contact + return contact + + def add_group_chat_contact(self, jid: Union[str, JID]) -> GroupchatContact: + if isinstance(jid, str): + jid = JID.from_string(jid) + + contact = self._contacts.get(jid) + if contact is not None: + if not isinstance(contact, GroupchatContact): + raise ValueError(f'Trying to add GroupchatContact {jid}, ' + f'but contact exists already as {contact}') + return contact + + contact = GroupchatContact(self._log, jid, self._account) + + self._contacts[jid] = contact + return contact + + def add_private_contact(self, jid: Union[str, JID]) -> GroupchatParticipant: + if isinstance(jid, str): + jid = JID.from_string(jid) + + if jid.resource is None: + raise ValueError(f'Trying to add a bare JID as private {jid}') + + contact = self._contacts.get(jid.bare) + if not isinstance(contact, GroupchatContact): + raise ValueError(f'Trying to add GroupchatParticipant {jid}, ' + f'to BareContact {contact}') + + if contact is None: + group_chat_contact = self.add_group_chat_contact(jid.bare) + return group_chat_contact.add_resource(jid.resource) + + return contact.add_resource(jid.resource) + def add_contact(self, jid: Union[str, JID], groupchat: bool = False) -> Union[BareContact, @@ -597,6 +648,10 @@ def add_resource(self, resource: str) -> GroupchatParticipant: # codebase is type checked and it creates hard to track # problems if we create a GroupchatParticipant without resource + contact = self._resources.get(resource) + if contact is not None: + return contact + jid = self._jid.new_with(resource=resource) assert isinstance(self._log, LogAdapter) contact = GroupchatParticipant(self._log, jid, self._account) ===================================== gajim/gtk/chat_page.py ===================================== @@ -224,6 +224,18 @@ def add_chat_for_workspace(self, type_: str, pinned: bool = False, select: bool = False) -> None: + + client = app.get_client(account) + + if type_ == 'chat': + client.get_module('Contacts').add_chat_contact(jid) + + elif type_ == 'groupchat': + client.get_module('Contacts').add_group_chat_contact(jid) + + elif type_ == 'pm': + client.get_module('Contacts').add_group_private_contact(jid) + if self.chat_exists(account, jid): if select: self._chat_list_stack.select_chat(account, jid) ===================================== gajim/gtk/control.py ===================================== @@ -134,7 +134,9 @@ def has_active_chat(self) -> bool: return self.contact is not None def clear(self) -> None: - self.contact.disconnect_all_from_obj(self) + if self.contact is not None: + self.contact.disconnect_all_from_obj(self) + self.contact = None self._clinet = None self.account = None ===================================== gajim/gtk/main.py ===================================== @@ -16,7 +16,6 @@ from typing import Any from typing import cast -from typing import Generator from typing import Optional import logging View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/07c857c3be2c811b6ccb659b70a251a66787402e...b07384caf5f4d60e5fa0f183d8fc500982fa02e3 -- View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/07c857c3be2c811b6ccb659b70a251a66787402e...b07384caf5f4d60e5fa0f183d8fc500982fa02e3 You're receiving this email because of your account on dev.gajim.org.
_______________________________________________ Commits mailing list Commits@gajim.org https://lists.gajim.org/cgi-bin/listinfo/commits