From b5c669bdff4111c5754f237d13224ec1ee1d595a Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 25 Sep 2012 12:26:56 -0700 Subject: Add options to auto add ID values to message and presence stanzas. --- sleekxmpp/stanza/message.py | 11 +++++++++++ sleekxmpp/stanza/presence.py | 11 +++++++++++ 2 files changed, 22 insertions(+) (limited to 'sleekxmpp/stanza') 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 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 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. -- cgit v1.2.3