basexmpp: Add a message_error event
The "message" event only receives messages with a body, and error messages don’t necessarily have it. Removing the body requirement from the "message" event could lean to unhandled conditions in existing code.
This commit is contained in:
parent
d5b1904ebb
commit
bdb1f66ac9
2 changed files with 20 additions and 0 deletions
|
@ -152,6 +152,13 @@ Event Index
|
||||||
Makes the contents of message stanzas available whenever one is received. Be
|
Makes the contents of message stanzas available whenever one is received. Be
|
||||||
sure to check the message type in order to handle error messages.
|
sure to check the message type in order to handle error messages.
|
||||||
|
|
||||||
|
message_error
|
||||||
|
- **Data:** :py:class:`~slixmpp.Message`
|
||||||
|
- **Source:** :py:class:`BaseXMPP <slixmpp.BaseXMPP>`
|
||||||
|
|
||||||
|
Makes the contents of message stanzas available whenever one is received.
|
||||||
|
Only handler messages with an ``error`` type.
|
||||||
|
|
||||||
message_form
|
message_form
|
||||||
- **Data:** :py:class:`~slixmpp.plugins.xep_0004.Form`
|
- **Data:** :py:class:`~slixmpp.plugins.xep_0004.Form`
|
||||||
- **Source:** :py:class:`~slixmpp.plugins.xep_0004.xep_0004`
|
- **Source:** :py:class:`~slixmpp.plugins.xep_0004.xep_0004`
|
||||||
|
|
|
@ -143,6 +143,13 @@ class BaseXMPP(XMLStream):
|
||||||
MatchXPath('{%s}message/{%s}body' % (self.default_ns,
|
MatchXPath('{%s}message/{%s}body' % (self.default_ns,
|
||||||
self.default_ns)),
|
self.default_ns)),
|
||||||
self._handle_message))
|
self._handle_message))
|
||||||
|
|
||||||
|
self.register_handler(
|
||||||
|
Callback('IMError',
|
||||||
|
MatchXPath('{%s}message/{%s}error' % (self.default_ns,
|
||||||
|
self.default_ns)),
|
||||||
|
self._handle_message_error))
|
||||||
|
|
||||||
self.register_handler(
|
self.register_handler(
|
||||||
Callback('Presence',
|
Callback('Presence',
|
||||||
MatchXPath("{%s}presence" % self.default_ns),
|
MatchXPath("{%s}presence" % self.default_ns),
|
||||||
|
@ -690,6 +697,12 @@ class BaseXMPP(XMLStream):
|
||||||
msg['to'] = self.boundjid
|
msg['to'] = self.boundjid
|
||||||
self.event('message', msg)
|
self.event('message', msg)
|
||||||
|
|
||||||
|
def _handle_message_error(self, msg):
|
||||||
|
"""Process incoming message error stanzas."""
|
||||||
|
if not self.is_component and not msg['to'].bare:
|
||||||
|
msg['to'] = self.boundjid
|
||||||
|
self.event('message_error', msg)
|
||||||
|
|
||||||
def _handle_available(self, pres):
|
def _handle_available(self, pres):
|
||||||
self.roster[pres['to']][pres['from']].handle_available(pres)
|
self.roster[pres['to']][pres['from']].handle_available(pres)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue