Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- a/src/core/xmpp.py Wed Oct 17 00:35:48 2012 +0200 +++ b/src/core/xmpp.py Sat Oct 20 17:23:56 2012 +0200 @@ -21,9 +21,10 @@ from twisted.internet import task, defer from twisted.words.protocols.jabber import jid, xmlstream -from wokkel import client, disco, xmppim, generic, compat +from wokkel import client, disco, xmppim, generic, compat, delay from logging import debug, info, error from sat.core import exceptions +from calendar import timegm class SatXMPPClient(client.XMPPClient): @@ -104,17 +105,25 @@ self.host = host def onMessage(self, message): - debug (_(u"got message from: %s"), message["from"]) - if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile): - return - 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 "" - self.host.bridge.newMessage(message["from"], mess_body, mess_type, message['to'], profile=self.parent.profile) - if not u"delay" in [elem.name for elem in message.elements()]: #we don't save delayed messages in history - self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, profile=self.parent.profile) - break + debug (_(u"got message from: %s"), message["from"]) + if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile): + return + 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 class SatRosterProtocol(xmppim.RosterClientProtocol):