Philipp Hörist pushed to branch master at gajim / gajim
Commits:
dce40846 by lovetox at 2020-05-16T17:50:30+02:00
Client: Unregister modules when account is disabled
- - - - -
fbd65d79 by lovetox at 2020-05-16T17:50:30+02:00
Client: Don't create nbxmpp.Client() after cleanup()
- - - - -
fdfb0864 by lovetox at 2020-05-16T17:50:30+02:00
PluginManager: Remove obsolete check on handler registration
- - - - -
2 changed files:
- gajim/common/client.py
- gajim/plugins/pluginmanager.py
Changes:
=====================================
gajim/common/client.py
=====================================
@@ -57,7 +57,6 @@ class Client(ConnectionHandlers):
self.password = None
self._priority = 0
- self.handlers_registered = False
self._connect_machine_calls = 0
self.avatar_conversion = False
self.addressing_supported = False
@@ -77,9 +76,10 @@ class Client(ConnectionHandlers):
self._ssl_errors = set()
+ self._destroyed = False
+
self.available_transports = {}
- # Register all modules
modules.register_modules(self)
self._create_client()
@@ -121,6 +121,16 @@ class Client(ConnectionHandlers):
self._remove_account = value
def _create_client(self):
+ 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
@@ -162,7 +172,8 @@ class Client(ConnectionHandlers):
self._client.subscribe('stanza-sent', self._on_stanza_sent)
self._client.subscribe('stanza-received', self._on_stanza_received)
- self._register_new_handlers()
+ for handler in modules.get_handlers(self):
+ self._client.register_handler(handler)
def process_ssl_errors(self):
if not self._ssl_errors:
@@ -372,11 +383,6 @@ class Client(ConnectionHandlers):
app.nec.push_incoming_event(
OurShowEvent(None, conn=self, show=show))
- def _register_new_handlers(self):
- for handler in modules.get_handlers(self):
- self._client.register_handler(handler)
- self.handlers_registered = True
-
def get_module(self, name):
return modules.get(self._account, name)
@@ -522,7 +528,8 @@ class Client(ConnectionHandlers):
self._reconnect_timer_source = None
def cleanup(self):
- pass
+ self._destroyed = True
+ modules.unregister_modules(self)
def quit(self, kill_core):
if kill_core and self._state in (ClientState.CONNECTING,
=====================================
gajim/plugins/pluginmanager.py
=====================================
@@ -406,13 +406,8 @@ class PluginManager(metaclass=Singleton):
instance, name = module.get_instance(con)
modules.register_single_module(con, instance, name)
- # If handlers have been registered, register the
- # plugin handlers. Otherwise this will be done
- # automatically on connecting
- # in connection_handlers._register_handlers()
- if con.handlers_registered:
- for handler in instance.handlers:
- con.connection.register_handler(handler)
+ for handler in instance.handlers:
+ con.connection.register_handler(handler)
def _unregister_modules_with_handlers(self, plugin):
if not hasattr(plugin, 'modules'):
@@ -422,11 +417,8 @@ class PluginManager(metaclass=Singleton):
instance = con.get_module(module.name)
modules.unregister_single_module(con, module.name)
- # Account is still connected and handlers are registered
- # So just unregister the plugin handlers
- if con.handlers_registered:
- for handler in instance.handlers:
- con.connection.unregister_handler(handler)
+ for handler in instance.handlers:
+ con.connection.unregister_handler(handler)
def activate_plugin(self, plugin):
'''
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/fe82e8874b5f904a5fcdc7780156e34…
--
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/fe82e8874b5f904a5fcdc7780156e34…
You're receiving this email because of your account on dev.gajim.org.