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.
This commit is contained in:
parent
c89a771c06
commit
512ae0b91e
1 changed files with 188 additions and 184 deletions
|
|
@ -53,7 +53,7 @@ class Item(object):
|
|||
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 @@ class Item(object):
|
|||
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 @@ class EntriesManager(object):
|
|||
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 @@ class Entry(EntriesManager):
|
|||
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 @@ class QuickBlog(EntriesManager, quick_widgets.QuickWidget):
|
|||
)
|
||||
)
|
||||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue