Mercurial > libervia-backend
comparison src/core/sat_main.py @ 752:f49945d728de
core,bridge: sendMessage bridge method is now async
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 17 Dec 2013 01:46:45 +0100 |
parents | a0f4a80a6536 |
children | e3ad48a2aab2 |
comparison
equal
deleted
inserted
replaced
751:1def5b7edf9f | 752:f49945d728de |
---|---|
507 return ret | 507 return ret |
508 | 508 |
509 def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'): | 509 def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'): |
510 to_jid = jid.JID(to_s) | 510 to_jid = jid.JID(to_s) |
511 #XXX: we need to use the dictionary comprehension because D-Bus return its own types, and pickle can't manage them. TODO: Need to find a better way | 511 #XXX: we need to use the dictionary comprehension because D-Bus return its own types, and pickle can't manage them. TODO: Need to find a better way |
512 self.sendMessage(to_jid, msg, subject, mess_type, {unicode(key): unicode(value) for key, value in extra.items()}, profile_key=profile_key) | 512 return self.sendMessage(to_jid, msg, subject, mess_type, {unicode(key): unicode(value) for key, value in extra.items()}, profile_key=profile_key) |
513 | 513 |
514 def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', extra={}, no_trigger=False, profile_key='@NONE@'): | 514 def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', extra={}, no_trigger=False, profile_key='@NONE@'): |
515 #FIXME: check validity of recipient | 515 #FIXME: check validity of recipient |
516 profile = self.memory.getProfileName(profile_key) | 516 profile = self.memory.getProfileName(profile_key) |
517 assert(profile) | 517 assert(profile) |
548 mess_data["type"] == 'chat' | 548 mess_data["type"] == 'chat' |
549 mess_data["type"] == "chat" if mess_data["subject"] else "normal" | 549 mess_data["type"] == "chat" if mess_data["subject"] else "normal" |
550 | 550 |
551 if not no_trigger: | 551 if not no_trigger: |
552 if not self.trigger.point("sendMessage", mess_data, treatments, profile): | 552 if not self.trigger.point("sendMessage", mess_data, treatments, profile): |
553 return | 553 return defer.succeed(None) |
554 | 554 |
555 debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()}) | 555 debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()}) |
556 mess_data['xml'] = domish.Element((None, 'message')) | 556 mess_data['xml'] = domish.Element((None, 'message')) |
557 mess_data['xml']["to"] = mess_data["to"].full() | 557 mess_data['xml']["to"] = mess_data["to"].full() |
558 mess_data['xml']["from"] = current_jid.full() | 558 mess_data['xml']["from"] = current_jid.full() |
567 text = '%s: %s' % (e.value.__class__.__name__, e.getErrorMessage()) | 567 text = '%s: %s' % (e.value.__class__.__name__, e.getErrorMessage()) |
568 if e.check(MessageSentAndStored): | 568 if e.check(MessageSentAndStored): |
569 debug(text) | 569 debug(text) |
570 elif e.check(AbortSendMessage): | 570 elif e.check(AbortSendMessage): |
571 warning(text) | 571 warning(text) |
572 return e | |
572 else: | 573 else: |
573 error("Unmanaged exception: %s" % text) | 574 error("Unmanaged exception: %s" % text) |
574 return e | 575 return e |
575 | 576 |
576 treatments.addCallbacks(self.sendAndStoreMessage, sendErrback, [False, profile]) | 577 treatments.addCallbacks(self.sendAndStoreMessage, sendErrback, [False, profile]) |
577 treatments.callback(mess_data) | 578 treatments.callback(mess_data) |
579 return treatments | |
578 | 580 |
579 def sendAndStoreMessage(self, mess_data, skip_send=False, profile=None): | 581 def sendAndStoreMessage(self, mess_data, skip_send=False, profile=None): |
580 """Actually send and store the message to history, after all the treatments | 582 """Actually send and store the message to history, after all the treatments |
581 have been done. This has been moved outside the main sendMessage method | 583 have been done. This has been moved outside the main sendMessage method |
582 because it is used by XEP-0033 to complete a server-side feature not yet | 584 because it is used by XEP-0033 to complete a server-side feature not yet |