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


Commits:
42d32017 by nicoco at 2025-03-08T16:36:26+00:00
feat: Use XEP-0172 nickname of contacts not in roster

Fixes #11476

- - - - -


1 changed file:

- gajim/common/modules/user_nickname.py


Changes:

=====================================
gajim/common/modules/user_nickname.py
=====================================
@@ -10,10 +10,12 @@
 
 from nbxmpp.namespaces import Namespace
 from nbxmpp.structs import MessageProperties
+from nbxmpp.structs import StanzaHandler
 
 from gajim.common import app
 from gajim.common import types
 from gajim.common.modules.base import BaseModule
+from gajim.common.modules.contacts import BareContact
 from gajim.common.modules.util import event_node
 
 
@@ -29,6 +31,47 @@ def __init__(self, con: types.Client):
         BaseModule.__init__(self, con)
         self._register_pubsub_handler(self._nickname_received)
 
+        self.handlers = [
+            StanzaHandler(name='message',
+                          callback=self._message_nickname_received,
+                          typ='chat',
+                          priority=51),
+        ]
+
+    def _message_nickname_received(
+        self,
+        _con: types.NBXMPPClient,
+        _stanza: Any,
+        properties: MessageProperties
+    ) -> None:
+
+        if properties.nickname is None:
+            return
+
+        remote_jid = properties.remote_jid
+        assert remote_jid is not None
+
+        contact = self._client.get_module('Contacts').get_contact(remote_jid)
+        if not isinstance(contact, BareContact):
+            return
+
+        if contact.subscription in ('both', 'to'):
+            # When we are subscripted to this contact we can
+            # get the nickname via pubsub
+            return
+
+        if contact.name == properties.nickname:
+            return
+
+        app.storage.cache.set_contact(
+            self._account,
+            remote_jid,
+            'nickname',
+            f'{properties.nickname} ({remote_jid})'
+        )
+
+        contact.notify('nickname-update')
+
     @event_node(Namespace.NICK)
     def _nickname_received(self,
                            _con: types.NBXMPPClient,



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

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