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)
This commit is contained in:
souliane 2013-09-05 20:48:47 +02:00
commit 9cb7071e89

View file

@ -108,23 +108,27 @@ class SatMessageProtocol(xmppim.MessageProtocol):
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):