Mercurial > libervia-web
diff 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 |
line wrap: on
line diff
--- a/libervia.py Sun Nov 17 17:57:14 2013 +0100 +++ b/libervia.py Sun Nov 17 21:16:07 2013 +0100 @@ -708,6 +708,29 @@ def _newAlert(self, message, title, alert_type): dialog.InfoDialog(title, message).show() + def send(self, targets, text, rich=False): + """Send a message to any target type. + @param targets: list of couple (type, entities) with: + - type in ("PUBLIC", "GROUP", "COMMENT", "STATUS" , "groupchat" , "chat") + - entities could be a JID, a list groups, a node hash... depending the target + @param text: the message content + @param rich: set to True if the message is sent as a rich text message. + """ + # FIXME: too many magic strings, we should use constants instead + extra = {"rich": text} if rich else {} + for type_, entities in targets: + if type_ in ("PUBLIC", "GROUP"): + self.bridge.call("sendMblog", None, type_, entities if type_ == "GROUP" else None, text, extra) + elif type_ == "COMMENT": + self.bridge.call("sendMblogComment", None, entities, text, extra) + elif type_ == "STATUS": + self.bridge.call('setStatus', None, text) + elif type_ in ("groupchat", "chat"): + self.bridge.call('sendMessage', None, entities, text, '', type_, extra) + else: + print "ERROR: Unknown target type" + + if __name__ == '__main__': pyjd.setup("http://localhost:8080/libervia.html") app = SatWebFrontend()