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


Commits:
e6bcc2de by Philipp Hörist at 2025-08-30T13:18:49+02:00
refactor

- - - - -


2 changed files:

- gajim/common/modules/vcard4.py
- gajim/gtk/contact_popover.py


Changes:

=====================================
gajim/common/modules/vcard4.py
=====================================
@@ -12,9 +12,7 @@
 import inspect
 import time
 import weakref
-from collections.abc import Callable
 
-from gi.repository import GLib
 from nbxmpp.errors import StanzaError
 from nbxmpp.errors import TimeoutStanzaError
 from nbxmpp.modules.vcard4 import VCard
@@ -46,8 +44,7 @@ def request_vcard(
             cached_result = self._vcard_cache.get(jid)
             if cached_result is not None:
                 _, vcard = cached_result
-                GLib.idle_add(self._on_vcard_from_cache, jid, vcard, callback)
-                return
+                return vcard
 
         if inspect.ismethod(callback):
             weak_callable = weakref.WeakMethod(callback)
@@ -69,12 +66,6 @@ def _expire_cache(self) -> None:
             if time.time() - MAX_CACHE_SECONDS > cache_time:
                 self._vcard_cache.pop(jid)
 
-    def _on_vcard_from_cache(
-        self, jid: JID, vcard: VCard, callback: Callable[[JID, VCard], Any]
-    ) -> int:
-        callback(jid, vcard)
-        return GLib.SOURCE_REMOVE
-
     def _on_vcard_received(self, task: Task) -> None:
         try:
             vcard = cast(VCard | None, task.finish())


=====================================
gajim/gtk/contact_popover.py
=====================================
@@ -94,13 +94,18 @@ def __init__(self, contact: BareContact) -> None:
         self._xmpp_address.set_label(str(self._contact.jid), 
link_scheme="xmpp")
 
         client = app.get_client(contact.account)
-        client.get_module("VCard4").request_vcard(
-            jid=self._contact.jid, callback=self._on_vcard_received
+        vcard = client.get_module("VCard4").request_vcard(
+            jid=self._contact.jid, callback=self._on_vcard_received, 
use_cache=True
         )
+        if vcard is not None:
+            self._set_vcard_rows(vcard)
 
         app.plugin_manager.extension_point("contact_tooltip_populate", self, 
contact)
 
     def _on_vcard_received(self, jid: JID, vcard: VCard) -> None:
+        self._set_vcard_rows(vcard)
+
+    def _set_vcard_rows(self, vcard: VCard) -> None:
         for prop in vcard.get_properties():
             match prop:
                 case RoleProperty():



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

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