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


Commits:
52729d2e by lovetox at 2021-03-20T15:04:27+01:00
Set allow_reply_func

- - - - -


4 changed files:

- gajim/common/modules/contacts.py
- gajim/common/modules/entity_time.py
- gajim/common/modules/last_activity.py
- gajim/common/modules/software_version.py


Changes:

=====================================
gajim/common/modules/contacts.py
=====================================
@@ -254,6 +254,10 @@ def subscription(self):
     def groups(self):
         return self._get_roster_attr('groups')
 
+    @property
+    def is_subscribed(self):
+        return self.subscription in ('from', 'both')
+
     @property
     def is_blocked(self):
         return self._module('Blocking').is_blocked(self._jid)


=====================================
gajim/common/modules/entity_time.py
=====================================
@@ -37,8 +37,20 @@ def set_enabled(self, enabled):
             self._nbxmpp('EntityTime').disable()
             return
 
-        if app.settings.get_account_setting(self._account, 'send_time_info'):
-            self._nbxmpp('EntityTime').enable()
+        if not app.settings.get_account_setting(self._account,
+                                                'send_time_info'):
+            return
+
+        self._nbxmpp('EntityTime').enable()
+        self._nbxmpp('EntityTime').set_allow_reply_func(self._allow_reply)
+
+    def _allow_reply(self, jid):
+        item = self._con.get_module('Roster').get_item(jid.bare)
+        if item is None:
+            return False
+
+        contact = self._get_contact(jid.bare)
+        return contact.is_subscribed
 
 
 def get_instance(*args, **kwargs):


=====================================
gajim/common/modules/last_activity.py
=====================================
@@ -32,15 +32,24 @@ def __init__(self, con):
         BaseModule.__init__(self, con)
 
     def set_enabled(self, enabled):
-        if enabled and app.is_installed('IDLE'):
-            if not app.settings.get_account_setting(self._account,
-                                                    'send_idle_time'):
-                return
-
-            self._nbxmpp('LastActivity').set_idle_func(
-                idle.Monitor.get_idle_sec)
-        else:
+        if not enabled or not app.is_installed('IDLE'):
             self._nbxmpp('LastActivity').disable()
+            return
+
+        if not app.settings.get_account_setting(self._account,
+                                                'send_idle_time'):
+            return
+
+        self._nbxmpp('LastActivity').set_idle_func(idle.Monitor.get_idle_sec)
+        self._nbxmpp('LastActivity').set_allow_reply_func(self._allow_reply)
+
+    def _allow_reply(self, jid):
+        item = self._con.get_module('Roster').get_item(jid.bare)
+        if item is None:
+            return False
+
+        contact = self._get_contact(jid.bare)
+        return contact.is_subscribed
 
 
 def get_instance(*args, **kwargs):


=====================================
gajim/common/modules/software_version.py
=====================================
@@ -32,14 +32,24 @@ def __init__(self, con):
         BaseModule.__init__(self, con)
 
     def set_enabled(self, enabled):
-        if enabled:
-            if not app.settings.get_account_setting(self._account,
-                                                    'send_os_info'):
-                return
-            self._nbxmpp('SoftwareVersion').set_software_version(
-                'Gajim', app.version, get_os_info())
-        else:
+        if not enabled:
             self._nbxmpp('SoftwareVersion').disable()
+            return
+
+        if not app.settings.get_account_setting(self._account, 'send_os_info'):
+            return
+
+        self._nbxmpp('SoftwareVersion').set_software_version(
+            'Gajim', app.version, get_os_info())
+        self._nbxmpp('SoftwareVersion').set_allow_reply_func(self._allow_reply)
+
+    def _allow_reply(self, jid):
+        item = self._con.get_module('Roster').get_item(jid.bare)
+        if item is None:
+            return False
+
+        contact = self._get_contact(jid.bare)
+        return contact.is_subscribed
 
 
 def get_instance(*args, **kwargs):



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

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/52729d2ed50e5cb9d7f26105870728a5ab7b1ef2
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

Reply via email to