comparison src/core/xmpp.py @ 636:7ea6d5a86e58

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)
author souliane <souliane@mailoo.org>
date Thu, 05 Sep 2013 20:48:47 +0200
parents d722778b152c
children 8004c7d4aba7
comparison
equal deleted inserted replaced
635:eff8772fd472 636:7ea6d5a86e58
106 106
107 def onMessage(self, message): 107 def onMessage(self, message):
108 debug(_(u"got message from: %s"), message["from"]) 108 debug(_(u"got message from: %s"), message["from"])
109 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):
110 return 110 return
111 # set message body to empty string by default, and later
112 # also forward message without body (chat state notification...)
113 mess_body = ""
111 for e in message.elements(): 114 for e in message.elements():
112 if e.name == "body": 115 if e.name == "body":
113 mess_type = message['type'] if message.hasAttribute('type') else 'normal'
114 mess_body = e.children[0] if e.children else "" 116 mess_body = e.children[0] if e.children else ""
115 try:
116 _delay = delay.Delay.fromElement(filter(lambda elm: elm.name == 'delay', message.elements())[0])
117 timestamp = timegm(_delay.stamp.utctimetuple())
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 117 break
118
119 mess_type = message['type'] if message.hasAttribute('type') else 'normal'
120 try:
121 _delay = delay.Delay.fromElement(filter(lambda elm: elm.name == 'delay', message.elements())[0])
122 timestamp = timegm(_delay.stamp.utctimetuple())
123 extra = {"archive": str(timestamp)}
124 if mess_type != 'groupchat': # XXX: we don't save delayed messages in history for groupchats
125 #TODO: add delayed messages to history if they aren't already in it
126 self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, timestamp, profile=self.parent.profile)
127 except IndexError:
128 extra = {}
129 self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, profile=self.parent.profile)
130 self.host.bridge.newMessage(message["from"], mess_body, mess_type, message['to'], extra, profile=self.parent.profile)
127 131
128 132
129 class SatRosterProtocol(xmppim.RosterClientProtocol): 133 class SatRosterProtocol(xmppim.RosterClientProtocol):
130 134
131 def __init__(self, host): 135 def __init__(self, host):