diff 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
line wrap: on
line diff
--- a/libervia.py	Sat Nov 23 14:46:03 2013 +0100
+++ b/libervia.py	Wed Dec 04 21:52:30 2013 +0100
@@ -723,17 +723,19 @@
     def _newAlert(self, message, title, alert_type):
         dialog.InfoDialog(title, message).show()
 
-    def send(self, targets, text, rich=False):
+    def send(self, targets, text, extra={}):
         """Send a message to any target type.
-        @param targets: list of couple (type, entities) with:
+        @param targets: list of tuples (type, entities, addr) with:
         - type in ("PUBLIC", "GROUP", "COMMENT", "STATUS" , "groupchat" , "chat")
         - entities could be a JID, a list groups, a node hash... depending the target
+        - addr in ("To", "Cc", "Bcc") - ignore case
         @param text: the message content
-        @param rich: set to True if the message is sent as a rich text message.
+        @param extra: options
         """
         # FIXME: too many magic strings, we should use constants instead
-        extra = {"rich": text} if rich else {}
-        for type_, entities in targets:
+        addresses = []
+        for target in targets:
+            type_, entities, addr = target[0], target[1], 'to' if len(target) < 3 else target[2].lower()
             if type_ in ("PUBLIC", "GROUP"):
                 self.bridge.call("sendMblog", None, type_, entities if type_ == "GROUP" else None, text, extra)
             elif type_ == "COMMENT":
@@ -741,9 +743,15 @@
             elif type_ == "STATUS":
                 self.bridge.call('setStatus', None, self.status_panel.presence, text)
             elif type_ in ("groupchat", "chat"):
-                self.bridge.call('sendMessage', None, entities, text, '', type_, extra)
+                addresses.append((addr, entities))
             else:
                 print "ERROR: Unknown target type"
+        if addresses:
+            if len(addresses) == 1 and addresses[0][0] == 'to':
+                self.bridge.call('sendMessage', None, addresses[0][1], text, '', type_, extra)
+            else:
+                extra.update({'address': '\n'.join([('%s:%s' % entry) for entry in addresses])})
+                self.bridge.call('sendMessage', None, self.whoami.domain, text, '', type_, extra)
 
 
 if __name__ == '__main__':