diff src/core/xmpp.py @ 1743:4c48468ead4c

plugin XEP-0203, core (xmpp): leave the management of delay element to XEP-0203 (fix bug 59): - this patch reveals a bug in primitivus Chat.printMessage relative to MUC history (the test to discard duplicates is wrong)
author souliane <souliane@mailoo.org>
date Fri, 11 Dec 2015 11:25:29 +0100
parents c1be6363bfab
children d17772b0fe22
line wrap: on
line diff
--- a/src/core/xmpp.py	Tue Dec 15 13:30:47 2015 +0100
+++ b/src/core/xmpp.py	Fri Dec 11 11:25:29 2015 +0100
@@ -26,7 +26,6 @@
 from sat.core.log import getLogger
 log = getLogger(__name__)
 from sat.core import exceptions
-from calendar import timegm
 from zope.interface import implements
 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
 
@@ -160,17 +159,15 @@
             return data
 
         def addToHistory(data):
-            # set message body to empty string by default, and later
-            # also forward message without body (chat state notification...)
             try:
-                _delay = delay.Delay.fromElement(filter(lambda elm: elm.name == 'delay', message.elements())[0])
-                timestamp = timegm(_delay.stamp.utctimetuple())
-                data['extra']['archive'] = str(timestamp)
+                timestamp = data['extra']['timestamp']  # timestamp added by XEP-0203
+            except KeyError:
+                self.host.memory.addToHistory(jid.JID(data['from']), jid.JID(data['to']), data['body'], data['type'], data['extra'], profile=self.parent.profile)
+            else:
                 if data['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
+                    data['extra']['archive'] = timestamp  # FIXME: this "archive" is actually never used
                     self.host.memory.addToHistory(jid.JID(data['from']), jid.JID(data['to']), data['body'], data['type'], data['extra'], timestamp, profile=self.parent.profile)
-            except IndexError:
-                self.host.memory.addToHistory(jid.JID(data['from']), jid.JID(data['to']), data['body'], data['type'], data['extra'], profile=self.parent.profile)
             return data
 
         def treatmentsEb(failure):