comparison libervia.py @ 280:1ccdc34cfb60

browser_side: changes related to the implementation of XEP-0033 (addressing)
author souliane <souliane@mailoo.org>
date Wed, 04 Dec 2013 21:52:30 +0100
parents 2d6bd975a72d
children ae3ec654836d
comparison
equal deleted inserted replaced
279:2d6bd975a72d 280:1ccdc34cfb60
721 dialog.ConfirmDialog(confirm_cb, text=data["message"], title=data["title"]).show() 721 dialog.ConfirmDialog(confirm_cb, text=data["message"], title=data["title"]).show()
722 722
723 def _newAlert(self, message, title, alert_type): 723 def _newAlert(self, message, title, alert_type):
724 dialog.InfoDialog(title, message).show() 724 dialog.InfoDialog(title, message).show()
725 725
726 def send(self, targets, text, rich=False): 726 def send(self, targets, text, extra={}):
727 """Send a message to any target type. 727 """Send a message to any target type.
728 @param targets: list of couple (type, entities) with: 728 @param targets: list of tuples (type, entities, addr) with:
729 - type in ("PUBLIC", "GROUP", "COMMENT", "STATUS" , "groupchat" , "chat") 729 - type in ("PUBLIC", "GROUP", "COMMENT", "STATUS" , "groupchat" , "chat")
730 - entities could be a JID, a list groups, a node hash... depending the target 730 - entities could be a JID, a list groups, a node hash... depending the target
731 - addr in ("To", "Cc", "Bcc") - ignore case
731 @param text: the message content 732 @param text: the message content
732 @param rich: set to True if the message is sent as a rich text message. 733 @param extra: options
733 """ 734 """
734 # FIXME: too many magic strings, we should use constants instead 735 # FIXME: too many magic strings, we should use constants instead
735 extra = {"rich": text} if rich else {} 736 addresses = []
736 for type_, entities in targets: 737 for target in targets:
738 type_, entities, addr = target[0], target[1], 'to' if len(target) < 3 else target[2].lower()
737 if type_ in ("PUBLIC", "GROUP"): 739 if type_ in ("PUBLIC", "GROUP"):
738 self.bridge.call("sendMblog", None, type_, entities if type_ == "GROUP" else None, text, extra) 740 self.bridge.call("sendMblog", None, type_, entities if type_ == "GROUP" else None, text, extra)
739 elif type_ == "COMMENT": 741 elif type_ == "COMMENT":
740 self.bridge.call("sendMblogComment", None, entities, text, extra) 742 self.bridge.call("sendMblogComment", None, entities, text, extra)
741 elif type_ == "STATUS": 743 elif type_ == "STATUS":
742 self.bridge.call('setStatus', None, self.status_panel.presence, text) 744 self.bridge.call('setStatus', None, self.status_panel.presence, text)
743 elif type_ in ("groupchat", "chat"): 745 elif type_ in ("groupchat", "chat"):
744 self.bridge.call('sendMessage', None, entities, text, '', type_, extra) 746 addresses.append((addr, entities))
745 else: 747 else:
746 print "ERROR: Unknown target type" 748 print "ERROR: Unknown target type"
749 if addresses:
750 if len(addresses) == 1 and addresses[0][0] == 'to':
751 self.bridge.call('sendMessage', None, addresses[0][1], text, '', type_, extra)
752 else:
753 extra.update({'address': '\n'.join([('%s:%s' % entry) for entry in addresses])})
754 self.bridge.call('sendMessage', None, self.whoami.domain, text, '', type_, extra)
747 755
748 756
749 if __name__ == '__main__': 757 if __name__ == '__main__':
750 pyjd.setup("http://localhost:8080/libervia.html") 758 pyjd.setup("http://localhost:8080/libervia.html")
751 app = SatWebFrontend() 759 app = SatWebFrontend()