Commit 6b2b6f8b authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Split base message handler

parent 2386104f
......@@ -20,6 +20,7 @@ import logging
from nbxmpp.protocol import NodeProcessed
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import ErrorProperties
from nbxmpp.structs import StanzaIDData
from nbxmpp.const import MessageType
log = logging.getLogger('nbxmpp.m.message')
......@@ -31,6 +32,9 @@ class BaseMessage:
self.handlers = [
StanzaHandler(name='message',
callback=self._process_message_base,
priority=5),
StanzaHandler(name='message',
callback=self._process_message_after_base,
priority=10),
]
......@@ -38,14 +42,23 @@ class BaseMessage:
properties.type = self._parse_type(stanza)
properties.jid = stanza.getFrom()
properties.id = stanza.getID()
properties.body = stanza.getBody()
properties.thread = stanza.getThread()
properties.subject = stanza.getSubject()
properties.self_message = self._parse_self_message(stanza, properties)
# Stanza ID
id_, by = stanza.getStanzaIDAttrs()
properties.stanza_id = StanzaIDData(id=id_, by=by)
if properties.type.is_error:
properties.error = ErrorProperties(stanza)
@staticmethod
def _process_message_after_base(_con, stanza, properties):
# This handler runs after decryption handlers had the chance
# to decrypt the body
properties.body = stanza.getBody()
properties.thread = stanza.getThread()
properties.subject = stanza.getSubject()
@staticmethod
def _parse_type(stanza):
type_ = stanza.getType()
......
......@@ -53,6 +53,9 @@ EntityCapsData.__new__.__defaults__ = (None, None, None)
HTTPAuthData = namedtuple('HTTPAuthData', 'id method url body')
HTTPAuthData.__new__.__defaults__ = (None, None, None, None)
StanzaIDData = namedtuple('StanzaIDData', 'id by')
StanzaIDData.__new__.__defaults__ = (None, None)
class Properties:
pass
......@@ -62,6 +65,7 @@ class MessageProperties:
self.carbon_type = None
self.type = MessageType.NORMAL
self.id = None
self.stanza_id = None
self.jid = None
self.subject = None
self.body = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment