Philipp Hörist pushed to branch master at gajim / gajim
Commits: 39628b6d by Philipp Hörist at 2022-10-05T22:59:05+02:00 new: Client: Add is_destroyed() method
- - - - - adb5f1a2 by Philipp Hörist at 2022-10-05T22:59:05+02:00 refactor: MessageActionsBox: Check if client is already destroyed
- - - - - b613e763 by Philipp Hörist at 2022-10-05T22:59:05+02:00 refactor: ConversationView: Move special row creation into switch_contact()
- - - - - 30071a1f by Philipp Hörist at 2022-10-05T22:59:05+02:00 cfix: VCardAvatars: Set task obsolete if we are not connected
- - - - - 126829fa by Philipp Hörist at 2022-10-05T22:59:05+02:00 cfix: Accounts: Execute disable_account() as late as possible
- - - - - 7a98a1f2 by Philipp Hörist at 2022-10-05T22:59:05+02:00 cfix: RemoveAccount: Execute remove_account() as late as possible
- - - - - c71ca59b by Philipp Hörist at 2022-10-05T22:59:05+02:00 refactor: Client: Remove workaround when disabling account
We only call disable account when we are disconnected now.
- - - - -
6 changed files:
- gajim/common/client.py - gajim/common/modules/vcard_avatars.py - gajim/gtk/accounts.py - gajim/gtk/conversation/view.py - gajim/gtk/message_actions_box.py - gajim/gtk/remove_account.py
Changes:
===================================== gajim/common/client.py ===================================== @@ -150,6 +150,9 @@ def local_address(self) -> Optional[str]: return address.to_string().split(':')[0] return None
+ def is_destroyed(self) -> bool: + return self._destroyed + def set_remove_account(self, value: bool) -> None: # Used by the RemoveAccount Assistant to make the Client # not react to any stream errors that happen while the @@ -157,16 +160,6 @@ def set_remove_account(self, value: bool) -> None: self._remove_account = value
def _create_client(self) -> None: - if self._destroyed: - # If we disable an account cleanup() is called and all - # modules are unregistered. Because disable_account() does not wait - # for the client to properly disconnect, handlers of the - # nbxmpp.Client() are emitted after we called cleanup(). - # After nbxmpp.Client() disconnects and is destroyed we create a - # new instance with this method but modules.get_handlers() fails - # because modules are already unregistered. - # TODO: Make this nicer - return log.info('Create new nbxmpp client') self._client = NBXMPPClient(log_context=self._account) self.connection = self._client @@ -645,12 +638,7 @@ def cleanup(self) -> None: Monitor.disconnect(self._idle_handler_id) app.app.disconnect(self._screensaver_handler_id) if self._client is not None: - # cleanup() is called before nbmxpp.Client has disconnected, - # when we disable the account. So we need to unregister - # handlers here. - # TODO: cleanup() should not be called before disconnect is finished - for handler in modules.get_handlers(self): - self._client.unregister_handler(handler) + self._client.destroy() modules.unregister_modules(self)
def quit(self, kill_core: bool) -> None:
===================================== gajim/common/modules/vcard_avatars.py ===================================== @@ -257,9 +257,11 @@ def preconditions_met(self) -> bool: try: client = app.get_client(self._contact.account) except Exception: + self.set_obsolete() return False
if not client.state.is_available: + self.set_obsolete() return False
if isinstance(self._contact, GroupchatParticipant):
===================================== gajim/gtk/accounts.py ===================================== @@ -545,13 +545,13 @@ def _on_disconnect(event: AccountDisconnected) -> None: if event.account != account: return app.ged.remove_event_handler('account-disconnected', - ged.CORE, + ged.POSTGUI, _on_disconnect) app.interface.disable_account(account)
def _disable() -> None: app.ged.register_event_handler('account-disconnected', - ged.CORE, + ged.POSTGUI, _on_disconnect) client = app.get_client(account) client.change_status('offline', 'offline')
===================================== gajim/gtk/conversation/view.py ===================================== @@ -187,6 +187,12 @@ def switch_contact(self, contact: ChatContactT) -> None: self._block_signals = True self._reset()
+ self._read_marker_row = ReadMarkerRow(self._contact) + self._list_box.add(self._read_marker_row) + + self._scroll_hint_row = ScrollHintRow(self._contact.account) + self._list_box.add(self._scroll_hint_row) + app.settings.disconnect_signals(self)
app.settings.connect_signal('print_join_left', @@ -232,15 +238,6 @@ def _reset(self) -> None: self._read_marker_row = None self._scroll_hint_row = None
- if self._contact is not None: - # These need to be present if ConversationView is reset - # without switch_contact being invoked - self._read_marker_row = ReadMarkerRow(self._contact) - self._list_box.add(self._read_marker_row) - - self._scroll_hint_row = ScrollHintRow(self._contact.account) - self._list_box.add(self._scroll_hint_row) - def reset(self) -> None: assert self._contact is not None self.switch_contact(self._contact)
===================================== gajim/gtk/message_actions_box.py ===================================== @@ -230,7 +230,7 @@ def switch_contact(self, contact: ChatContactT) -> None: self._update_message_input_state()
def clear(self) -> None: - if self._client is not None: + if self._client is not None and not self._client.is_destroyed(): self._set_chatstate(False) self._client.disconnect_all_from_obj(self)
===================================== gajim/gtk/remove_account.py ===================================== @@ -69,8 +69,9 @@ def __init__(self, account: str) -> None: self.connect('destroy', self._on_destroy)
self.register_events([ - ('account-connected', ged.GUI1, self._on_account_connected), - ('account-disconnected', ged.GUI1, self._on_account_disconnected), + ('account-connected', ged.POSTGUI, self._on_account_connected), + ('account-disconnected', ged.POSTGUI, + self._on_account_disconnected), ])
self._set_remove_from_server_checkbox()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/81365d4e8da0287213c7019716c7525d...