diff sat_frontends/quick_frontend/quick_blog.py @ 2807:0b7ce5daee9b

plugin XEP-0277: blog items data are now entirely serialised before going to bridge: So far, and for historical reasons, blog items data where serialised using a unicode: unicode dict, which was causing trouble for many types of values (timestamps, booleans, lists). This patch changes it by serialising the whole items before going to bridge, and deserialising it when going back. This way, complex data can be used easily in items. This impact psEvent and serItemsData* methods which are renamed transItemsData* because there are not always serialising anymore (a new argument "serialise" allows to specify it). When editing a blog post in jp, metadata are now more easy to manipulate, specially lists like tags.
author Goffi <goffi@goffi.org>
date Sat, 23 Feb 2019 18:59:00 +0100
parents 003b8b4b56a7
children ab2696e34d29
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_blog.py	Wed Feb 20 19:42:35 2019 +0100
+++ b/sat_frontends/quick_frontend/quick_blog.py	Sat Feb 23 18:59:00 2019 +0100
@@ -53,7 +53,7 @@
         self.title = data.get("title")
         self.title_rich = None
         self.title_xhtml = data.get("title_xhtml")
-        self.tags = list(data_format.dict2iter("tag", data))
+        self.tags = data.get('tags', [])
         self.content = data.get("content")
         self.content_rich = None
         self.content_xhtml = data.get("content_xhtml")
@@ -64,10 +64,7 @@
         except KeyError:
             self.author_jid = None
 
-        try:
-            self.author_verified = C.bool(data["author_jid_verified"])
-        except KeyError:
-            self.author_verified = False
+        self.author_verified = data.get("author_jid_verified", False)
 
         try:
             self.updated = float(
@@ -148,16 +145,8 @@
         for item, comments in items:
             self.addEntry(item, comments, service=service, node=node, with_update=False)
 
-    def addEntry(
-        self,
-        item=None,
-        comments=None,
-        service=None,
-        node=None,
-        with_update=True,
-        editable=False,
-        edit_entry=False,
-    ):
+    def addEntry(self, item=None, comments=None, service=None, node=None,
+                 with_update=True, editable=False, edit_entry=False):
         """Add a microblog entry
 
         @param editable (bool): True if the entry can be modified
@@ -286,21 +275,21 @@
                 if value is not None:
                     mb_data[name] = value
 
-        data_format.iter2dict("tag", self.item.tags, mb_data)
+        mb_data['tags'] = self.item.tags
 
         if self.blog.new_message_target not in (C.PUBLIC, C.GROUP):
             raise NotImplementedError
 
         if self.level == 0:
-            mb_data["allow_comments"] = C.BOOL_TRUE
+            mb_data["allow_comments"] = True
 
         if self.blog.new_message_target == C.GROUP:
-            data_format.iter2dict("group", self.blog.targets, mb_data)
+            mb_data['groups'] = list(self.blog.targets)
 
         self.blog.host.bridge.mbSend(
             unicode(self.service or ""),
             self.node or "",
-            mb_data,
+            data_format.serialise(mb_data),
             profile=self.blog.profile,
         )
 
@@ -398,9 +387,14 @@
             )
         )
         for result in results:
-            service, node, failure, items, metadata = result
+            service, node, failure, items_data, metadata = result
+            for item_data in items_data:
+                item_data[0] = data_format.deserialise(item_data[0])
+                for item_metadata in item_data[1]:
+                    item_metadata[3] = [data_format.deserialise(i) for i in item_metadata[3]]
             if not failure:
-                self._addMBItemsWithComments((items, metadata), service=jid.JID(service))
+                self._addMBItemsWithComments((items_data, metadata),
+                                             service=jid.JID(service))
 
         self.update()
         if remaining: