diff libervia/backend/plugins/plugin_xep_0084.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0084.py	Tue Jun 18 12:06:45 2024 +0200
+++ b/libervia/backend/plugins/plugin_xep_0084.py	Wed Jun 19 18:44:57 2024 +0200
@@ -65,13 +65,9 @@
         host.register_namespace("avatar_data", NS_AVATAR_DATA)
         self.host = host
         self._p = host.plugins["XEP-0060"]
-        self._i = host.plugins['IDENTITY']
+        self._i = host.plugins["IDENTITY"]
         self._i.register(
-            IMPORT_NAME,
-            "avatar",
-            self.get_avatar,
-            self.set_avatar,
-            priority=2000
+            IMPORT_NAME, "avatar", self.get_avatar, self.set_avatar, priority=2000
         )
         host.plugins["XEP-0163"].add_pep_event(
             None, NS_AVATAR_METADATA, self._on_metadata_update
@@ -85,19 +81,15 @@
         defer.ensureDeferred(self.on_metadata_update(client, itemsEvent))
 
     async def on_metadata_update(
-        self,
-        client: SatXMPPEntity,
-        itemsEvent: pubsub.ItemsEvent
+        self, client: SatXMPPEntity, itemsEvent: pubsub.ItemsEvent
     ) -> None:
         entity = client.jid.userhostJID()
         avatar_metadata = await self.get_avatar(client, entity)
         await self._i.update(client, IMPORT_NAME, "avatar", avatar_metadata, entity)
 
     async def get_avatar(
-            self,
-            client: SatXMPPEntity,
-            entity_jid: jid.JID
-        ) -> Optional[dict]:
+        self, client: SatXMPPEntity, entity_jid: jid.JID
+    ) -> Optional[dict]:
         """Get avatar data
 
         @param entity: entity to get avatar from
@@ -107,10 +99,7 @@
         # metadata
         try:
             items, __ = await self._p.get_items(
-                client,
-                service,
-                NS_AVATAR_METADATA,
-                max_items=1
+                client, service, NS_AVATAR_METADATA, max_items=1
             )
         except exceptions.NotFound:
             return None
@@ -130,7 +119,7 @@
                 metadata = {
                     "id": str(info_elt["id"]),
                     "size": int(info_elt["bytes"]),
-                    "media_type": str(info_elt["type"])
+                    "media_type": str(info_elt["type"]),
                 }
                 avatar_id = metadata["id"]
                 if not avatar_id:
@@ -150,10 +139,7 @@
         if not cache_data:
             try:
                 data_items, __ = await self._p.get_items(
-                    client,
-                    service,
-                    NS_AVATAR_DATA,
-                    item_ids=[avatar_id]
+                    client, service, NS_AVATAR_DATA, item_ids=[avatar_id]
                 )
                 data_item_elt = data_items[0]
             except (error.StanzaError, IndexError) as e:
@@ -173,18 +159,13 @@
                 )
                 return None
             with self.host.common_cache.cache_data(
-                IMPORT_NAME,
-                avatar_id,
-                metadata["media_type"]
+                IMPORT_NAME, avatar_id, metadata["media_type"]
             ) as f:
                 f.write(avatar_buf)
-                cache_data = {
-                    "path": Path(f.name),
-                    "mime_type": metadata["media_type"]
-                }
+                cache_data = {"path": Path(f.name), "mime_type": metadata["media_type"]}
 
         return self._i.avatar_build_metadata(
-                cache_data['path'], cache_data['mime_type'], avatar_id
+            cache_data["path"], cache_data["mime_type"], avatar_id
         )
 
     def build_item_data_elt(self, avatar_data: Dict[str, Any]) -> domish.Element:
@@ -213,10 +194,7 @@
         return pubsub.Item(id=self._p.ID_SINGLETON, payload=metadata_elt)
 
     async def set_avatar(
-        self,
-        client: SatXMPPEntity,
-        avatar_data: Dict[str, Any],
-        entity: jid.JID
+        self, client: SatXMPPEntity, avatar_data: Dict[str, Any], entity: jid.JID
     ) -> None:
         """Set avatar of the profile
 
@@ -235,7 +213,7 @@
                 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
                 self._p.OPT_PERSIST_ITEMS: 1,
                 self._p.OPT_MAX_ITEMS: 1,
-            }
+            },
         )
         item_data_elt = self.build_item_data_elt(avatar_data)
         await self._p.send_items(client, service, NS_AVATAR_DATA, [item_data_elt])
@@ -249,7 +227,7 @@
                 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
                 self._p.OPT_PERSIST_ITEMS: 1,
                 self._p.OPT_MAX_ITEMS: 1,
-            }
+            },
         )
         item_metadata_elt = self.build_item_metadata_elt(avatar_data)
         await self._p.send_items(client, service, NS_AVATAR_METADATA, [item_metadata_elt])
@@ -261,7 +239,7 @@
     def getDiscoInfo(self, requestor, service, nodeIdentifier=""):
         return [
             disco.DiscoFeature(NS_AVATAR_METADATA),
-            disco.DiscoFeature(NS_AVATAR_DATA)
+            disco.DiscoFeature(NS_AVATAR_DATA),
         ]
 
     def getDiscoItems(self, requestor, service, nodeIdentifier=""):