diff src/core/xmpp.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 d722778b152c
children 8004c7d4aba7
line wrap: on
line diff
--- a/src/core/xmpp.py	Sun Sep 08 19:12:59 2013 +0200
+++ b/src/core/xmpp.py	Thu Sep 05 20:48:47 2013 +0200
@@ -108,23 +108,27 @@
         debug(_(u"got message from: %s"), message["from"])
         if not self.host.trigger.point("MessageReceived", message, profile=self.parent.profile):
             return
+        # set message body to empty string by default, and later
+        # also forward message without body (chat state notification...)
+        mess_body = ""
         for e in message.elements():
             if e.name == "body":
-                mess_type = message['type'] if message.hasAttribute('type') else 'normal'
                 mess_body = e.children[0] if e.children else ""
-                try:
-                    _delay = delay.Delay.fromElement(filter(lambda elm: elm.name == 'delay', message.elements())[0])
-                    timestamp = timegm(_delay.stamp.utctimetuple())
-                    extra = {"archive": str(timestamp)}
-                    if mess_type != 'groupchat':  # XXX: we don't save delayed messages in history for groupchats
-                        #TODO: add delayed messages to history if they aren't already in it
-                        self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, timestamp, profile=self.parent.profile)
-                except IndexError:
-                    extra = {}
-                    self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, profile=self.parent.profile)
-                self.host.bridge.newMessage(message["from"], mess_body, mess_type, message['to'], extra, profile=self.parent.profile)
                 break
 
+        mess_type = message['type'] if message.hasAttribute('type') else 'normal'
+        try:
+            _delay = delay.Delay.fromElement(filter(lambda elm: elm.name == 'delay', message.elements())[0])
+            timestamp = timegm(_delay.stamp.utctimetuple())
+            extra = {"archive": str(timestamp)}
+            if mess_type != 'groupchat':  # XXX: we don't save delayed messages in history for groupchats
+                #TODO: add delayed messages to history if they aren't already in it
+                self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, timestamp, profile=self.parent.profile)
+        except IndexError:
+            extra = {}
+            self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, profile=self.parent.profile)
+        self.host.bridge.newMessage(message["from"], mess_body, mess_type, message['to'], extra, profile=self.parent.profile)
+
 
 class SatRosterProtocol(xmppim.RosterClientProtocol):