diff src/core/sat_main.py @ 636:7ea6d5a86e58

plugin XEP-0085: Chat State Notifications - new "options" parameter to send chat states - plugin command export: messages without body are now delivered (since all the chat states other than "active" need them)
author souliane <souliane@mailoo.org>
date Thu, 05 Sep 2013 20:48:47 +0200
parents d207c2186519
children 49587e170f53
line wrap: on
line diff
--- a/src/core/sat_main.py	Sun Sep 08 19:12:59 2013 +0200
+++ b/src/core/sat_main.py	Thu Sep 05 20:48:47 2013 +0200
@@ -469,21 +469,24 @@
             ret.append((conf_id, conf_type, data))
         return ret
 
-    def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', profile_key='@NONE@'):
+    def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', options={}, profile_key='@NONE@'):
         to_jid = jid.JID(to_s)
-        self.sendMessage(to_jid, msg, subject, mess_type, profile_key=profile_key)
-    
-    def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', no_trigger = False, profile_key='@NONE@'):
+        self.sendMessage(to_jid, msg, subject, mess_type, options=options, profile_key=profile_key)
+
+    def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', options={}, no_trigger=False, profile_key='@NONE@'):
         #FIXME: check validity of recipient
         profile = self.memory.getProfileName(profile_key)
         assert(profile)
         client = self.profiles[profile]
         current_jid = client.jid
+        if options is None:
+            options = {}
         mess_data = {  # we put data in a dict, so trigger methods can change them
             "to": to_jid,
             "message": msg,
             "subject": subject,
-            "type": mess_type
+            "type": mess_type,
+            "options": options,
         }
 
         if mess_data["type"] == "auto":
@@ -517,12 +520,28 @@
         message["type"] = mess_data["type"]
         if mess_data["subject"]:
             message.addElement("subject", None, subject)
-        message.addElement("body", None, mess_data["message"])
+        # message without body are used to send chat states
+        if mess_data["message"]:
+            message.addElement("body", None, mess_data["message"])
+        if not no_trigger:
+            if not self.trigger.point("sendMessageXml", message,
+                                      mess_data, profile):
+                return
         client.xmlstream.send(message)
         if mess_data["type"] != "groupchat":
-            self.memory.addToHistory(current_jid, mess_data['to'], unicode(mess_data["message"]), unicode(mess_data["type"]), profile=profile)  # we don't add groupchat message to history, as we get them back
-                                                                                              # and they will be added then
-            self.bridge.newMessage(message['from'], unicode(mess_data["message"]), mess_type=mess_data["type"], to_jid=message['to'], extra={}, profile=profile)  # We send back the message, so all clients are aware of it
+            # we don't add groupchat message to history, as we get them back
+            # and they will be added then
+            self.memory.addToHistory(current_jid, mess_data['to'],
+                                     unicode(mess_data["message"]),
+                                     unicode(mess_data["type"]),
+                                     profile=profile)
+            # We send back the message, so all clients are aware of it
+            if mess_data["message"]:
+                self.bridge.newMessage(message['from'],
+                                       unicode(mess_data["message"]),
+                                       mess_type=mess_data["type"],
+                                       to_jid=message['to'], extra={},
+                                       profile=profile)
 
     def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'):
         """Send our presence information"""