Philipp Hörist pushed to branch master at gajim / gajim


Commits:
f17bdee3 by Philipp Hörist at 2024-05-31T23:52:18+02:00
fix: Application: Reactived feature actions after sm resume

- - - - -


3 changed files:

- gajim/common/client.py
- gajim/gtk/application.py
- gajim/gtk/main.py


Changes:

=====================================
gajim/common/client.py
=====================================
@@ -191,6 +191,7 @@ def _on_resume_successful(self,
             self.update_presence()
 
         self.notify('state-changed', SimpleClientState.CONNECTED)
+        self.notify('resume-successful')
 
     def _set_client_available(self) -> None:
         self._set_state(ClientState.AVAILABLE)


=====================================
gajim/gtk/application.py
=====================================
@@ -43,7 +43,6 @@
 from nbxmpp import JID
 from nbxmpp.const import ConnectionProtocol
 from nbxmpp.const import ConnectionType
-from nbxmpp.namespaces import Namespace
 from nbxmpp.protocol import InvalidJid
 
 import gajim
@@ -486,10 +485,20 @@ def set_account_actions_state(self,
         for action_name in ONLINE_ACCOUNT_ACTIONS:
             self.set_action_state(f'{account}-{action_name}', new_state)
 
+        # Disable all feature actions on disconnect
         if not new_state:
             for action_name in FEATURE_ACCOUNT_ACTIONS:
                 self.set_action_state(f'{account}-{action_name}', new_state)
 
+    def update_feature_actions_state(self, account: str) -> None:
+        client = app.get_client(account)
+        mam_available = client.get_module('MAM').available
+        blocking_available = client.get_module('Blocking').supported
+
+        self.set_action_state(f'{account}-archive', mam_available)
+        self.set_action_state(f'{account}-blocking', blocking_available)
+        self.set_action_state(f'{account}-block-contact', blocking_available)
+
     def update_app_actions_state(self) -> None:
         active_accounts = bool(app.get_connected_accounts(exclude_local=True))
         self.set_action_state('create-groupchat', active_accounts)
@@ -514,14 +523,7 @@ def _load_shortcuts(self) -> None:
             self.set_accels_for_action(action, accels)
 
     def _on_feature_discovered(self, event: events.FeatureDiscovered) -> None:
-        if event.feature == Namespace.MAM_2:
-            action = '%s-archive' % event.account
-            self.set_action_state(action, True)
-        elif event.feature == Namespace.BLOCKING:
-            action = '%s-blocking' % event.account
-            self.set_action_state(action, True)
-            action = '%s-block-contact' % event.account
-            self.set_action_state(action, True)
+        self.update_feature_actions_state(event.account)
 
     def create_account(self,
                        account: str,


=====================================
gajim/gtk/main.py
=====================================
@@ -158,6 +158,8 @@ def __init__(self) -> None:
         for client in app.get_clients():
             client.connect_signal('state-changed',
                                   self._on_client_state_changed)
+            client.connect_signal('resume-successful',
+                                  self._on_client_resume_successful)
 
     def get_action(self, name: str) -> Gio.SimpleAction:
         action = self.lookup_action(name)
@@ -234,6 +236,8 @@ def _on_account_enabled(self, event: events.AccountEnabled) 
-> None:
         self._main_stack.add_account_page(event.account)
         client = app.get_client(event.account)
         client.connect_signal('state-changed', self._on_client_state_changed)
+        client.connect_signal('resume-successful',
+                              self._on_client_resume_successful)
 
     def _on_account_disabled(self, event: events.AccountDisabled) -> None:
         workspace_id = self._workspace_side_bar.get_first_workspace()
@@ -294,6 +298,12 @@ def _on_client_state_changed(self,
         app.app.set_account_actions_state(client.account, state.is_connected)
         app.app.update_app_actions_state()
 
+    def _on_client_resume_successful(self,
+                                     client: Client,
+                                     _signal_name: str) -> None:
+
+        app.app.update_feature_actions_state(client.account)
+
     def _on_allow_gajim_update(self,
                                event: events.AllowGajimUpdateCheck) -> None:
         self.add_app_message(event.name)



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/f17bdee3750aec91e361f455e0da77de0226b6d3

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/f17bdee3750aec91e361f455e0da77de0226b6d3
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to