# HG changeset patch # User Goffi # Date 1516654846 -3600 # Node ID dc55b854ccf38192d00eda6eaa5c2a71d38dd721 # Parent 0d6c53e6c591b484f47169806d8f5fd095c15ea9 plugin XEP-0277: use shortuuid instead of uuid + use item's XMPP URI for atom ID diff -r 0d6c53e6c591 -r dc55b854ccf3 src/plugins/plugin_xep_0277.py --- a/src/plugins/plugin_xep_0277.py Mon Jan 22 08:36:36 2018 +0100 +++ b/src/plugins/plugin_xep_0277.py Mon Jan 22 22:00:46 2018 +0100 @@ -31,12 +31,13 @@ from sat.tools import sat_defer from sat.tools import utils from sat.tools.common import data_format +from sat.tools.common import uri as xmpp_uri # XXX: sat_tmp.wokkel.pubsub is actually used instead of wokkel version from wokkel import pubsub from wokkel import disco, iwokkel from zope.interface import implements -import uuid +import shortuuid import time import dateutil import calendar @@ -345,14 +346,17 @@ defer.returnValue(microblog_data) @defer.inlineCallbacks - def data2entry(self, data, item_id=None, profile=C.PROF_KEY_NONE): + def data2entry(self, client, data, item_id, service, node): """Convert a data dict to en entry usable to create an item @param data: data dict as given by bridge method. - @param item_id(unicode, None): id of the item to use + @param item_id(unicode): id of the item to use + @param service(jid.JID, None): pubsub service where the item is sent + Needed to construct Atom id + @param node(unicode): pubsub node where the item is sent + Needed to construct Atom id @return: deferred which fire domish.Element """ - client = self.host.getClient(profile) entry_elt = domish.Element((NS_ATOM, 'entry')) ## language ## @@ -369,7 +373,7 @@ elem = entry_elt.addElement(elem_name) if type_: if type_ == '_rich': # convert input from current syntax to XHTML - xml_content = yield synt.convert(data[attr], synt.getCurrentSyntax(profile), "XHTML") + xml_content = yield synt.convert(data[attr], synt.getCurrentSyntax(client.profile), "XHTML") if '{}_xhtml'.format(elem_name) in data: raise failure.Failure(exceptions.DataError(_("Can't have xhtml and rich content at the same time"))) else: @@ -442,7 +446,11 @@ category_elt['term'] = tag ## id ## - entry_id = data.get('id', item_id or unicode(uuid.uuid4())) # FIXME: use a proper id (see XEP-0277 §7.1) + entry_id = data.get('id', xmpp_uri.buildXMPPUri( + u'pubsub', + path=service.full() if service is not None else client.jid.userhost(), + node=node, + item=item_id)) entry_elt.addElement('id', content=entry_id) # ## comments ## @@ -596,13 +604,13 @@ if node is None: node = NS_MICROBLOG - item_id = data.get('id') or unicode(uuid.uuid4()) + item_id = data.get('id') or unicode(shortuuid.uuid()) try: yield self._manageComments(client, data, service, node, item_id, access=None) except error.StanzaError: log.warning(u"Can't create comments node for item {}".format(item_id)) - item = yield self.data2entry(data, item_id, client.profile) + item = yield self.data2entry(client, data, item_id, service, node) ret = yield self._p.publish(client, service, node, [item]) defer.returnValue(ret)