comparison src/backend.py @ 381:7c490bb60847

backend: items ids are returned in payload if not specified on publish
author Goffi <goffi@goffi.org>
date Sun, 13 Jan 2019 18:56:19 +0100
parents e81964db3cd6
children aa3a464df605
comparison
equal deleted inserted replaced
380:e81964db3cd6 381:7c490bb60847
68 from twisted.application import service 68 from twisted.application import service
69 from twisted.python import components, log 69 from twisted.python import components, log
70 from twisted.internet import defer, reactor 70 from twisted.internet import defer, reactor
71 from twisted.words.protocols.jabber.error import StanzaError 71 from twisted.words.protocols.jabber.error import StanzaError
72 # from twisted.words.protocols.jabber.jid import JID, InvalidFormat 72 # from twisted.words.protocols.jabber.jid import JID, InvalidFormat
73 from twisted.words.xish import utility 73 from twisted.words.xish import domish, utility
74 74
75 from wokkel import disco 75 from wokkel import disco
76 from wokkel import data_form 76 from wokkel import data_form
77 from wokkel import rsm 77 from wokkel import rsm
78 from wokkel import iwokkel 78 from wokkel import iwokkel
378 elif not items and (persistItems or deliverPayloads): 378 elif not items and (persistItems or deliverPayloads):
379 raise error.ItemRequired() 379 raise error.ItemRequired()
380 380
381 items_data = [] 381 items_data = []
382 check_overwrite = False 382 check_overwrite = False
383 ret_payload = None # payload returned, None or domish.Element
383 for item in items: 384 for item in items:
384 # we enforce publisher (cf XEP-0060 §7.1.2.3) 385 # we enforce publisher (cf XEP-0060 §7.1.2.3)
385 item['publisher'] = requestor.full() 386 item['publisher'] = requestor.full()
386 if persistItems or deliverPayloads: 387 if persistItems or deliverPayloads:
387 item.uri = None 388 item.uri = None
388 item.defaultUri = None 389 item.defaultUri = None
389 if not item.getAttribute("id"): 390 if not item.getAttribute("id"):
390 item["id"] = yield node.getNextId() 391 item["id"] = yield node.getNextId()
391 new_item = True 392 new_item = True
393 ret_pubsub_elt = domish.Element((pubsub.NS_PUBSUB, u'pubsub'))
394 ret_publish_elt = ret_pubsub_elt.addElement(u'publish')
395 ret_publish_elt[u'node'] = node.nodeIdentifier
396 ret_item_elt = ret_publish_elt.addElement(u'item')
397 ret_item_elt["id"] = item[u"id"]
398 ret_payload = ret_pubsub_elt
392 else: 399 else:
393 check_overwrite = True 400 check_overwrite = True
394 new_item = False 401 new_item = False
395 access_model, item_config = self.parseItemConfig(item) 402 access_model, item_config = self.parseItemConfig(item)
396 categories = self.parseCategories(item) 403 categories = self.parseCategories(item)
408 415
409 # TODO: check conflict and recalculate max id if serial_ids is set 416 # TODO: check conflict and recalculate max id if serial_ids is set
410 yield node.storeItems(items_data, requestor) 417 yield node.storeItems(items_data, requestor)
411 418
412 yield self._doNotify(node, items_data, deliverPayloads, pep, recipient) 419 yield self._doNotify(node, items_data, deliverPayloads, pep, recipient)
420 defer.returnValue(ret_payload)
413 421
414 def _doNotify(self, node, items_data, deliverPayloads, pep, recipient): 422 def _doNotify(self, node, items_data, deliverPayloads, pep, recipient):
415 if items_data and not deliverPayloads: 423 if items_data and not deliverPayloads:
416 for item_data in items_data: 424 for item_data in items_data:
417 item_data.item.children = [] 425 item_data.item.children = []