Mercurial > libervia-backend
comparison src/core/sat_main.py @ 697:0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
- treaments deferred can be used by plugins to change XML elements before sending them, in a similar way as for newMessage
- sendMessageXml trigger became useless, so it as been removed in favor of the new deferred
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 13 Nov 2013 13:57:36 +0100 |
parents | 9a50aa7feefb |
children | d731ae066158 |
comparison
equal
deleted
inserted
replaced
696:f1a2831d549d | 697:0c84fb112d70 |
---|---|
488 "message": msg, | 488 "message": msg, |
489 "subject": subject, | 489 "subject": subject, |
490 "type": mess_type, | 490 "type": mess_type, |
491 "options": options, | 491 "options": options, |
492 } | 492 } |
493 treatments = defer.Deferred() # XXX: plugin can add their treatments to this deferred | |
493 | 494 |
494 if mess_data["type"] == "auto": | 495 if mess_data["type"] == "auto": |
495 # we try to guess the type | 496 # we try to guess the type |
496 if mess_data["subject"]: | 497 if mess_data["subject"]: |
497 mess_data["type"] = 'normal' | 498 mess_data["type"] = 'normal' |
510 else: | 511 else: |
511 mess_data["type"] == 'chat' | 512 mess_data["type"] == 'chat' |
512 mess_data["type"] == "chat" if mess_data["subject"] else "normal" | 513 mess_data["type"] == "chat" if mess_data["subject"] else "normal" |
513 | 514 |
514 if not no_trigger: | 515 if not no_trigger: |
515 if not self.trigger.point("sendMessage", mess_data, profile): | 516 if not self.trigger.point("sendMessage", mess_data, treatments, profile): |
516 return | 517 return |
517 | 518 |
518 debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()}) | 519 debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()}) |
519 message = domish.Element((None, 'message')) | 520 mess_data['xml'] = domish.Element((None, 'message')) |
520 message["to"] = mess_data["to"].full() | 521 mess_data['xml']["to"] = mess_data["to"].full() |
521 message["from"] = current_jid.full() | 522 mess_data['xml']["from"] = current_jid.full() |
522 message["type"] = mess_data["type"] | 523 mess_data['xml']["type"] = mess_data["type"] |
523 if mess_data["subject"]: | 524 if mess_data["subject"]: |
524 message.addElement("subject", None, subject) | 525 mess_data['xml'].addElement("subject", None, subject) |
525 # message without body are used to send chat states | 526 # message without body are used to send chat states |
526 if mess_data["message"]: | 527 if mess_data["message"]: |
527 message.addElement("body", None, mess_data["message"]) | 528 mess_data['xml'].addElement("body", None, mess_data["message"]) |
528 if not no_trigger: | 529 |
529 if not self.trigger.point("sendMessageXml", message, | 530 def sendAndStore(mess_data): |
530 mess_data, profile): | 531 client.xmlstream.send(mess_data['xml']) |
531 return | 532 if mess_data["type"] != "groupchat": |
532 client.xmlstream.send(message) | 533 # we don't add groupchat message to history, as we get them back |
533 if mess_data["type"] != "groupchat": | 534 # and they will be added then |
534 # we don't add groupchat message to history, as we get them back | 535 self.memory.addToHistory(current_jid, mess_data['to'], |
535 # and they will be added then | 536 unicode(mess_data["message"]), |
536 self.memory.addToHistory(current_jid, mess_data['to'], | 537 unicode(mess_data["type"]), |
537 unicode(mess_data["message"]), | 538 profile=profile) |
538 unicode(mess_data["type"]), | 539 # We send back the message, so all clients are aware of it |
539 profile=profile) | 540 if mess_data["message"]: |
540 # We send back the message, so all clients are aware of it | 541 self.bridge.newMessage(mess_data['xml']['from'], |
541 if mess_data["message"]: | 542 unicode(mess_data["message"]), |
542 self.bridge.newMessage(message['from'], | 543 mess_type=mess_data["type"], |
543 unicode(mess_data["message"]), | 544 to_jid=mess_data['xml']['to'], extra={}, |
544 mess_type=mess_data["type"], | 545 profile=profile) |
545 to_jid=message['to'], extra={}, | 546 |
546 profile=profile) | 547 treatments.addCallback(sendAndStore) |
548 treatments.callback(mess_data) | |
547 | 549 |
548 def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'): | 550 def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'): |
549 """Send our presence information""" | 551 """Send our presence information""" |
550 profile = self.memory.getProfileName(profile_key) | 552 profile = self.memory.getProfileName(profile_key) |
551 assert(profile) | 553 assert(profile) |