Mercurial > libervia-backend
comparison sat/core/xmpp.py @ 3221:b1c90eedbc12
core (xmpp): fixed workflow with post_xml_treatments in sendMessage:
post_xml_treatments was incorrectly added to workflow using chainDeferred (which only
add the callback, so post_xml_treatments own callbacks were not waited). As a result,
plugins callback could not be waited as expected before a message was sent.
This patch fixes it by not using chainDeferred anymore.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 22 Mar 2020 13:59:19 +0100 |
parents | fee8e33e2b3f |
children | 0404b306641d |
comparison
equal
deleted
inserted
replaced
3220:4fbea7f1e012 | 3221:b1c90eedbc12 |
---|---|
494 """shortcut to create an IQ element managing deferred | 494 """shortcut to create an IQ element managing deferred |
495 | 495 |
496 @param type_(unicode): IQ type ('set' or 'get') | 496 @param type_(unicode): IQ type ('set' or 'get') |
497 @param timeout(None, int): timeout in seconds | 497 @param timeout(None, int): timeout in seconds |
498 @return((D)domish.Element: result stanza | 498 @return((D)domish.Element: result stanza |
499 errback is called if and error stanza is returned | 499 errback is called if an error stanza is returned |
500 """ | 500 """ |
501 iq_elt = xmlstream.IQ(self.xmlstream, type_) | 501 iq_elt = xmlstream.IQ(self.xmlstream, type_) |
502 iq_elt.timeout = timeout | 502 iq_elt.timeout = timeout |
503 return iq_elt | 503 return iq_elt |
504 | 504 |
509 @param condition(unicode): error condition | 509 @param condition(unicode): error condition |
510 """ | 510 """ |
511 iq_error_elt = error.StanzaError(condition).toResponse(iq_elt) | 511 iq_error_elt = error.StanzaError(condition).toResponse(iq_elt) |
512 self.xmlstream.send(iq_error_elt) | 512 self.xmlstream.send(iq_error_elt) |
513 | 513 |
514 def generateMessageXML(self, data): | 514 def generateMessageXML(self, data, post_xml_treatments=None): |
515 """Generate <message/> stanza from message data | 515 """Generate <message/> stanza from message data |
516 | 516 |
517 @param data(dict): message data | 517 @param data(dict): message data |
518 domish element will be put in data['xml'] | 518 domish element will be put in data['xml'] |
519 following keys are needed: | 519 following keys are needed: |
522 - uid: can be set to '' if uid attribute is not wanted | 522 - uid: can be set to '' if uid attribute is not wanted |
523 - message | 523 - message |
524 - type | 524 - type |
525 - subject | 525 - subject |
526 - extra | 526 - extra |
527 @param post_xml_treatments(Deferred): a Deferred which will be called with data | |
528 one XML is generated | |
527 @return (dict) message data | 529 @return (dict) message data |
528 """ | 530 """ |
529 data["xml"] = message_elt = domish.Element((None, "message")) | 531 data["xml"] = message_elt = domish.Element((None, "message")) |
530 message_elt["to"] = data["to"].full() | 532 message_elt["to"] = data["to"].full() |
531 message_elt["from"] = data["from"].full() | 533 message_elt["from"] = data["from"].full() |
552 thread_elt = message_elt.addElement("thread", content=thread) | 554 thread_elt = message_elt.addElement("thread", content=thread) |
553 try: | 555 try: |
554 thread_elt["parent"] = data["extra"]["thread_parent"] | 556 thread_elt["parent"] = data["extra"]["thread_parent"] |
555 except KeyError: | 557 except KeyError: |
556 pass | 558 pass |
559 | |
560 if post_xml_treatments is not None: | |
561 post_xml_treatments.callback(data) | |
557 return data | 562 return data |
558 | 563 |
559 def addPostXmlCallbacks(self, post_xml_treatments): | 564 def addPostXmlCallbacks(self, post_xml_treatments): |
560 """Used to add class level callbacks at the end of the workflow | 565 """Used to add class level callbacks at the end of the workflow |
561 | 566 |
648 return defer.succeed(None) | 653 return defer.succeed(None) |
649 | 654 |
650 log.debug(_("Sending message (type {type}, to {to})") | 655 log.debug(_("Sending message (type {type}, to {to})") |
651 .format(type=data["type"], to=to_jid.full())) | 656 .format(type=data["type"], to=to_jid.full())) |
652 | 657 |
653 pre_xml_treatments.addCallback(lambda __: self.generateMessageXML(data)) | 658 pre_xml_treatments.addCallback(lambda __: self.generateMessageXML(data, post_xml_treatments)) |
654 pre_xml_treatments.chainDeferred(post_xml_treatments) | 659 pre_xml_treatments.addCallback(lambda __: post_xml_treatments) |
655 post_xml_treatments.addCallback(self.sendMessageData) | 660 post_xml_treatments.addCallback(lambda __: self.sendMessageData(data)) |
656 if send_only: | 661 if send_only: |
657 log.debug(_("Triggers, storage and echo have been inhibited by the " | 662 log.debug(_("Triggers, storage and echo have been inhibited by the " |
658 "'send_only' parameter")) | 663 "'send_only' parameter")) |
659 else: | 664 else: |
660 self.addPostXmlCallbacks(post_xml_treatments) | 665 self.addPostXmlCallbacks(post_xml_treatments) |