comparison src/core/xmpp.py @ 513:8ee9113d307b

core, quick_frontend, primitivus, wixi, bridge: fixed delayed message timestamp: - new "extra" parameter in newMessage signal
author Goffi <goffi@goffi.org>
date Sat, 20 Oct 2012 17:23:56 +0200
parents 862c0d6ab974
children 75216d94a89d
comparison
equal deleted inserted replaced
512:862c0d6ab974 513:8ee9113d307b
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 from twisted.internet import task, defer 22 from twisted.internet import task, defer
23 from twisted.words.protocols.jabber import jid, xmlstream 23 from twisted.words.protocols.jabber import jid, xmlstream
24 from wokkel import client, disco, xmppim, generic, compat 24 from wokkel import client, disco, xmppim, generic, compat, delay
25 from logging import debug, info, error 25 from logging import debug, info, error
26 from sat.core import exceptions 26 from sat.core import exceptions
27 from calendar import timegm
27 28
28 29
29 class SatXMPPClient(client.XMPPClient): 30 class SatXMPPClient(client.XMPPClient):
30 31
31 def __init__(self, host_app, profile, user_jid, password, host=None, port=5222): 32 def __init__(self, host_app, profile, user_jid, password, host=None, port=5222):
102 def __init__(self, host): 103 def __init__(self, host):
103 xmppim.MessageProtocol.__init__(self) 104 xmppim.MessageProtocol.__init__(self)
104 self.host = host 105 self.host = host
105 106
106 def onMessage(self, message): 107 def onMessage(self, message):
107 debug (_(u"got message from: %s"), message["from"]) 108 debug (_(u"got message from: %s"), message["from"])
108 if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile): 109 if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile):
109 return 110 return
110 for e in message.elements(): 111 for e in message.elements():
111 if e.name == "body": 112 if e.name == "body":
112 mess_type = message['type'] if message.hasAttribute('type') else 'normal' 113 mess_type = message['type'] if message.hasAttribute('type') else 'normal'
113 mess_body = e.children[0] if e.children else "" 114 mess_body = e.children[0] if e.children else ""
114 self.host.bridge.newMessage(message["from"], mess_body, mess_type, message['to'], profile=self.parent.profile) 115 try:
115 if not u"delay" in [elem.name for elem in message.elements()]: #we don't save delayed messages in history 116 _delay = delay.Delay.fromElement(filter(lambda elm: elm.name == 'delay', message.elements())[0])
116 self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, profile=self.parent.profile) 117 timestamp = timegm(_delay.stamp.utctimetuple())
117 break 118 extra = {"archive": str(timestamp)}
119 if mess_type != 'groupchat': #XXX: we don't save delayed messages in history for groupchats
120 #TODO: add delayed messages to history if they aren't already in it
121 self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, timestamp, profile=self.parent.profile)
122 except IndexError:
123 extra = {}
124 self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, profile=self.parent.profile)
125 self.host.bridge.newMessage(message["from"], mess_body, mess_type, message['to'], extra, profile=self.parent.profile)
126 break
118 127
119 class SatRosterProtocol(xmppim.RosterClientProtocol): 128 class SatRosterProtocol(xmppim.RosterClientProtocol):
120 129
121 def __init__(self, host): 130 def __init__(self, host):
122 xmppim.RosterClientProtocol.__init__(self) 131 xmppim.RosterClientProtocol.__init__(self)