Philipp Hörist pushed to branch master at gajim / python-nbxmpp


Commits:
deca68c5 by nicoco at 2025-10-23T12:19:19+00:00
imprv: Add pronouns field to VCard4

- - - - -


2 changed files:

- nbxmpp/modules/vcard4.py
- test/unit/test_vcard4.py


Changes:

=====================================
nbxmpp/modules/vcard4.py
=====================================
@@ -50,6 +50,7 @@ PROPERTY_DEFINITION: dict[str, tuple[list[str], Literal["*", 
"*1", "1*", "1"]]]
     "bday": (["altid", "calscale"], "*1"),
     "anniversary": (["altid", "calscale"], "*1"),
     "gender": ([], "*1"),
+    "pronouns": (["language", "pref", "type", "altid"], "*"),
     "adr": (["language", "altid", "pid", "pref", "type", "geo", "tz", 
"label"], "*"),
     "tel": (["altid", "pid", "pref", "type", "mediatype"], "*"),
     "email": (["altid", "pid", "pref", "type"], "*"),
@@ -681,6 +682,11 @@ class GenderProperty:
         )
 
 
+@dataclass
+class PronounsProperty(TextProperty):
+    name: str = field(default="pronouns", init=False)
+
+
 @dataclass
 class AdrProperty:
 
@@ -993,6 +999,7 @@ PROPERTY_CLASSES = {
     "bday": BDayProperty,
     "anniversary": AnniversaryProperty,
     "gender": GenderProperty,
+    "pronouns": PronounsProperty,
     "adr": AdrProperty,
     "tel": TelProperty,
     "email": EmailProperty,
@@ -1030,6 +1037,7 @@ PropertyT = (
     | BDayProperty
     | AnniversaryProperty
     | GenderProperty
+    | PronounsProperty
     | AdrProperty
     | TelProperty
     | EmailProperty


=====================================
test/unit/test_vcard4.py
=====================================
@@ -104,6 +104,9 @@ class TestVCard4(unittest.TestCase):
                 <key>
                   <uri>https://stpeter.im/stpeter.asc</uri>
                 </key>
+                <pronouns>
+                  <text>he/him</text>
+                </pronouns>
                 <unsupported-element>unsupported</unsupported-element>
             </vcard>
         """
@@ -125,6 +128,39 @@ class TestVCard4(unittest.TestCase):
         assert isinstance(lang_param, LanguageParameter)
         self.assertEqual(lang_param.value, "fr")
 
+        pronouns_props = list(filter(lambda p: p.name == "pronouns", props))
+        self.assertEqual(len(pronouns_props), 1)
+        self.assertEqual(pronouns_props[0].value, "he/him")
+
         # Preserve unsupported elements
         node = vcard.to_node()
         self.assertEqual(node.getTagData("unsupported-element"), "unsupported")
+
+    def test_vcard4_pronouns(self):
+        vcard_node = Node(
+            node="""
+            <vcard xmlns="urn:ietf:params:xml:ns:vcard-4.0">
+                <fn><text>Cartman</text></fn>
+                <pronouns>
+                  <parameters>
+                    <language><language-tag>fr</language-tag></language>
+                    <pref>
+                      <integer>1</integer>
+                    </pref>
+                  </parameters>
+                  <text>il/lui</text>
+                </pronouns>
+                <pronouns>
+                  <text>he/him</text>
+                </pronouns>
+            </vcard>
+        """
+        )
+
+        vcard = VCard.from_node(vcard_node)
+        props = vcard.get_properties()
+        pronouns_props = list(filter(lambda p: p.name == "pronouns", props))
+        self.assertEqual(len(pronouns_props), 2)
+        self.assertEqual(
+            pronouns_props[0].parameters.get_parameter("language").value, "fr"
+        )



View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/deca68c5e752ba4004b8461d9c02e1dcc33a9e9f

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