diff options
author | Lance Stout <lancestout@gmail.com> | 2012-09-25 12:26:56 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-09-25 12:26:56 -0700 |
commit | b5c669bdff4111c5754f237d13224ec1ee1d595a (patch) | |
tree | 2c5a1e35ed4d3d962b93cf3f40c2efb3aa6734e2 | |
parent | e449dce65c0d267c4d3206b6f9ac2e89807192bc (diff) | |
download | slixmpp-b5c669bdff4111c5754f237d13224ec1ee1d595a.tar.gz slixmpp-b5c669bdff4111c5754f237d13224ec1ee1d595a.tar.bz2 slixmpp-b5c669bdff4111c5754f237d13224ec1ee1d595a.tar.xz slixmpp-b5c669bdff4111c5754f237d13224ec1ee1d595a.zip |
Add options to auto add ID values to message and presence stanzas.
-rw-r--r-- | sleekxmpp/basexmpp.py | 11 | ||||
-rw-r--r-- | sleekxmpp/stanza/message.py | 11 | ||||
-rw-r--r-- | sleekxmpp/stanza/presence.py | 11 |
3 files changed, 33 insertions, 0 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 244d19c5..55250751 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -114,6 +114,17 @@ class BaseXMPP(XMLStream): #: ``'to'`` and ``'from'`` JIDs of stanzas. self.is_component = False + #: Messages may optionally be tagged with ID values. Setting + #: :attr:`use_message_ids` to `True` will assign all outgoing + #: messages an ID. Some plugin features require enabling + #: this option. + self.use_message_ids = False + + #: Presence updates may optionally be tagged with ID values. + #: Setting :attr:`use_message_ids` to `True` will assign all + #: outgoing messages an ID. + self.use_presence_ids = False + #: The API registry is a way to process callbacks based on #: JID+node combinations. Each callback in the registry is #: marked with: diff --git a/sleekxmpp/stanza/message.py b/sleekxmpp/stanza/message.py index 02133682..0bb6e587 100644 --- a/sleekxmpp/stanza/message.py +++ b/sleekxmpp/stanza/message.py @@ -63,6 +63,17 @@ class Message(RootStanza): lang_interfaces = sub_interfaces types = set(['normal', 'chat', 'headline', 'error', 'groupchat']) + def __init__(self, *args, **kwargs): + """ + Initialize a new <message /> stanza with an optional 'id' value. + + Overrides StanzaBase.__init__. + """ + StanzaBase.__init__(self, *args, **kwargs) + if self['id'] == '': + if self.stream is not None and self.stream.use_message_ids: + self['id'] = self.stream.new_id() + def get_type(self): """ Return the message type. diff --git a/sleekxmpp/stanza/presence.py b/sleekxmpp/stanza/presence.py index 7951f861..84bcd122 100644 --- a/sleekxmpp/stanza/presence.py +++ b/sleekxmpp/stanza/presence.py @@ -72,6 +72,17 @@ class Presence(RootStanza): 'subscribed', 'unsubscribe', 'unsubscribed']) showtypes = set(['dnd', 'chat', 'xa', 'away']) + def __init__(self, *args, **kwargs): + """ + Initialize a new <presence /> stanza with an optional 'id' value. + + Overrides StanzaBase.__init__. + """ + StanzaBase.__init__(self, *args, **kwargs) + if self['id'] == '': + if self.stream is not None and self.stream.use_presence_ids: + self['id'] = self.stream.new_id() + def exception(self, e): """ Override exception passback for presence. |