comparison 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
comparison
equal deleted inserted replaced
1742:244a605623d6 1743:4c48468ead4c
24 from twisted.words.protocols.jabber import error 24 from twisted.words.protocols.jabber import error
25 from wokkel import client, disco, xmppim, generic, delay, iwokkel 25 from wokkel import client, disco, xmppim, generic, delay, iwokkel
26 from sat.core.log import getLogger 26 from sat.core.log import getLogger
27 log = getLogger(__name__) 27 log = getLogger(__name__)
28 from sat.core import exceptions 28 from sat.core import exceptions
29 from calendar import timegm
30 from zope.interface import implements 29 from zope.interface import implements
31 from twisted.words.protocols.jabber.xmlstream import XMPPHandler 30 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
32 31
33 32
34 class SatXMPPClient(client.XMPPClient): 33 class SatXMPPClient(client.XMPPClient):
158 if data is not None: 157 if data is not None:
159 self.host.bridge.newMessage(data['from'], data['body'], data['type'], data['to'], data['extra'], profile=self.parent.profile) 158 self.host.bridge.newMessage(data['from'], data['body'], data['type'], data['to'], data['extra'], profile=self.parent.profile)
160 return data 159 return data
161 160
162 def addToHistory(data): 161 def addToHistory(data):
163 # set message body to empty string by default, and later
164 # also forward message without body (chat state notification...)
165 try: 162 try:
166 _delay = delay.Delay.fromElement(filter(lambda elm: elm.name == 'delay', message.elements())[0]) 163 timestamp = data['extra']['timestamp'] # timestamp added by XEP-0203
167 timestamp = timegm(_delay.stamp.utctimetuple()) 164 except KeyError:
168 data['extra']['archive'] = str(timestamp) 165 self.host.memory.addToHistory(jid.JID(data['from']), jid.JID(data['to']), data['body'], data['type'], data['extra'], profile=self.parent.profile)
166 else:
169 if data['type'] != 'groupchat': # XXX: we don't save delayed messages in history for groupchats 167 if data['type'] != 'groupchat': # XXX: we don't save delayed messages in history for groupchats
170 #TODO: add delayed messages to history if they aren't already in it 168 #TODO: add delayed messages to history if they aren't already in it
169 data['extra']['archive'] = timestamp # FIXME: this "archive" is actually never used
171 self.host.memory.addToHistory(jid.JID(data['from']), jid.JID(data['to']), data['body'], data['type'], data['extra'], timestamp, profile=self.parent.profile) 170 self.host.memory.addToHistory(jid.JID(data['from']), jid.JID(data['to']), data['body'], data['type'], data['extra'], timestamp, profile=self.parent.profile)
172 except IndexError:
173 self.host.memory.addToHistory(jid.JID(data['from']), jid.JID(data['to']), data['body'], data['type'], data['extra'], profile=self.parent.profile)
174 return data 171 return data
175 172
176 def treatmentsEb(failure): 173 def treatmentsEb(failure):
177 failure.trap(exceptions.SkipHistory) 174 failure.trap(exceptions.SkipHistory)
178 return data 175 return data