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


Commits:
96ddd13f by Philipp Hörist at 2026-03-24T00:30:38+01:00
feat: Bring back Entity Time (XEP-0202) support

- - - - -


3 changed files:

- gajim/common/client.py
- gajim/common/modules/entity_time.py
- gajim/common/modules/vcard4.py


Changes:

=====================================
gajim/common/client.py
=====================================
@@ -536,6 +536,7 @@ def _finish_connect(self) -> None:
         self.get_module('Bookmarks').request_bookmarks()
         self.get_module('SoftwareVersion').set_enabled(True)
         self.get_module('LastActivity').set_enabled(True)
+        self.get_module('EntityTime').set_enabled(True)
         self.get_module('Annotations').request_annotations()
         self.get_module('Blocking').get_blocking_list()
         self.get_module('VCard4').subscribe_to_node()


=====================================
gajim/common/modules/entity_time.py
=====================================
@@ -6,8 +6,13 @@
 
 from __future__ import annotations
 
+from typing import cast
+
+from nbxmpp.protocol import JID
+
 from gajim.common import types
 from gajim.common.modules.base import BaseModule
+from gajim.common.modules.contacts import BareContact
 
 
 class EntityTime(BaseModule):
@@ -23,3 +28,26 @@ def __init__(self, con: types.Client) -> None:
         BaseModule.__init__(self, con)
 
         self.handlers = []
+
+    def set_enabled(self, enabled: bool) -> None:
+        if not enabled:
+            self._nbxmpp('EntityTime').disable()
+            return
+
+        self._nbxmpp('EntityTime').enable()
+        self._nbxmpp('EntityTime').set_allow_reply_func(self._allow_reply)
+
+    def _allow_reply(self, jid: JID) -> bool:
+        bare_jid = jid.new_as_bare()
+        item = self._con.get_module('Roster').get_item(bare_jid)
+        if item is None:
+            return False
+
+        if not self._client.get_module("VCard4").is_timezone_published():
+            self._log.info(
+                "Ignore entity time request, because timezone is not published"
+            )
+            return False
+
+        contact = cast(BareContact, self._get_contact(bare_jid))
+        return contact.is_subscribed


=====================================
gajim/common/modules/vcard4.py
=====================================
@@ -121,6 +121,9 @@ def update_timezone(self) -> None:
     def ignore_timezone_change(self) -> None:
         self._ignore_timezone_change = True
 
+    def is_timezone_published(self) -> bool:
+        return get_timezone_from_vcard(self._own_vcard) is not None
+
     def subscribe_to_node(self) -> None:
         self._log.info("Subscribe to node")
         self._client.get_module('PubSub').subscribe(Namespace.VCARD4_PUBSUB)



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

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