plugin XEP-0277: use shortuuid instead of uuid + use item's XMPP URI for atom ID
This commit is contained in:
parent
c09a5feb3c
commit
80efb4b121
1 changed files with 16 additions and 8 deletions
|
|
@ -31,12 +31,13 @@ from sat.tools import xml_tools
|
|||
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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue