comparison libervia.py @ 269:9eb9c7d41bdc

browser_side: added generic method "send" in SatWebFrontend
author souliane <souliane@mailoo.org>
date Sun, 17 Nov 2013 21:16:07 +0100
parents a76243c02074
children 886b47896f3c
comparison
equal deleted inserted replaced
268:79970bf6af93 269:9eb9c7d41bdc
706 dialog.ConfirmDialog(confirm_cb, text=data["message"], title=data["title"]).show() 706 dialog.ConfirmDialog(confirm_cb, text=data["message"], title=data["title"]).show()
707 707
708 def _newAlert(self, message, title, alert_type): 708 def _newAlert(self, message, title, alert_type):
709 dialog.InfoDialog(title, message).show() 709 dialog.InfoDialog(title, message).show()
710 710
711 def send(self, targets, text, rich=False):
712 """Send a message to any target type.
713 @param targets: list of couple (type, entities) with:
714 - type in ("PUBLIC", "GROUP", "COMMENT", "STATUS" , "groupchat" , "chat")
715 - entities could be a JID, a list groups, a node hash... depending the target
716 @param text: the message content
717 @param rich: set to True if the message is sent as a rich text message.
718 """
719 # FIXME: too many magic strings, we should use constants instead
720 extra = {"rich": text} if rich else {}
721 for type_, entities in targets:
722 if type_ in ("PUBLIC", "GROUP"):
723 self.bridge.call("sendMblog", None, type_, entities if type_ == "GROUP" else None, text, extra)
724 elif type_ == "COMMENT":
725 self.bridge.call("sendMblogComment", None, entities, text, extra)
726 elif type_ == "STATUS":
727 self.bridge.call('setStatus', None, text)
728 elif type_ in ("groupchat", "chat"):
729 self.bridge.call('sendMessage', None, entities, text, '', type_, extra)
730 else:
731 print "ERROR: Unknown target type"
732
733
711 if __name__ == '__main__': 734 if __name__ == '__main__':
712 pyjd.setup("http://localhost:8080/libervia.html") 735 pyjd.setup("http://localhost:8080/libervia.html")
713 app = SatWebFrontend() 736 app = SatWebFrontend()
714 app.onModuleLoad() 737 app.onModuleLoad()
715 pyjd.run() 738 pyjd.run()